>> 0.upto(11) do |n|?> puts Time.now.beginning_of_month.ago(n.months)>> endSat Mar 01 00:00:00 -0600 2008 Thu Jan 31 00:00:00 -0600 2008 Tue Jan 01 00:00:00 -0600 2008 Sun Dec 02 00:00:00 -0600 2007 Fri Nov 02 00:00:00 -0500 2007 Wed Oct 03 00:00:00 -0500 2007 Mon Sep 03 00:00:00 -0500 2007 Sat Aug 04 00:00:00 -0500 2007 Thu Jul 05 00:00:00 -0500 2007 Tue Jun 05 00:00:00 -0500 2007 Sun May 06 00:00:00 -0500 2007 Fri Apr 06 00:00:00 -0500 2007 Uhhh....where is Feb in this list... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Here it is, could of sworn I was doing it this way already, sorry about that internet...>> 0.upto(11) do |n|?> puts Time.now.beginning_of_month.months_ago(n)>> endSat Mar 01 00:00:00 -0600 2008 Fri Feb 01 00:00:00 -0600 2008 Tue Jan 01 00:00:00 -0600 2008 Sat Dec 01 00:00:00 -0600 2007 Thu Nov 01 00:00:00 -0500 2007 Mon Oct 01 00:00:00 -0500 2007 Sat Sep 01 00:00:00 -0500 2007 Wed Aug 01 00:00:00 -0500 2007 Sun Jul 01 00:00:00 -0500 2007 Fri Jun 01 00:00:00 -0500 2007 Tue May 01 00:00:00 -0500 2007 Sun Apr 01 00:00:00 -0500 2007 On Mar 6, 12:19 am, uncle <akt...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> >> 0.upto(11) do |n| > > ?> puts Time.now.beginning_of_month.ago(n.months)>> end > > Sat Mar 01 00:00:00 -0600 2008 > Thu Jan 31 00:00:00 -0600 2008 > Tue Jan 01 00:00:00 -0600 2008 > Sun Dec 02 00:00:00 -0600 2007 > Fri Nov 02 00:00:00 -0500 2007 > Wed Oct 03 00:00:00 -0500 2007 > Mon Sep 03 00:00:00 -0500 2007 > Sat Aug 04 00:00:00 -0500 2007 > Thu Jul 05 00:00:00 -0500 2007 > Tue Jun 05 00:00:00 -0500 2007 > Sun May 06 00:00:00 -0500 2007 > Fri Apr 06 00:00:00 -0500 2007 > > Uhhh....where is Feb in this list...--~--~---------~--~----~------------~-------~--~----~ 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 6 Mar 2008, at 06:19, uncle wrote:> >>> 0.upto(11) do |n| > ?> puts Time.now.beginning_of_month.ago(n.months) >>> endSounds like you''re using rails 1.x. n.months (or n.days etc...) used to be dumb: it just converted an integer into a corresponding number of seconds, an approach with obvious limitations. In rails 2, it''s smarter and leverages Date to di it''s computations, so when I run your code I get Sat Mar 01 00:00:00 UTC 2008 Fri Feb 01 00:00:00 UTC 2008 Tue Jan 01 00:00:00 UTC 2008 Sat Dec 01 00:00:00 UTC 2007 Thu Nov 01 00:00:00 UTC 2007 Mon Oct 01 00:00:00 UTC 2007 Sat Sep 01 00:00:00 UTC 2007 Wed Aug 01 00:00:00 UTC 2007 Sun Jul 01 00:00:00 UTC 2007 Fri Jun 01 00:00:00 UTC 2007 Tue May 01 00:00:00 UTC 2007 Sun Apr 01 00:00:00 UTC 2007 (Note also how your code drifts, because it''s effectively just subtracting a fixed number of days and not all months have the same length). If you''re stuck with 1.x this probably does the trick too 0.upto(11) do |n| puts Time.now.months_ago(n).beginning_of_month end Fred>>> > Sat Mar 01 00:00:00 -0600 2008 > Thu Jan 31 00:00:00 -0600 2008 > Tue Jan 01 00:00:00 -0600 2008 > Sun Dec 02 00:00:00 -0600 2007 > Fri Nov 02 00:00:00 -0500 2007 > Wed Oct 03 00:00:00 -0500 2007 > Mon Sep 03 00:00:00 -0500 2007 > Sat Aug 04 00:00:00 -0500 2007 > Thu Jul 05 00:00:00 -0500 2007 > Tue Jun 05 00:00:00 -0500 2007 > Sun May 06 00:00:00 -0500 2007 > Fri Apr 06 00:00:00 -0500 2007 > > > Uhhh....where is Feb in this list... > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
uncle wrote:> Here it is, could of sworn I was doing it this way already, sorry > about that internet...On behalf of the internet, I forgive you! -- 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 -~----------~----~----~----~------~----~------~--~---