Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # When adding or subtracting DateTime objects, the return type is a Rational expressing the fraction of a day's number of minutes (1440). So 0.5 would mean half a day, or 720 minutes, or 12 hours.
- # When adding or subtracting Time objects, the return type is Float expressing the difference in seconds.
- #Here's an example showing the difference between two times that are an hour apart:
- MINUTES_IN_A_DAY = 1440
- ref1 = "2018-03-13T08:00:00+00:00"
- ref2 = "2018-03-13T09:00:00+00:00"
- # -3600 = 3600 seconds ago, i.e. 1 hour ago
- Time.zone.iso8601(ref1) - Time.zone.iso8601(ref2)
- # => -3600.0
- # You'd get the same result if you did 60.0 / 1440.0
- DateTime.iso8601(ref1) - DateTime.iso8601(ref2)
- # => (-1/24)
- # Shown another way, convert to float and multiply by 1440 minutes to get
- # difference in minutes
- (DateTime.iso8601(ref1) - DateTime.iso8601(ref2)).to_f * MINUTES_IN_A_DAY
- # => -60.0
Add Comment
Please, Sign In to add comment