in reply to Re: Last day of the month. Any shorter
in thread Last day of the month. Any shorter

"I think you're taking a risk by trying to implement your own leap-year calculation."

Why? It's a simple and well documented algorithm, you can write it in a line of Perl. What's the risk?

Personally I keep hoping that a rudimentary date time module (maybe DateTime.pm or a subset) will be included with Perl core, then using the "comes with" will be easier than cutting and pasting the line of perl around :)

--
Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho

  • Comment on Re: Re: Last day of the month. Any shorter

Replies are listed 'Best First'.
Re: Re: Re: Last day of the month. Any shorter
by jdporter (Paladin) on May 20, 2004 at 04:13 UTC
    Still not sure why you'd want to. Just doing the leap-year check by hand is longer than some of the entire solutions presented.

    And also:

    use Time::Local; sub is_leapyear { 1 == (gmtime(timegm(0,0,1,28,1,$_[0])+24*60*60))[4] }
    (But this has severe limitations on the range of valid dates input.)

      I thought you were indicating there was a specific risk in implementing the usual algorithm and I wanted to know what it was.

      The gmtime-timegm method you give is a neat trick but I can't see any good reason to prefer it. It really needs code to catch years outside the epoch range, or at a minimum a comment to highlight it's limitation.

      --
      Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho