Skip to content

Instantly share code, notes, and snippets.

@ramhoj
Created March 23, 2012 13:04
Show Gist options
  • Select an option

  • Save ramhoj/2170462 to your computer and use it in GitHub Desktop.

Select an option

Save ramhoj/2170462 to your computer and use it in GitHub Desktop.
Time.zone.parse bug
# Use
DateTime.parse("2012-03-25 03:29").in_time_zone(Time.zone)
# Instead of
Time.zone.parse("2012-03-25 03:29")
# Until the pull request https://github.com/jarkko/rails/commit/bb4a1d68f6db8bf99d2b6e21eee72a19d494dee0 has been pulled into Rails.
@jarkko

jarkko commented Mar 23, 2012

Copy link
Copy Markdown

Looks dandy. Note though that the second example shouldn't push the time up by an hour. The problem of course is that if you'd use PST instead (i.e. are not sure whether it is or is not DST at that point), it would break:

1.9.3p125 :104 > Time.zone.parse("2012-03-25 03:29 PDT")
 => Sun, 25 Mar 2012 03:29:00 PDT -07:00 
1.9.3p125 :105 > Time.zone.parse("2012-03-25 03:29 PST")
 => Sun, 25 Mar 2012 04:29:00 PDT -07:00 

@jarkko

jarkko commented Mar 23, 2012

Copy link
Copy Markdown

So yeah, go ahead :-)

@ramhoj

ramhoj commented Mar 23, 2012

Copy link
Copy Markdown
Author

Damn you copy-pate! :).

Thanks for catching that. The blog post is now updated at http://elabs.se/blog/36-working-with-time-zones-in-ruby-on-rails#bug_in_timezoneparse

I really appreciate you going down to the bottom of this issue. I know that I've seen it briefly before but it went a way and I didn't had the time to understand what was really going on. Great to have it all figured out now!

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