I am trying to write a program that stages files to later archive based off of either dates embedded in the filenames or if those don't exist then from the date of the mtime on the filesystem for each file.

Ok, so, that being said, I need the date to be as accurate as possible. However, after some tests I am finding that the mtime returned from stat() and then being converted to human readable format via Perl's built-in gmtime() that for some reason the month returned is one month off.

I find it more difficult to believe that there is something wrong with Perl versus something wrong with what I am doing. Please check my work and see if I am off somewhere.

First, I touch a file so I get the desired mtime that I am looking for. I check the mtime using a utility I wrote called macls. Here is the output...

MACtime for: "test_file_1_200008261030" Mode(-rw-r--r-- => 0644) gvc(2000) gvcadm(104) 0 bytes 0 blocks Modified time ........ Sat Aug 26 09:30:00 2000 Access time ........ Sat Aug 26 09:30:00 2000 Inode Change ........ Tue Jun 18 12:14:19 2002 ******************************************************* MACtime for: "test_file_2_199504231930" Mode(-rw-r--r-- => 0644) gvc(2000) gvcadm(104) 0 bytes 0 blocks Modified time ........ Sun Apr 23 18:30:00 1995 Access time ........ Sun Apr 23 18:30:00 1995 Inode Change ........ Tue Jun 18 12:14:39 2002 ******************************************************* MACtime for: "test_file_3_200506200200" Mode(-rw-r--r-- => 0644) gvc(2000) gvcadm(104) 0 bytes 0 blocks Modified time ........ Mon Jun 20 01:00:00 2005 Access time ........ Mon Jun 20 01:00:00 2005 Inode Change ........ Tue Jun 18 12:15:00 2002 Total files checked : 4 Total size in bytes : 0 Total size in Kbytes: 0K
Note the strange and abnormal dates how they jump around and stuff =P jk. Anyway, so we know the dates are on the file system the way I want them. Oh, also note that the time stamp I used for the touch command is in the filename so I can reference it should the mtime get whacked in the moving of the files from place to place on the fs. One thing I just noticed is the actual time I specified for the touch command is off by one hour on the file system. Very interesting.

Ok. Now, I now do the following:

perl -e 'open(F,"test_file_1_200008261030");$date = (stat(F))[9];@date + = (eval((gmtime($date))[3,4,5]));print "@date\n"' 26 7 100
For everyone who doesn't know, the first number is the day, the second number is the month and the third number is the year - 1900. Everything is fine except the month value. Its off by a month.

What am I overlooking?

_ _ _ _ _ _ _ _ _ _
- Jim
Insert clever comment here...


In reply to built-in gmtime() returning one month off? by snafu

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.