Skip to content

Allow setting a default time zone for Time.parse#60

Open
jeremyevans wants to merge 1 commit intoruby:masterfrom
jeremyevans:parse-default-timezone
Open

Allow setting a default time zone for Time.parse#60
jeremyevans wants to merge 1 commit intoruby:masterfrom
jeremyevans:parse-default-timezone

Conversation

@jeremyevans
Copy link
Copy Markdown
Contributor

This is to allow for easier conversion of DateTime.parse code to Time.parse. DateTime.parse will assume UTC for parsed times without a time zone or offset, while Time will assume local time. This allows using zone: "UTC" to match the DateTime.parse behavior.

Ideally, it would have pulled the timezone from the now argument, but I believe that backwards incompatibility from doing that now is too great.

You can work around this now by appending " UTC" to the parsed string, as that is ignored if the string actually has a timezone or offset, but that doesn't seem like a clean approach.

This is to allow for easier conversion of DateTime.parse code to
Time.parse. DateTime.parse will assume UTC for parsed times without a
time zone or offset, while Time will assume local time. This allows
using `zone: "UTC"` to match the DateTime.parse behavior.

Ideally, it would have pulled the timezone from the `now` argument,
but I believe that backwards incompatibility from doing that now
is too great.

You can work around this now by appending " UTC" to the parsed string,
as that is ignored if the string actually has a timezone or offset,
but that doesn't seem like a clean approach.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant