A little app I wrote has a calendar view for three months. Everything went fine until today, when it didn''t display August - September - October, but August - August - September. Next month had become this month. Watch this:>> Time.now=> Wed Aug 01 21:13:55 +0200 2007>> 1.month.from_now=> Fri Aug 31 21:14:01 +0200 2007>> Time.now.advance :months=>1=> Sat Sep 01 21:14:13 +0200 2007 Especially annoying since the rdoc for ActiveSupport::CoreExtensions::Numeric::Time pretends that:> These methods use Time#advance for precise date calculations when using > from_now, ago, etc. as well as adding or subtracting their results from a Time > object. For example: > > # equivalent to Time.now.advance(:months => 1) > 1.month.from_nowIt''s NOT equivalent. It''s broken. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Boop Boop wrote:> >> Time.now > => Wed Aug 01 21:13:55 +0200 2007 > >> 1.month.from_nowWe got that yesterday, with 1.month and 1.month.ago.> It''s NOT equivalent. It''s broken.+1. Now how to reconcile 1.month meaning two things - "one month''s worth of seconds" and "a month offset from this month"? -- Phlip http://www.oreilly.com/catalog/9780596510657/ ^ assert_xpath http://tinyurl.com/yrc77g <-- assert_latest Model --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Boop Boop wrote:> A little app I wrote has a calendar view for three months. > Everything went fine until today, when it didn''t display August - > September - October, but August - August - September. Next month had > become this month. > > Watch this: > >>> Time.now > => Wed Aug 01 21:13:55 +0200 2007 >>> 1.month.from_now > => Fri Aug 31 21:14:01 +0200 2007 >>> Time.now.advance :months=>1 > => Sat Sep 01 21:14:13 +0200 2007 > > Especially annoying since the rdoc for > ActiveSupport::CoreExtensions::Numeric::Time pretends that: > >> These methods use Time#advance for precise date calculations when using >> from_now, ago, etc. as well as adding or subtracting their results from a Time >> object. For example: >> >> # equivalent to Time.now.advance(:months => 1) >> 1.month.from_now > > It''s NOT equivalent. It''s broken.Where did you get this? I just checked the API docs at: http://api.rubyonrails.com/classes/ActiveSupport/CoreExtensions/Numeric/Time.html And they explicitly state that: If you need precise date calculations that doesn''t just treat months as 30 days, then have a look at Time#advance. Some of these methods are approximations, Ruby''s core Date and Time should be used for precision date and time arithmetic -- Cheers, - Jacob Atzen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Aug 1, 2007, at 3:42 PM, Jacob Atzen wrote:> Boop Boop wrote: >> A little app I wrote has a calendar view for three months. >> Everything went fine until today, when it didn''t display August - >> September - October, but August - August - September. Next month had >> become this month. >> >> Watch this: >> >>>> Time.now >> => Wed Aug 01 21:13:55 +0200 2007 >>>> 1.month.from_now >> => Fri Aug 31 21:14:01 +0200 2007 >>>> Time.now.advance :months=>1 >> => Sat Sep 01 21:14:13 +0200 2007 >> >> Especially annoying since the rdoc for >> ActiveSupport::CoreExtensions::Numeric::Time pretends that: >> >>> These methods use Time#advance for precise date calculations when >>> using >>> from_now, ago, etc. as well as adding or subtracting their >>> results from a Time >>> object. For example: >>> >>> # equivalent to Time.now.advance(:months => 1) >>> 1.month.from_now >> >> It''s NOT equivalent. It''s broken. > > Where did you get this? > > I just checked the API docs at: > > http://api.rubyonrails.com/classes/ActiveSupport/CoreExtensions/ > Numeric/Time.html > > And they explicitly state that: > > If you need precise date calculations that doesn''t just treat > months as 30 days, then have a look at Time#advance. > > Some of these methods are approximations, Ruby''s core Date and > Time should be used for precision date and time arithmetic > > -- > Cheers, > - Jacob AtzenJust read the right docs: Time#months_ago and Time#months_since http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/ Calculations.html#M000330 >> Time.now.months_since(1) => Sat Sep 01 18:57:06 -0400 2007 -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---