Let''s say I have this: @start_date = 1.month.from_now I want to make sure that the "day" for @start_date is always 1. How can I change the day for @start_date? -- 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 -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2007-Jun-01 18:48 UTC
Re: Easy Question: How to set the day for a Time object?
On Jun 1, 2007, at 2:14 PM, Joe Peck wrote:> Let''s say I have this: > @start_date = 1.month.from_now > > I want to make sure that the "day" for @start_date is always 1. > How can > I change the day for @start_date? > > --Depending on what you want: >> Time.now => Fri Jun 01 14:47:42 -0400 2007 >> Time.now.next_month.beginning_of_month => Sun Jul 01 00:00:00 -0400 2007 >> 1.month.from_now.beginning_of_week => Mon Jun 25 00:00:00 -0400 2007 Your choice. -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 -~----------~----~----~----~------~----~------~--~---
Dave Coleman
2007-Jun-01 18:52 UTC
Re: Easy Question: How to set the day for a Time object?
Joe Peck wrote:> Let''s say I have this: > @start_date = 1.month.from_now > > I want to make sure that the "day" for @start_date is always 1. How can > I change the day for @start_date?@start_date = 1.month.from_now.beginning_of_month Should work for ya. -- 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 -~----------~----~----~----~------~----~------~--~---
> >> Time.now.next_month.beginning_of_month > => Sun Jul 01 00:00:00 -0400 2007That is perfect. Thank you; is there a list of these methods somewhere? I''ve been looking for them, but haven''t found them... -- 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 -~----------~----~----~----~------~----~------~--~---
sean.seanlynch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-01 19:13 UTC
Re: Easy Question: How to set the day for a Time object?
On Jun 1, 1:54 pm, Joe Peck <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > >> Time.now.next_month.beginning_of_month > > => Sun Jul 01 00:00:00 -0400 2007 > > That is perfect. Thank you; is there a list of these methods somewhere? > I''ve been looking for them, but haven''t found them... > > -- > Posted viahttp://www.ruby-forum.com/.The short answer (though overwhelming) is here: http://www.ruby-doc.org/ The search function leads you to: http://facets.rubyforge.org/src/doc/rdoc/more/classes/Time.html#M000174 Of course thats easy when you know the method name. If you are new to Ruby, have patience. You will learn. The pickaxe book is invaluable: --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2007-Jun-01 19:17 UTC
Re: Easy Question: How to set the day for a Time object?
On Jun 1, 2007, at 2:54 PM, Joe Peck wrote:> >>>> Time.now.next_month.beginning_of_month >> => Sun Jul 01 00:00:00 -0400 2007 > That is perfect. Thank you; is there a list of these methods > somewhere? > I''ve been looking for them, but haven''t found them... > > --Look at the API docs for ActiveSupport::CoreExtensions::Time::Calculations FYI, note the difference between: 2.months.from_now and Time.now.months_since(2) # aka, Time.now.next_month.next_month -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 -~----------~----~----~----~------~----~------~--~---
Sharon Machlis
2007-Jun-01 19:23 UTC
Re: Easy Question: How to set the day for a Time object?
If you''re just looking for all the methods for the Time class specifically, I''d suggest trying here: http://www.ruby-doc.org/core/classes/Time.html There''s also a list of some of the classes and methods here: http://dev.rubycentral.com/ref/ It doesn''t look to be 100% complete, but there are a lot of methods listed for many of the built-in classes, including Time http://dev.rubycentral.com/ref/ref_c_time.html The Ruby Cookbook can be helpful also, giving suggestions on different problems and how to solve them. I need to listen to the advice given above, since I''m also new to Ruby and need to have patience.> That is perfect. Thank you; is there a list of these methods somewhere? > I''ve been looking for them, but haven''t found them...-- 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 -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2007-Jun-01 20:07 UTC
Re: Easy Question: How to set the day for a Time object?
But since the OP used .from_now which is a method added by ActiveSupport and this *is* the Rails list, it''s appropriate to point at the Rails API rather than just the Ruby Time class docs. (Not that they wouldn''t be helpful, you just won''t find all of "these methods" if you limit "somewhere" to Ruby''s core docs.) -Rob On Jun 1, 2007, at 3:23 PM, Sharon Machlis wrote:> > If you''re just looking for all the methods for the Time class > specifically, I''d suggest trying here: > > http://www.ruby-doc.org/core/classes/Time.html > > There''s also a list of some of the classes and methods here: > > http://dev.rubycentral.com/ref/ > > It doesn''t look to be 100% complete, but there are a lot of methods > listed for many of the built-in classes, including Time > > http://dev.rubycentral.com/ref/ref_c_time.html > > The Ruby Cookbook can be helpful also, giving suggestions on different > problems and how to solve them. I need to listen to the advice given > above, since I''m also new to Ruby and need to have patience. > >> That is perfect. Thank you; is there a list of these methods >> somewhere? >> I''ve been looking for them, but haven''t found them...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 -~----------~----~----~----~------~----~------~--~---
Sharon Machlis
2007-Jun-01 20:40 UTC
Re: Easy Question: How to set the day for a Time object?
Yes, good point, of course the Ruby classes wouldn''t include all the Rails options. I just happened to have those handy because I was working on some quick date formatting this morning. The Rails API is definitely a more complete and appropriate choice for this list. Rob Biedenharn wrote:> But since the OP used .from_now which is a method added by > ActiveSupport and this *is* the Rails list, it''s appropriate to point > at the Rails API rather than just the Ruby Time class docs. (Not > that they wouldn''t be helpful, you just won''t find all of "these > methods" if you limit "somewhere" to Ruby''s core docs.) > > -Rob > > On Jun 1, 2007, at 3:23 PM, Sharon Machlis wrote: > >> It doesn''t look to be 100% complete, but there are a lot of methods >>> I''ve been looking for them, but haven''t found them... > Rob Biedenharn http://agileconsultingllc.com > Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org-- 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 -~----------~----~----~----~------~----~------~--~---