In my app, I am using
> Time.parse('12:30 pm MDT').utc
=> 2015-06-08 18:30:00 UTC
> Time.parse('12:30 pm EDT').utc
=> 2015-06-08 16:30:00 UTC
> Time.parse('12:30 pm CDT').utc
=> 2015-06-08 17:30:00 UTC
> Time.parse('12:30 pm PDT').utc
=> 2015-06-08 19:30:00 UTC
> Time.parse('12:30 pm MST').utc
=> 2015-06-08 19:30:00 UTC
Which all works just fine, but as soon as I start asking for hawaii or alaskan timezones, it returns an incorrect result:
> Time.parse('12:30 pm HST').utc
=> 2015-06-08 12:30:00 UTC
> Time.parse('12:30 pm HAST').utc
=> 2015-06-08 12:30:00 UTC
> Time.parse('12:30 pm AKDT').utc
=> 2015-06-08 12:30:00 UTC
> Time.parse('12:30 pm AKST').utc
=> 2015-06-08 12:30:00 UTC
Even this does not work:
> Time.parse('12:30 pm -800').utc
=> 2015-06-08 12:30:00 UTC
Does anyone have any idea why this is happening? And perhaps more importantly, does anyone have any advice about how to parse a time that is -800 or -900?
The documentation of
Time.parse
contains (emphasis mine):The following is from the syntax description in RFC 822 (5.1):
As you can see your timezone names aren't mentioned. You have to write
-0800
and-0900
as the leading zero is required (to match the4DIGIT
part). If you want or have to keep the names, the more sophisticatedDateTime
class can be used.