The Time and Date class treat edge cases differently. This is prone to introduce errors since they are often used
together.
Example 1: 24:00 is valid in DateTime but not in Time
puts DateTime::valid_time?(24,0,0) # => 1 (valid)
puts Time.utc(2007,1,1,24,0) # => Argument error: argument out of range
Example 2: 31st of april wraps around in Time but is an error in Date
puts Time.parse("4/31/2007") # => Tue May 1 00:00:00 2007
puts DateTime.parse("4/31/2007") # => Argument error: invalid date
Especially the first one is annoying because you need to check for "hour==24" everywhere you parse a human
entered string into a since otherwise it will parse and validate fine but then error out when you try to make a time
out of it. (Try out entering 24:00 as a time in a random RoR application and see it crash :-/) |