Time::Local (which should be in your Perl distribution) has a conversion mode where its date arguments aren't validated to be in the proper range. A nifty side-effect of this is that you can ask it to convert the 176th of January (or 10_000th second of 2003, or 1234th hour of February, etc), and it will Do What You Mean©.
use Time::Local 'timelocal_nocheck'; my $year = 2003 - 1900; my $dyear = 176; my $epoch = timelocal_nocheck 0,0,0,$dyear,0,$year; ## January is month 0 ^
Time::Local only converts Y/M/D,H:M:S to epoch seconds, but you can very easily extract out the month and day components from the epoch time with localtime:
my ($month, $day) = (localtime $epoch)[4,3]; $month++; ## again, months run from 0 to 11
.. or you could format the date with whatever format you like, using strftime
use POSIX 'strftime'; print strftime("%x", localtime $epoch), $/;
For doing simple date calculations like this, using localtime and Time::Local is a lot less overhead than the behemoth Date::Calc.

UPDATE: If you only care about getting the text output (you don't need the day/month components individually), it looks like strftime also normalizes its input in the same way as timelocal_nocheck:

$ perl -MPOSIX=strftime -le 'print strftime("%c", 0,0,0,176,0,103)' Thu Jun 25 00:00:00 2003
Also realized that I needed to use 2003-1900 (not just 2003) as the final argument to timelocal_nocheck, so updated that.

blokhead


In reply to Re: Need Help with DATE::CALC $doy by blokhead
in thread Need Help with DATE::CALC $doy by Anonymous Monk

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.