Discussion:
WinApi getFileModifiedtime
(too old to reply)
Timon
2009-05-28 10:13:01 UTC
Permalink
hi all!

i wanted to check if out AX3 labelfiles are up-to-date, so i thought i
compare filedate of the labelfiles to last date/time entry in the syslabellog
table.

i used WinAPI::getFileModifiedTime to check the time the label file was last
modified.

i experienced a time difference of 2h ours between the systemtime and the
value the winapi call return for a fresh written labelfile.

looks like the winapi call ignores daylight savingtime and the local timezone.

i build this little workaround:
http://paste2.org/p/229244

static void getTimeDifferenceFS()
{
AsciiIo file;
str TempFile = WinApi::getTempFilename(WinApi::getTempPath(),"Mei");
;

// Write TempFile for timestamp
file = new AsciiIo(TempFile,"w");
file.write();

print TimeNow() - WinApi::getFileModifiedTime(TempFile); // time
differnce in sec between Localtime and modifiedFileTime value returned by
WinAPI::getFileModifiedTime()
pause;
}

Maybe there is more simple solution, i am missing?

Regards,
Timon
marcin
2010-05-27 23:48:02 UTC
Permalink
hi Timon,

Same problem here, 2 hours difference. They convert NTFS UTC to system time
but something fails "WinAPI::fileTimeToSystemTime(filetime)"

Have you found better solution than saving temporary file?

Regards, Marcin

====================


#winapi
client server static timeOfDay getFileTimeEx(Filename filename, int type)
{
int hFile = WinAPI::createFile(filename, #OPEN_EXISTING);
Binary filetime;
Binary systemTime;

if (hFile)
{
filetime = WinAPI::getFileTime(hFile, type);
WinAPI::closeHandle(hFile);
if (filetime)
{
systemTime = WinAPI::fileTimeToSystemTime(filetime);

if (systemTime)
return WinAPI::SystemTimeToTimeOfDay(systemTime);
}
}
return 0;
}
marcin
2010-09-22 10:49:03 UTC
Permalink
answering my own question...
finally I found the solution
I've added new method to WinApi class

client public static Binary systemTimeToTzSpecificLocalTime(Binary _UTCTime)
{
DLL _winApiDLL = new DLL('KERNEL32');
DLLFunction _systemTimeToTzSpecificLocalTime = new
DLLFunction(_winApiDLL, 'SystemTimeToTzSpecificLocalTime');

Binary systemTime = new Binary(#offset16);

_systemTimeToTzSpecificLocalTime.returns(ExtTypes::DWord);
_systemTimeToTzSpecificLocalTime.arg(ExtTypes::DWord);
_systemTimeToTzSpecificLocalTime.arg(ExtTypes::Pointer);
_systemTimeToTzSpecificLocalTime.arg(ExtTypes::Pointer);

if (_systemTimeToTzSpecificLocalTime.call(0, _UTCTime, systemTime))
{
return systemTime;
}
return null;
}

and modified existing method by adding
systemTime = WinAPI::systemTimeToTzSpecificLocalTime(systemTime);


client server static timeOfDay briGetFileTimeEx(Filename filename, int type)
{
int hFile = WinAPI::createFile(filename, #OPEN_EXISTING);
Binary filetime;
Binary systemTime;

if (hFile)
{
filetime = WinAPI::getFileTime(hFile, type);
WinAPI::closeHandle(hFile);
if (filetime)
{
systemTime = WinAPI::fileTimeToSystemTime(filetime);
systemTime = WinAPI::systemTimeToTzSpecificLocalTime(systemTime);

if (systemTime)
return WinAPI::SystemTimeToTimeOfDay(systemTime);
}
}
return 0;
}

regards, marcin
marcin
2010-09-22 10:53:03 UTC
Permalink
answering my own question...

one can solve the problem by adding a new method to WinAPI class

client public static Binary systemTimeToTzSpecificLocalTime(Binary _UTCTime)
{
DLL _winApiDLL = new DLL('KERNEL32');
DLLFunction _systemTimeToTzSpecificLocalTime = new
DLLFunction(_winApiDLL, 'SystemTimeToTzSpecificLocalTime');

Binary systemTime = new Binary(#offset16);

_systemTimeToTzSpecificLocalTime.returns(ExtTypes::DWord);
_systemTimeToTzSpecificLocalTime.arg(ExtTypes::DWord);
_systemTimeToTzSpecificLocalTime.arg(ExtTypes::Pointer);
_systemTimeToTzSpecificLocalTime.arg(ExtTypes::Pointer);

if (_systemTimeToTzSpecificLocalTime.call(0, _UTCTime, systemTime))
{
return systemTime;
}
return null;
}

and adding one line to existing method getFileTimeEx
systemTime = WinAPI::systemTimeToTzSpecificLocalTime(systemTime);


client server static timeOfDay getFileTimeEx(Filename filename, int type)
{
int hFile = WinAPI::createFile(filename, #OPEN_EXISTING);
Binary filetime;
Binary systemTime;

if (hFile)
{
filetime = WinAPI::getFileTime(hFile, type);
WinAPI::closeHandle(hFile);
if (filetime)
{
systemTime = WinAPI::fileTimeToSystemTime(filetime);
systemTime = WinAPI::systemTimeToTzSpecificLocalTime(systemTime);

if (systemTime)
return WinAPI::SystemTimeToTimeOfDay(systemTime);
}
}
return 0;
}
marcin
2010-09-22 11:10:03 UTC
Permalink
answering my own question...

one can solve the problem by adding a new method to WinAPI class

client public static Binary systemTimeToTzSpecificLocalTime(Binary _UTCTime)
{
DLL _winApiDLL = new DLL('KERNEL32');
DLLFunction _systemTimeToTzSpecificLocalTime = new
DLLFunction(_winApiDLL, 'SystemTimeToTzSpecificLocalTime');

Binary systemTime = new Binary(#offset16);

_systemTimeToTzSpecificLocalTime.returns(ExtTypes::DWord);
_systemTimeToTzSpecificLocalTime.arg(ExtTypes::DWord);
_systemTimeToTzSpecificLocalTime.arg(ExtTypes::Pointer);
_systemTimeToTzSpecificLocalTime.arg(ExtTypes::Pointer);

if (_systemTimeToTzSpecificLocalTime.call(0, _UTCTime, systemTime))
{
return systemTime;
}
return null;
}

and adding one line to existing method getFileTimeEx
systemTime = WinAPI::systemTimeToTzSpecificLocalTime(systemTime);


client server static timeOfDay getFileTimeEx(Filename filename, int type)
{
int hFile = WinAPI::createFile(filename, #OPEN_EXISTING);
Binary filetime;
Binary systemTime;

if (hFile)
{
filetime = WinAPI::getFileTime(hFile, type);
WinAPI::closeHandle(hFile);
if (filetime)
{
systemTime = WinAPI::fileTimeToSystemTime(filetime);
systemTime = WinAPI::systemTimeToTzSpecificLocalTime(systemTime);

if (systemTime)
return WinAPI::SystemTimeToTimeOfDay(systemTime);
}
}
return 0;
}

Loading...