Here's the problem, and you get credit for discovering what I believe to be a bug in Date::Manip (or its documentation).

The documentation for Date::Manip correctly states that ParseDateString() will not correctly handle a raw number of seconds since epoch. Obviously, seconds since epoch is exactly what $s->mtime() is giving you. So you need a way of getting Date::Manip's ParseDateString() to recognize that what you're handing it is seconds since epoch.

The POD for Date::Manip goes on to tell you how to do that:

NOTE: One of the most frequently asked questions that I have gotten is how to parse seconds since the epoch. ParseDateString cannot simply parse a number as the seconds since the epoch (it conflicts with some ISO-8601 date formats). There are two ways to get this information. First, you can do the following:

$secs = ... # seconds since Jan 1, 1970 00:00:00 GMT $date = &DateCalc("Jan 1, 1970 00:00:00 GMT",$secs);

Second, you can call it directly as:

$date = &ParseDateString("epoch $secs");

You're attempting to use the second method, and at least for me on Win32 ActivePerl 5.8.6 with Date::Manip version 5.42, that second method simply doesn't work as advertised. It fails to convince Date::Manip that you've handed it a string of seconds since epoch, and the result is that ParseDateString doesn't know what it's looking at, and defaults to returning an empty string.

I have gone on to confirm that at least the first method suggested in the documentation for Date::Manip does work. That is,

printf "%s: Age [%s], size[%d]\n", $farm, DateCalc( "Jan 1, 1970 00:00:00 GMT",$s->mtime() ), $s->size();

Try that on for size. ;)

Update: Bug alert has been rescinded. See my followup below.


Dave


In reply to Re^3: Human Readable Date by davido
in thread Human Readable Date by FireyIce01

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.