Created
April 29, 2009 04:09
-
-
Save bjeanes/103571 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # If it is going to make it a UTC time, it should | |
| # at least convert it but it just assumes it is | |
| # UTC without even looking at the time zone | |
| time = "2007-08-05T20:00:00-04:00" | |
| Time.parse(time) # => Mon Aug 06 10:00:00 1000 2007 | |
| time.to_time # => Sun Aug 05 20:00:00 UTC 2007 | |
| # Fix: | |
| class String | |
| def to_time(form = :utc) | |
| time = Time.parse(self) | |
| form.to_sym == :utc ? time.utc : time | |
| end | |
| end | |
| puts time.to_time # => Mon Aug 06 00:00:00 UTC 2007 | |
| puts time.to_time(:local) # => Mon Aug 06 10:00:00 1000 2007 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment