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

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

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

Show comment
Hide comment
@gnib

gnib 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.

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

This comment has been minimized.

Show comment
Hide comment
@philr

philr May 1, 2014

Member

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@davispuh

davispuh 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.

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

This comment has been minimized.

Show comment
Hide comment
@gnib

gnib 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/tzinfo/tzinfo/issues/19#issuecomment-41934860
.

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/tzinfo/tzinfo/issues/19#issuecomment-41934860
.

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