I spot (($year)%4). That's incomplete. Every year divisible by 4 is a leap except those divisible by 100. But those divisible by 400 are also leap years.

2095 n 2096 y 2097 n 2098 n 2099 n 2100 n <-- %100==0 2101 n 2102 n 2103 n 2104 y 2105 n 1995 n 1996 y 1997 n 1998 n 1999 n 2000 y <-- %400==0 2001 n

But since you're restricting yourself to the years 1970 to 2038, you're ok.

You've basically reimplemented (core module) Time::Local's timegm_nocheck, so you might want to verify against it.


In reply to Re: high speed/efficiency http date to unix time, leap years handling? by ikegami
in thread high speed/efficiency http date to unix time, leap years handling? by bulk88

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.