xref: /reactos/sdk/lib/crt/include/internal/time.h (revision c2c66aff)
1 #define DIFFTIME 0x19db1ded53e8000ULL
2 #define DIFFDAYS (3 * DAYSPER100YEARS + 17 * DAYSPER4YEARS + 1 * DAYSPERYEAR)
3 
4 #define DAYSPERYEAR 365
5 #define DAYSPER4YEARS (4*DAYSPERYEAR+1)
6 #define DAYSPER100YEARS (25*DAYSPER4YEARS-1)
7 #define DAYSPER400YEARS (4*DAYSPER100YEARS+1)
8 #define SECONDSPERDAY (24*60*60)
9 #define SECONDSPERHOUR (60*60)
10 #define LEAPDAY 59
11 
12 static __inline
13 __time64_t
FileTimeToUnixTime(const FILETIME * FileTime,USHORT * millitm)14 FileTimeToUnixTime(const FILETIME *FileTime, USHORT *millitm)
15 {
16     ULARGE_INTEGER ULargeInt;
17     __time64_t time;
18 
19     ULargeInt.LowPart = FileTime->dwLowDateTime;
20     ULargeInt.HighPart = FileTime->dwHighDateTime;
21     ULargeInt.QuadPart -= DIFFTIME;
22 
23     time = ULargeInt.QuadPart / 10000000;
24     if (millitm)
25         *millitm = (USHORT)((ULargeInt.QuadPart % 10000000) / 10000);
26 
27     return time;
28 }
29 
30 static __inline
leapyears_passed(long days)31 long leapyears_passed(long days)
32 {
33     long quadcenturies, centuries, quadyears;
34     quadcenturies = days / DAYSPER400YEARS;
35     days -= quadcenturies;
36     centuries = days / DAYSPER100YEARS;
37     days += centuries;
38     quadyears = days / DAYSPER4YEARS;
39     return quadyears - centuries + quadcenturies;
40 }
41 
42 static __inline
leapdays_passed(long days)43 long leapdays_passed(long days)
44 {
45     return leapyears_passed(days + DAYSPERYEAR - LEAPDAY + 1);
46 }
47 
48 static __inline
years_passed(long days)49 long years_passed(long days)
50 {
51     return (days - leapdays_passed(days)) / 365;
52 }
53 
54 extern long dst_begin;
55 extern long dst_end;
56