DateTime.strptime not work with "Arizona" #8

Closed
jainankush12 opened this Issue Oct 30, 2013 · 1 comment

Comments

Projects
None yet
2 participants
@jainankush12

We are using "ActiveSupport::TimeZone.us_zones" to get US zones.

DateTime.strptime works fine with zone "Central Time (US & Canada)":

DateTime.strptime("10/01/2013 12:00 PM Central Time (US & Canada)".strip, "%m/%d/%Y %I:%M %p %Z")

=> Tue, 01 Oct 2013 12:00:00 -0600

but for Arizona:

DateTime.strptime("10/01/2013 12:00 PM Arizona".strip, "%m/%d/%Y %I:%M %p %Z")

=> Tue, 01 Oct 2013 12:00:00 +0000

Result should be => Tue, 01 Oct 2013 12:00:00 -0700

@philr

This comment has been minimized.

Show comment
Hide comment
@philr

philr Oct 30, 2013

Member

This isn't an issue with TZInfo. TZInfo doesn't have any knowledge of the ActiveSupport time zones and doesn't override core Ruby methods such as DateTime.strptime.

I don't think ActiveSupport overrides DateTime.strptime either, so you're going to be calling the Ruby standard library implementation. This also has no knowledge of ActiveSupport's time zones and therefore cannot do what you are expecting.

You may want to look into using ActiveSupport::TimeWithZone instead.

Member

philr commented Oct 30, 2013

This isn't an issue with TZInfo. TZInfo doesn't have any knowledge of the ActiveSupport time zones and doesn't override core Ruby methods such as DateTime.strptime.

I don't think ActiveSupport overrides DateTime.strptime either, so you're going to be calling the Ruby standard library implementation. This also has no knowledge of ActiveSupport's time zones and therefore cannot do what you are expecting.

You may want to look into using ActiveSupport::TimeWithZone instead.

@philr philr closed this Oct 30, 2013

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