Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

treacher opened this issue Feb 12, 2015 · 3 comments
Labels

Comments

@treacher
Copy link

@treacher treacher commented Feb 12, 2015

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
Copy link
Member

@philr 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
Copy link
Contributor

@zverok 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
Copy link
Member

@philr 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.