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

TZInfo cannot parse 2-letter time code "ET"? #19

Closed
gnib opened this issue May 1, 2014 · 4 comments
Closed

TZInfo cannot parse 2-letter time code "ET"? #19

gnib opened this issue May 1, 2014 · 4 comments
Labels

Comments

@gnib
Copy link

@gnib gnib commented May 1, 2014

It seems TZInfo doesn't recognize time strings with 2-letter timezone codes, for examples:

irb(main):001:0> require 'tzinfo'
=> true
irb(main):002:0> DateTime.parse('01:30 am ET')
=> #<DateTime:
2014-04-30T01:30:00+00:00 ((2456778j,5400s,0n),+0s,2299161j)>
irb(main):003:0> DateTime.parse('01:30 am')
=> #<DateTime:
2014-04-30T01:30:00+00:00 ((2456778j,5400s,0n),+0s,2299161j)>
irb(main):004:0> DateTime.parse('01:30 am EDT')
=> #<DateTime:
2014-04-30T01:30:00-04:00 ((2456778j,19800s,0n),-14400s,2299161j)>
irb(main):005:0> Time.parse('1:30am ET')
=> 2014-04-30 01:30:00 -0700
irb(main):006:0> Time.parse('1:30am')
=> 2014-04-30 01:30:00 -0700
irb(main):007:0> Time.parse('1:30am EDT')
=> 2014-04-29 22:30:00 -0700
irb(main):008:0> Time.parse('1:30am Est')
=> 2014-04-29 23:30:00 -0700
irb(main):009:0>

As you could see, timzone code "ET" was basically ignored, while "EDT" and "EST" were parsed correctly. Is this intended?

I think the best behavior would be to take "ET" (or "PT", "CT", etc) as "EDT" if it's daylight saving time like right now, and as "EST" if not in DST, what do you think? By the way, I'm in PDT, thus the -0700 offset.

Is there a workaround to parse the 2-letter timezone codes?

Thanks!

@gnib
Copy link
Author

@gnib gnib commented May 1, 2014

Sorry, I just realized that the parse() method may not have been implemented in TZInfo, is it in 'date' or 'time'? Thanks.

@philr philr added the question label May 1, 2014
@philr
Copy link
Member

@philr philr commented May 1, 2014

Time.parse and DateTime.parse are not implemented by TZInfo. They are from the Ruby core and standard libraries respectively.

I think that Time.parse calls the parsing code from date internally.

@philr philr closed this May 1, 2014
@davispuh
Copy link

@davispuh davispuh commented May 1, 2014

If you want to parse such date/time formats with non-typical timezone names, your best bet currently is to look at Chronic and TimezoneParser. Only currently Chronic doesn't have proper timezone support yet, but it's planned to be implemented using TimezoneParser gem.

@gnib
Copy link
Author

@gnib gnib commented May 1, 2014

Thanks a lot for the info! I will check them out.

On Thu, May 1, 2014 at 10:44 AM, Dāvis notifications@github.com wrote:

If you want to parse such date/time formats with non-typical timezone
names, your best bet currently is to look at Chronichttp://mojombo/chronicand
TimezoneParser http://davispuh/TimezoneParser. Only currently Chronic
doesn't have proper timezone support yet, but it's planned to be
implemented using TimezoneParser gem.


Reply to this email directly or view it on GitHubhttps://github.com//issues/19#issuecomment-41934860
.

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.