> > with the following output on win2k. > > 9 0 10 0 9 10 > > This is weird, I would have expected to get an output like: 2002 10 27 8 9 10 > with the followingo patch applied... > > nog.
Eeek, sorry about that. I forgot a WINAPI in the typedef, see my new version in the attachment... The following output is more in line with your expectations: 2002 10 27 8 9 10 I have also attached the output of timetest2.c after some adjustments to make it compile on my box which is missing winternl.h. (I didn't take the time to download the SDK.) However, I don't follow the part about appling patches. I have compiled the code using msvc and executed the code on windows 2000. /peda
#include <stdio.h> #include <windows.h> typedef short CSHORT; typedef struct { CSHORT Year; CSHORT Month; CSHORT Day; CSHORT Hour; CSHORT Minute; CSHORT Second; CSHORT Milliseconds; CSHORT Weekday; } TIME_FIELDS, *PTIME_FIELDS; typedef VOID (WINAPI *RtlTimeToTimeFieldsT) (PLARGE_INTEGER Time, PTIME_FIELDS TimeFields); int main() { LARGE_INTEGER RtlTime; TIME_FIELDS tf; HINSTANCE hLib; RtlTimeToTimeFieldsT RtlTimeToTimeFields; RtlTime.LowPart = 0x20de5700; RtlTime.HighPart = 0x1c27d90; hLib = LoadLibrary("ntdll"); RtlTimeToTimeFields = (RtlTimeToTimeFieldsT) GetProcAddress(hLib, "RtlTimeToTimeFields"); RtlTimeToTimeFields(&RtlTime, &tf); FreeLibrary(hLib); printf("%d %d %d %d %d %d\n", tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second); return 0; }
#include <stdio.h> #include <windows.h> typedef short CSHORT; typedef struct { CSHORT Year; CSHORT Month; CSHORT Day; CSHORT Hour; CSHORT Minute; CSHORT Second; CSHORT Milliseconds; CSHORT Weekday; } TIME_FIELDS, *PTIME_FIELDS; typedef VOID (WINAPI *RtlTimeToTimeFieldsT)(PLARGE_INTEGER Time, PTIME_FIELDS TimeFields); #define testtime(HighTime, LowTime) \ RtlTime.HighPart = HighTime; \ RtlTime.LowPart = LowTime; \ RtlTimeToTimeFields(&RtlTime, &tf); \ printf("%04d %02d %02d %02d %02d %02d\n", tf.Year, tf.Month, tf.Day,\ tf.Hour, tf.Minute, tf.Second); /* The year to which to test */ #define TargetYear 2222 /* Taken from dlls/ntdll/time.c */ #define EPOCHYEAR 1601 #define TICKSPERSEC 10000000 #define SECSPERDAY 86400 #define MONSPERYEAR 12 static const int MonthLengths[2][MONSPERYEAR] = { { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } }; int IsLeapYear(int Year) { return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0; } int main() { int Month, Year; UINT64 time = 0, tmp; LARGE_INTEGER RtlTime; TIME_FIELDS tf; HINSTANCE hLib; RtlTimeToTimeFieldsT RtlTimeToTimeFields; hLib = LoadLibrary("ntdll"); RtlTimeToTimeFields = (RtlTimeToTimeFieldsT)GetProcAddress (hLib, "RtlTimeToTimeFields"); for(Year = 0; Year <= (TargetYear - EPOCHYEAR); Year++) { for(Month = 0; Month < MONSPERYEAR; Month++) { tmp = MonthLengths[IsLeapYear(Year + EPOCHYEAR)][Month] * SECSPERDAY; tmp *= TICKSPERSEC; time += tmp; testtime(time >> 32, (time & 0xffffffff)); } } FreeLibrary(hLib); return 0; }
timetest2.zip
Description: Zip archive