in reply to Year /^\d+$/ bug!

I'd write that up and send it to the module's author. Sounds buggy to me. At the very least, it should return an error code that there is no Feb 29th. On a more Perlish level, it should try and 'do the right thing'.

My personal opinion on the 'right thing' is that +1 month refers to the next month, so wrapping Feb 29th (non-leap year) to March 1st seems wrong. (I would have a differnt feeling for adding a month worth of days.) But truncating it down to Feb 28th also seems wrong. Perhaps an error code is the best result.

But in any case, let the author know. Sounds like they didn't come across that condition, so never checked for it. Feedback is important to keeping the quality of modules high.

=Blue
...you might be eaten by a grue...

Replies are listed 'Best First'.
Re: Re: Year /^\d+$/ bug!
by $code or die (Deacon) on Nov 30, 2000 at 00:59 UTC
    Hmmm, I just tried it again and it seems to work:
    perl -MDate::Calc -MData::Dumper -e "print Dumper(\Date::Calc::Add_Delta_YMD(2001,1,29,0,+1,0));" and it printed:
    $VAR1 = \2001; $VAR2 = \2; $VAR3 = \28;
    I tried it several different ways and all of them seemed to work now. Maybe the author of Date::Calc saw my post, wrote a fix, hacked my box and replaced by buggy module with a new version!

    Or maybe I didn't test it properly before I posted.

    Well, as far as Date::Calc is concerned (if we are to believe it) we should truncate it down to Feb 28th.

    I don't quite feel at ease about this, but my world view is now secure again - I can say with confidence the exact date in one month's time!
      The business answer is to truncate and stay at the end of the month. I asked an accountant who audits code more than a year ago since the guys I worked with couldn't agree. His point was that If you are in January, adding one month should NEVER get you March. =)

      --
      $you = new YOU;
      honk() if $you->love(perl)

      Ah yes, but can you tell "1 day" later when daylight savings is involved. 8) 23 hours one way, 25 the other.

      Those wacky humans...

      =Blue
      ...you might be eaten by a grue...

        How are we expected to live like this!!! I need to know that blue is blue and green is green. I need to know that there are 86400 seconds in a day and 2,???,??? seconds in a month!!!

        From now on I work onlly in seconds from the epoch - if someone asks me the time, I will say "975,528,976". If they ask me for the date, I will be able to say the same thing. Perfect!