Timezone#now returning UTC for all time stamps. #36

Closed
treacher opened this Issue Feb 12, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@treacher

Not sure if this is a bug bit this seems kind of strange to me. Would love to get your feed back on the following:

require 'tzinfo'
tz = TZInfo::Timezone.get('Australia/Melbourne')
tz.now
=> 2015-02-12 16:26:08 UTC

So the time is correct. But it is showing UTC for the timezone.

@treacher treacher closed this Feb 12, 2015

@philr

This comment has been minimized.

Show comment
Hide comment
@philr

philr Feb 12, 2015

Member

Ruby Time instances only support two different time zones - UTC and the system configured local time zone. It is not possible to return an instance of Time with the correct time zone information for every possible time zone. Therefore, methods that return local times always use UTC.

Member

philr commented Feb 12, 2015

Ruby Time instances only support two different time zones - UTC and the system configured local time zone. It is not possible to return an instance of Time with the correct time zone information for every possible time zone. Therefore, methods that return local times always use UTC.

@philr philr added the question label Feb 12, 2015

@zverok

This comment has been minimized.

Show comment
Hide comment
@zverok

zverok Feb 16, 2016

Contributor

Sorry for writing in the old issue, but it seems Time in fact can be constructed in any offset:

t1 = Time.new(2007,11,1,15,25,0, "+09:00")
# => 2007-11-01 15:25:00 +0900 

# This method can't accept usec directly, but the following works:
t2 = Time.new(2007,11,1,15,25,Rational(3, 100), "+09:00")
# => 2007-11-01 15:25:00 +0900 
t2.usec
# => 30000 

I'd like to try and do a pull request which would return time + offset. Or there's some hidden problems I can't see?..

Contributor

zverok commented Feb 16, 2016

Sorry for writing in the old issue, but it seems Time in fact can be constructed in any offset:

t1 = Time.new(2007,11,1,15,25,0, "+09:00")
# => 2007-11-01 15:25:00 +0900 

# This method can't accept usec directly, but the following works:
t2 = Time.new(2007,11,1,15,25,Rational(3, 100), "+09:00")
# => 2007-11-01 15:25:00 +0900 
t2.usec
# => 30000 

I'd like to try and do a pull request which would return time + offset. Or there's some hidden problems I can't see?..

@philr

This comment has been minimized.

Show comment
Hide comment
@philr

philr Feb 16, 2016

Member

@zverok Thanks for letting me know. It looks like this was added in Ruby 1.9.2, but I hadn't spotted it before.

It would certainly be worth looking into using this - I've raised issue #49 for making the change. You are welcome to submit a pull request.

The current version of TZInfo supports Ruby 1.8.7 and later. I'm planning to change to require 1.9.3 from the next release and remove all the code to support earlier Ruby versions. This should simplify the changes needed to use the new Time constructor.

Member

philr commented Feb 16, 2016

@zverok Thanks for letting me know. It looks like this was added in Ruby 1.9.2, but I hadn't spotted it before.

It would certainly be worth looking into using this - I've raised issue #49 for making the change. You are welcome to submit a pull request.

The current version of TZInfo supports Ruby 1.8.7 and later. I'm planning to change to require 1.9.3 from the next release and remove all the code to support earlier Ruby versions. This should simplify the changes needed to use the new Time constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment