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

Reverse lookup? #22

Closed
bradpauly opened this issue Jun 27, 2014 · 1 comment
Closed

Reverse lookup? #22

bradpauly opened this issue Jun 27, 2014 · 1 comment
Labels

Comments

@bradpauly
Copy link

@bradpauly bradpauly commented Jun 27, 2014

Hi, I hope it's okay to ask a question here. I was going to post to the mailing list, but rubyforge seems to be gone.

I'd like to find the zone identifiers where the local time is a certain time. For example, in which zones is it currently 6pm?

The best I could come up with on my own was to look at all zones and check the time in each one. Is there another way to do this? I've been browsing http://rubydoc.info/gems/tzinfo/TZInfo without much luck. Any ideas or suggestions on where to read on rubydoc would be great. Thanks!

@philr
Copy link
Member

@philr philr commented Jun 30, 2014

There's nothing in TZInfo that will do what you want directly.

Depending on exactly how you want to handle daylight savings transitions, your best option might be to calculate and store the offset of each time zone and use this to group the time zones you are interested in.

This will give you the base offset from UTC in seconds for timezone:

timezone.current_period.utc_offset

The Timezone#current_period method returns a TimezonePeriod object representing the offset that is currently in force for the time zone.

The TimezonePeriod#utc_offset method doesn't include the additional +1 hour for daylight savings, so will be the same all year round for most time zones. Use TimezonePeriod#utc_total_offset instead of you want to get the offset including the effect of daylight savings.

@philr philr added the question label Jun 30, 2014
@philr philr closed this Jun 30, 2014
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
2 participants
You can’t perform that action at this time.