Re: Error with the leap year
[email protected] (Rick Measham)
| Newsgroups | perl.datetime |
|---|---|
| Message-ID | <[email protected]> |
No configuration option is required in this case. The OP isn't having trouble with date math: that would have done what he wanted. He's using the set() method to set the object to a date that doesn't exist. Any behavior beyond an error would be incorrect. Should ->new( year => 2012, month => 13, day => 42 ) assume you wanted Dec 31? No, it's an error. If you wanted 13 months, 42 days after Jan 1st 2012, then you should be using date math. Cheers! Rick Measham đŸ“± On 03/03/2012, at 5:14, Karen Etheridge <[email protected]> wrote: > 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++ > -- > Message protected for iSite by MailGuard: e-mail anti-virus, anti-spam and content filtering.http://www.mailguard.com.au > Click here to report this message as spam: > https://login.mailguard.com.au/report/1EfBtCKdpY/2VzzLrnXo9n13n6snrZNTJ/0 > -- Message protected for iSite by MailGuard: e-mail anti-virus, anti-spam and content filtering.http://www.mailguard.com.au