Hey all, I was wondering what decision led to the cut off point in ActiveSupport::Duration where a duration''s switches from listing the tracking itself by its own time unit value (year, month, day) and switches to seconds (hour, minutes, and seconds) e.g. 1.year + 2.months # => 1 year and 2 months>> 1.year + 2.months + 4.days#=> 1 year, 2 months, and 4 days But 4.days + 3.hours #=> 4 days and 10800 seconds (I''d expect ''4 days and 3 hours'') 4.days + 3.hours + 12.minutes #=> 4 days and 11520 seconds (I''d expect ''4 days, 3 hours, and 12 minutes) I can see from ActiveSupport::CoreExtensions::Numeric::Time that hours and minutes define themselves in terms of seconds, but was wondering if anyone could shed light on why this organized this way. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Koziarski
2008-Mar-19 20:58 UTC
Re: Historical Question about ActiveSupport::Duration objects
> I was wondering what decision led to the cut off point in > ActiveSupport::Duration where a duration''s switches from listing the > tracking itself by its own time unit value (year, month, day) and > switches to seconds (hour, minutes, and seconds) > e.g. > > 1.year + 2.months > # => 1 year and 2 months > > >> 1.year + 2.months + 4.days > #=> 1 year, 2 months, and 4 days > > But > 4.days + 3.hours > #=> 4 days and 10800 seconds > (I''d expect ''4 days and 3 hours'') > > 4.days + 3.hours + 12.minutes > #=> 4 days and 11520 seconds > (I''d expect ''4 days, 3 hours, and 12 minutes) > > I can see from ActiveSupport::CoreExtensions::Numeric::Time that hours > and minutes define themselves in terms of seconds, but was wondering > if anyone could shed light on why this organized this way.Historically they were all defined in terms of seconds which meant they were frequently incorrect when used for calculations due to DST, varying length months and leap years. Good enough for "show me last month''s blog posts" but not for "advance the due date by one month" or "release the prisoner in 1 year". To fix those errors years, months, days etc need to be treated differently. But hours and minutes are still correct when treated as seconds, so they never needed to be redefined. We could change them but it seems like it''ll just slow things down a little for some slightly nicer #inspect output. That''s my understanding anyway. -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---