| |
| Posted by Regan Heath in reply to simon.hodson | PermalinkReply |
|
Regan Heath
Posted in reply to simon.hodson
| On Tue, 13 Jun 2006 15:57:39 +0000 (UTC), <simon.hodson@hssnet.com> wrote:
> Anyone know an easy way of getting the last write time of a file into a UTC time
> regardless of the source filesystem?
>
> I need to equate update times on source files and have found that these times
> can be different under Windows when the source files are stored on different
> filesystems. NTFS uses UTC with no TimeZone) and FAT uses UTC with a TimeZone.
> The resolution also appears to be different too, but I'll worry about that
> later.
>
> Looks as though I need to find out the filesystem the source file is on then
> make the correct translation to UTC.
>
> Anyone got any ideas?
In C, you would use the "stat" function, combined with "gmtime". You can use both in D too:
import std.stream;
import std.stdio;
import std.c.time;
extern (C) {
struct _stat {
int st_dev;
ushort st_ino;
ushort st_mode;
short st_nlink;
short st_uid;
short st_gid;
// uint st_rdev;
int st_size;
int st_atime;
int st_mtime;
int st_ctime;
}
int stat(char *path, _stat *buffer);
}
void main()
{
_stat buf;
tm *tm;
File f;
f = new File("test36.txt",FileMode.Out);
f.writeLine("Line 1");
f.writeLine("Line 2");
f.close();
if (stat("test36.txt",&buf) == -1) writefln("FAIL");
else {
writefln("st_dev: ",buf.st_dev);
writefln("st_ino: ",buf.st_ino);
writefln("st_mode: ",buf.st_mode);
writefln("st_nlink: ",buf.st_nlink);
writefln("st_uid: ",buf.st_uid);
writefln("st_gid: ",buf.st_gid);
writefln("st_size: ",buf.st_size);
writefln("st_atime: ",buf.st_atime);
writefln("st_mtime: ",buf.st_mtime);
writefln("st_ctime: ",buf.st_ctime);
}
writefln("");
tm = localtime(&buf.st_atime);
if (tm) writefln("Access Time(LCL): ",asctime(tm)[0..24]);
tm = gmtime(&buf.st_atime);
if (tm) writefln("Access Time(GMT): ",asctime(tm)[0..24]);
tm = localtime(&buf.st_mtime);
if (tm) writefln("Modification Time(LCL): ",asctime(tm)[0..24]);
tm = gmtime(&buf.st_mtime);
if (tm) writefln("Modification Time(GMT): ",asctime(tm)[0..24]);
tm = localtime(&buf.st_ctime);
if (tm) writefln("Creation Time(LCL): ",asctime(tm)[0..24]);
tm = gmtime(&buf.st_ctime);
if (tm) writefln("Creation Time(GMT): ",asctime(tm)[0..24]);
}
Regan
|