Reputation: 670
I'm in the process of creating a problematic data set and I'm looking to set the year of the modification times of files to <1900. I know that Time::Local uses an offset from 1900. I was wondering if there was any way around using this offset to create files whose modification times occur before the year 1900. (Windows Enviroment btw.)
This is the code I've been using so far:
use strict;
use warnings;
use File::stat;
use Time::localtime;
use Time::Local;
my $file = "test.txt";
my $when = timelocal(0,0,10,25,6,1899);
#current mod time of the file
my $datetime_string = ctime(stat($file)->mtime);
print $datetime_string,"\n";
#change the mod time of the file
utime $when, $when, $file;
#new mod time
$datetime_string = ctime(stat($file)->mtime);
print $datetime_string,"\n";
Edit: In regards to @ikegami 's comment, I did start to look into Win32::API
. Specifically Win32API::File::Time
. This is the code that I have so far for that:
use Win32API::File::Time qw{:win};
$filename="AnnotationTest.java";
($atime, $mtime, $ctime) = GetFileTime ($filename);
print $mtime,"\n";
SetFileTime ($filename, $atime, $mtime, $ctime);
($atime, $mtime, $ctime) = GetFileTime ($filename);
print $mtime,"\n";
With this code I'm not 100% sure what the format of the modification time is.
Upvotes: 0
Views: 595
Reputation: 22952
I'm not sure that utime supports going that far back. If it's a signed 32-bit offset from 1970 then that only gets you to 1901 afaict. Is there a cut-off around -(2**31)?
Upvotes: 1