Re: Error with the leap year
[email protected] (Karen Etheridge)
| Newsgroups | perl.datetime |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Mar 01, 2012 at 08:26:13PM -0800, Michael G Schwern wrote: > 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"? This is very similar to the 'end_of_month_mode' feature in DateTime::Duration, which handles how (for example) "Jan 30 + 1 month" calculations are handled. Therefore, I would suggest a configuration option for handling how wrapping is done involving leap years. For that matter, leap seconds pose the same problem - if 00:00:60 is a leap second, how does one handle 00:00:60 + 1 minute? is it wrapped to the next minute (00:02:00), truncated (00:01:59), or...? -- #!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj $/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1 lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/) . . . . . Karen Etheridge, [email protected] GCS C+++$ USL+++$ P+++$ w--- M++