On 2012.3.1 2:14 PM, [email protected] wrote:
> If the date for $dt is 20120229, the following produces an error!
> 
> $dt->set_year($dt1->year + 1);
> 
> Invalid day of month (day = 29 - month = 2)

This error is correct, there is no Feb 29, 2013.

It could return March 1, 2013... but then adding a year to Feb 29, 2012 and
adding a year and a day give the same result which doesn't make sense.

It does present a problem... how do you reliably say "same date next year"?
You can't add 365 days because that falls afoul of the leap year problem.  If
you asked a human "let's schedule for the same day next year" you'd have to
ask if they meant Feb 28th or March 1st.  So I think throwing an exception is
the right thing to do.  The application can catch it and ask the user for
clarification.

Reply via email to