bjeanes (owner)

Revisions

gist: 103571 Download_button fork
public
Public Clone URL: git://gist.github.com/103571.git
Embed All Files: show embed
rails_bug?.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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