Mason Kessinger
2006-Jan-16 23:08 UTC
[Rails] [newbie] This Month / Next Month / The One After That
What I want to do is simple. I''d like code that prints out the name of this month (January) the next month (February) and the one after that (March) I''ve been able to print this month: <% t = Time.now %> <%= t.strftime(" This Month is: %B") %> But I can''t figure out how to get the next months to print out! -- Posted via http://www.ruby-forum.com/.
Jens Alfke
2006-Jan-16 23:24 UTC
[Rails] [newbie] This Month / Next Month / The One After That
On 16 Jan ''06, at 11:53 AM, Mason Kessinger wrote:> I''d like code that prints out the name of this month (January) the > next > month (February) and the one after that (March)I was delving into the time/date morass over the weekend*, so now I get to sound like an expert: Date.today.mon returns the current month number (1..12). Date::MONTHNAMES is an array of month names. Don''t forget to use modular arthmetic, of course :) *And may I take a moment to gripe about how confusing it is that Ruby has entirely distinct Time and Date classes, and that there is no obvious way to convert between them? I spent about an hour on Saturday trying to find a way to compute the number of days between two Times. --Jens -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060116/2eef541d/attachment.html
Francois Beausoleil
2006-Jan-16 23:35 UTC
[Rails] [newbie] This Month / Next Month / The One After That
2006/1/16, Jens Alfke <jens@mooseyard.com>:> *And may I take a moment to gripe about how confusing it is that Ruby has > entirely distinct Time and Date classes, and that there is no obvious way to > convert between them? I spent about an hour on Saturday trying to find a way > to compute the number of days between two Times.Look no further than ActiveSupport: Date#to_time # returns self, converted to a Time @ midnight Date#to_date # returns self Time#to_date # returns self, converted to a Date Time#to_time # returns self Hope that helps ! -- Fran?ois Beausoleil http://blog.teksol.info/
Mason Kessinger
2006-Jan-16 23:39 UTC
[Rails] Re: [newbie] This Month / Next Month / The One After That
Thanks. I''ve only been at this for a few weeks in my spare time so this will save me much headache. I really appreciate your help! mk -- Posted via http://www.ruby-forum.com/.
pm
2006-Jan-23 15:37 UTC
[Rails] Re: [newbie] This Month / Next Month / The One After That
But how to change month names ? to obtain french month for instance.. -- Posted via http://www.ruby-forum.com/.
Jules Jacobs
2006-Jan-23 16:03 UTC
[Rails] Re: [newbie] This Month / Next Month / The One After That
pm wrote:> But how to change month names ? to obtain french month for instance..Just use your own array instead of Date::MONTHNAMES. FRENCH_MONTHNAMES = [''Janvier'', ''Fevrier'', ... , ''Decembre'']> I was delving into the time/date morass over the weekend*, so now I > get to sound like an expert: > Date.today.mon returns the current month number (1..12). > Date::MONTHNAMES is an array of month names. > Don''t forget to use modular arthmetic, of course :)next = 1.month.from_now nextnext = 2.months.from_now <%= next.strftime(" Next Month is: %B") %> <%= nextnext.strftime(" The Month After That One is: %B") %> :) -- Posted via http://www.ruby-forum.com/.
pm
2006-Jan-23 16:41 UTC
[Rails] Re: [newbie] This Month / Next Month / The One After That
thank you for your help.>> But how to change month names ? to obtain french month for instance.. > > Just use your own array instead of Date::MONTHNAMES. > > FRENCH_MONTHNAMES = [''Janvier'', ''Fevrier'', ... , ''Decembre''] >I can use FRENCH_MONTHNAMES like a table.. but I want to replace %B in the expression.. and i can''t =( thanks ;) pm -- Posted via http://www.ruby-forum.com/.
Jules Jacobs
2006-Jan-23 17:29 UTC
[Rails] Re: [newbie] This Month / Next Month / The One After That
pm wrote:> thank you for your help. > >>> But how to change month names ? to obtain french month for instance.. >> >> Just use your own array instead of Date::MONTHNAMES. >> >> FRENCH_MONTHNAMES = [''Janvier'', ''Fevrier'', ... , ''Decembre''] >> > > I can use FRENCH_MONTHNAMES like a table.. > but I want to replace %B in the expression.. and i can''t =( > > thanks ;) > > pmirb(main):001:0> Date::MONTHNAMES => [nil, "January", "February", "March", "April", "May", "June", "July", "August ", "September", "October", "November", "December"] irb(main):002:0> Date::MONTHNAMES[1] = ''Janvier'' => "Janvier" irb(main):003:0> Date::MONTHNAMES[1] => "Janvier" irb(main):004:0> Time.now => Mon Jan 23 18:27:28 West-Europa (standaardtijd) 2006 irb(main):005:0> Time.now.strftime("%B") => "January" irb(main):006:0> :( irb(main):007:1* -- Posted via http://www.ruby-forum.com/.
pm
2006-Jan-24 10:07 UTC
[Rails] Re: [newbie] This Month / Next Month / The One After That
"And finally, everything worked out just fine. Christmas was saved, though there wasn''t much time. But after that night, things were never the same" Danny Elfman =) I have found the solution.. I have override strftime with this code =) And it''s so great =) http://poocs.net/articles/2005/10/04/localization-for-rubys-time-strftime Thanks a lot -- Posted via http://www.ruby-forum.com/.