Hey guys, Every time I build a calendar system or anything with an annually recurring set of dates, I find myself doing this all the time to avoid getting invalid date exceptions: year = Date.today.year if (year % 4 != 0) && rhs.month == 2 && rhs.day == 29 rday = 28 else rday = rhs.day end date = Date.new(year, rhs.month, rday) Would anybody be interested in a patch so we could just do: Date.new(year, rhs.month, rhs.day, :fix_leap_year => true) Maybe even make :fix_leap_year => true the default behavior? Thanks, Ryan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Where does ''rhs'' come from? On Mon, Apr 20, 2009 at 8:01 AM, Ryan Angilly <angilly@gmail.com> wrote:> Hey guys, > > Every time I build a calendar system or anything with an annually recurring > set of dates, I find myself doing this all the time to avoid getting invalid > date exceptions: > > year = Date.today.year > > if (year % 4 != 0) && rhs.month == 2 && rhs.day == 29 > rday = 28 > else > rday = rhs.day > end > > date = Date.new(year, rhs.month, rday) > > Would anybody be interested in a patch so we could just do: > > Date.new(year, rhs.month, rhs.day, :fix_leap_year => true) > > Maybe even make :fix_leap_year => true the default behavior? > > > Thanks, > Ryan > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
In this case it''s a model with month and day attributes. On Mon, Apr 20, 2009 at 8:13 AM, Jordi <jordi@bunster.org> wrote:> Where does ''rhs'' come from? > > > On Mon, Apr 20, 2009 at 8:01 AM, Ryan Angilly <angilly@gmail.com> wrote: > >> Hey guys, >> >> Every time I build a calendar system or anything with an annually >> recurring set of dates, I find myself doing this all the time to avoid >> getting invalid date exceptions: >> >> year = Date.today.year >> >> if (year % 4 != 0) && rhs.month == 2 && rhs.day == 29 >> rday = 28 >> else >> rday = rhs.day >> end >> >> date = Date.new(year, rhs.month, rday) >> >> Would anybody be interested in a patch so we could just do: >> >> Date.new(year, rhs.month, rhs.day, :fix_leap_year => true) >> >> Maybe even make :fix_leap_year => true the default behavior? >> >> >> Thanks, >> Ryan >> >> >> > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Oh, I get your problem. You want Date.new to change 29 to 28 if it was given february, but outside of a leap year. I don''t think this is the right forum for this discussion. Date is actually part of the Ruby library. Try one of the lists at http://www.ruby-lang.org/en/community/mailing-lists/. On Mon, Apr 20, 2009 at 8:22 AM, Ryan Angilly <angilly@gmail.com> wrote:> In this case it''s a model with month and day attributes. > > > On Mon, Apr 20, 2009 at 8:13 AM, Jordi <jordi@bunster.org> wrote: > >> Where does ''rhs'' come from? >> >> >> On Mon, Apr 20, 2009 at 8:01 AM, Ryan Angilly <angilly@gmail.com> wrote: >> >>> Hey guys, >>> >>> Every time I build a calendar system or anything with an annually >>> recurring set of dates, I find myself doing this all the time to avoid >>> getting invalid date exceptions: >>> >>> year = Date.today.year >>> >>> if (year % 4 != 0) && rhs.month == 2 && rhs.day == 29 >>> rday = 28 >>> else >>> rday = rhs.day >>> end >>> >>> date = Date.new(year, rhs.month, rday) >>> >>> Would anybody be interested in a patch so we could just do: >>> >>> Date.new(year, rhs.month, rhs.day, :fix_leap_year => true) >>> >>> Maybe even make :fix_leap_year => true the default behavior? >>> >>> >>> Thanks, >>> Ryan >>> >>> >>> >> >> >> > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---