4 * RtlTimeToTimeFields, RtlTimeFieldsToTime and defines are taken from ReactOS and
5 * adapted to wine with special permissions of the author
6 * Rex Jolliff (rex@lvcablemodem.com)
8 * Copyright 1999 Juergen Schmied
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/port.h"
31 #ifdef HAVE_SYS_TIME_H
32 # include <sys/time.h>
38 #define NONAMELESSUNION
39 #define NONAMELESSSTRUCT
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
46 #define SETTIME_MAX_ADJUST 120
48 /* This structure is used to store strings that represent all of the time zones
49 * in the world. (This is used to help GetTimeZoneInformation)
53 const char *psTZFromUnix;
54 WCHAR psTZWindows[32];
59 static const struct tagTZ_INFO TZ_INFO[] =
62 {'D','a','t','e','l','i','n','e',' ','S','t','a','n','d','a','r','d',' ',
63 'T','i','m','e','\0'}, -720, 0},
65 {'S','a','m','o','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
68 {'H','a','w','a','i','i','a','n',' ','S','t','a','n','d','a','r','d',' ',
69 'T','i','m','e','\0'}, 600, 0},
71 {'A','l','a','s','k','a','n',' ','S','t','a','n','d','a','r','d',' ','T',
72 'i','m','e','\0'}, 480, 1},
74 {'P','a','c','i','f','i','c',' ','S','t','a','n','d','a','r','d',' ','T',
75 'i','m','e','\0'}, 420, 1},
77 {'U','S',' ','M','o','u','n','t','a','i','n',' ','S','t','a','n','d','a',
78 'r','d',' ','T','i','m','e','\0'}, 420, 0},
80 {'M','o','u','n','t','a','i','n',' ','S','t','a','n','d','a','r','d',' ',
81 'T','i','m','e','\0'}, 360, 1},
83 {'C','e','n','t','r','a','l',' ','A','m','e','r','i','c','a',' ','S','t',
84 'a','n','d','a','r','d',' ','T','i','m','e','\0'}, 360, 0},
86 {'C','e','n','t','r','a','l',' ','S','t','a','n','d','a','r','d',' ','T',
87 'i','m','e','\0'}, 300, 1},
89 {'S','A',' ','P','a','c','i','f','i','c',' ','S','t','a','n','d','a','r',
90 'd',' ','T','i','m','e','\0'}, 300, 0},
92 {'E','a','s','t','e','r','n',' ','S','t','a','n','d','a','r','d',' ','T',
93 'i','m','e','\0'}, 240, 1},
95 {'U','S',' ','E','a','s','t','e','r','n',' ','S','t','a','n','d','a','r',
96 'd',' ','T','i','m','e','\0'}, 300, 0},
98 {'A','t','l','a','n','t','i','c',' ','S','t','a','n','d','a','r','d',' ',
99 'T','i','m','e','\0'}, 180, 1},
101 {'S','A',' ','W','e','s','t','e','r','n',' ','S','t','a','n','d','a','r',
102 'd',' ','T','i','m','e','\0'}, 240, 0},
104 {'P','a','c','i','f','i','c',' ','S','A',' ','S','t','a','n','d','a','r',
105 'd',' ','T','i','m','e','\0'}, 240, 0},
107 {'N','e','w','f','o','u','n','d','l','a','n','d',' ','S','t','a','n','d',
108 'a','r','d',' ','T','i','m','e','\0'}, 150, 1},
110 {'E','.',' ','S','o','u','t','h',' ','A','m','e','r','i','c','a',' ','S',
111 't','a','n','d','a','r','d',' ','T','i','m','e','\0'}, 180, 0},
113 {'S','A',' ','E','a','s','t','e','r','n',' ','S','t','a','n','d','a','r',
114 'd',' ','T','i','m','e','\0'}, 180, 0},
116 {'G','r','e','e','n','l','a','n','d',' ','S','t','a','n','d','a','r','d',
117 ' ','T','i','m','e','\0'}, 120, 1},
119 {'M','i','d','-','A','t','l','a','n','t','i','c',' ','S','t','a','n','d',
120 'a','r','d',' ','T','i','m','e','\0'}, 120, 0},
122 {'A','z','o','r','e','s',' ','S','t','a','n','d','a','r','d',' ','T','i',
123 'm','e','\0'}, 0, 1},
125 {'C','a','p','e',' ','V','e','r','d','e',' ','S','t','a','n','d','a','r',
126 'd',' ','T','i','m','e','\0'}, 60, 0},
128 {'G','r','e','e','n','w','i','c','h',' ','S','t','a','n','d','a','r','d',
129 ' ','T','i','m','e','\0'}, 0, 0},
131 {'G','M','T',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'},
134 {'G','M','T',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'},
137 {'C','e','n','t','r','a','l',' ','E','u','r','o','p','e',' ','S','t','a',
138 'n','d','a','r','d',' ','T','i','m','e','\0'}, -120, 1},
140 {'W','.',' ','C','e','n','t','r','a','l',' ','A','f','r','i','c','a',' ',
141 'S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, -60, 0},
143 {'E','.',' ','E','u','r','o','p','e',' ','S','t','a','n','d','a','r','d',
144 ' ','T','i','m','e','\0'}, -180, 1},
146 {'E','g','y','p','t',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
149 {'S','o','u','t','h',' ','A','f','r','i','c','a',' ','S','t','a','n','d',
150 'a','r','d',' ','T','i','m','e','\0'}, -120, 0},
152 {'I','s','r','a','e','l',' ','S','t','a','n','d','a','r','d',' ','T','i',
153 'm','e','\0'}, -120, 0},
155 {'A','r','a','b','i','c',' ','S','t','a','n','d','a','r','d',' ','T','i',
156 'm','e','\0'}, -240, 1},
158 {'A','r','a','b',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e',
161 {'R','u','s','s','i','a','n',' ','S','t','a','n','d','a','r','d',' ','T',
162 'i','m','e','\0'}, -240, 1},
164 {'E','.',' ','A','f','r','i','c','a',' ','S','t','a','n','d','a','r','d',
165 ' ','T','i','m','e','\0'}, -180, 0},
167 {'I','r','a','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e',
170 {'A','r','a','b','i','a','n',' ','S','t','a','n','d','a','r','d',' ','T',
171 'i','m','e','\0'}, -240, 0},
173 {'C','a','u','c','a','s','u','s',' ','S','t','a','n','d','a','r','d',' ',
174 'T','i','m','e','\0'}, -300, 1},
176 {'A','f','g','h','a','n','i','s','t','a','n',' ','S','t','a','n','d','a',
177 'r','d',' ','T','i','m','e','\0'}, -270, 0},
179 {'E','k','a','t','e','r','i','n','b','u','r','g',' ','S','t','a','n','d',
180 'a','r','d',' ','T','i','m','e','\0'}, -360, 1},
182 {'W','e','s','t',' ','A','s','i','a',' ','S','t','a','n','d','a','r','d',
183 ' ','T','i','m','e','\0'}, -300, 0},
185 {'I','n','d','i','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
188 {'N','e','p','a','l',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
191 {'N','.',' ','C','e','n','t','r','a','l',' ','A','s','i','a',' ','S','t',
192 'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -420, 1},
194 {'C','e','n','t','r','a','l',' ','A','s','i','a',' ','S','t','a','n','d',
195 'a','r','d',' ','T','i','m','e','\0'}, -360, 0},
197 {'S','r','i',' ','L','a','n','k','a',' ','S','t','a','n','d','a','r','d',
198 ' ','T','i','m','e','\0'}, -360, 0},
200 {'M','y','a','n','m','a','r',' ','S','t','a','n','d','a','r','d',' ','T',
201 'i','m','e','\0'}, -390, 0},
203 {'S','E',' ','A','s','i','a',' ','S','t','a','n','d','a','r','d',' ','T',
204 'i','m','e','\0'}, -420, 0},
206 {'N','o','r','t','h',' ','A','s','i','a',' ','S','t','a','n','d','a','r',
207 'd',' ','T','i','m','e','\0'}, -480, 1},
209 {'C','h','i','n','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
212 {'N','o','r','t','h',' ','A','s','i','a',' ','E','a','s','t',' ','S','t',
213 'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -540, 1},
215 {'M','a','l','a','y',' ','P','e','n','i','n','s','u','l','a',' ','S','t',
216 'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -480, 0},
218 {'W','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a','n','d',
219 'a','r','d',' ','T','i','m','e','\0'}, -480, 0},
221 {'T','o','k','y','o',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
224 {'K','o','r','e','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
227 {'Y','a','k','u','t','s','k',' ','S','t','a','n','d','a','r','d',' ','T',
228 'i','m','e','\0'}, -600, 1},
230 {'C','e','n','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a',
231 'n','d','a','r','d',' ','T','i','m','e','\0'}, -570, 0},
233 {'E','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a','n','d',
234 'a','r','d',' ','T','i','m','e','\0'}, -600, 0},
236 {'W','e','s','t',' ','P','a','c','i','f','i','c',' ','S','t','a','n','d',
237 'a','r','d',' ','T','i','m','e','\0'}, -600, 0},
239 {'V','l','a','d','i','v','o','s','t','o','k',' ','S','t','a','n','d','a',
240 'r','d',' ','T','i','m','e','\0'}, -660, 1},
242 {'C','e','n','t','r','a','l',' ','P','a','c','i','f','i','c',' ','S','t',
243 'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -720, 1},
245 {'N','e','w',' ','Z','e','a','l','a','n','d',' ','S','t','a','n','d','a',
246 'r','d',' ','T','i','m','e','\0'}, -720, 0},
248 {'F','i','j','i',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e',
251 {'T','o','n','g','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
255 /*********** start of code by Rex Jolliff (rex@lvcablemodem.com) **************/
257 #define TICKSPERSEC 10000000
258 #define TICKSPERMSEC 10000
259 #define SECSPERDAY 86400
260 #define SECSPERHOUR 3600
261 #define SECSPERMIN 60
262 #define MINSPERHOUR 60
263 #define HOURSPERDAY 24
264 #define EPOCHWEEKDAY 1 /* Jan 1, 1601 was Monday */
265 #define DAYSPERWEEK 7
266 #define EPOCHYEAR 1601
267 #define DAYSPERNORMALYEAR 365
268 #define DAYSPERLEAPYEAR 366
269 #define MONSPERYEAR 12
271 /* 1601 to 1970 is 369 years plus 89 leap days */
272 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)86400)
273 /* 1601 to 1980 is 379 years plus 91 leap days */
274 #define SECS_1601_to_1980 ((379 * 365 + 91) * (ULONGLONG)86400)
277 static const int YearLengths[2] = {DAYSPERNORMALYEAR, DAYSPERLEAPYEAR};
278 static const int MonthLengths[2][MONSPERYEAR] =
280 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
281 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
284 static inline int IsLeapYear(int Year)
286 return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
289 static inline void NormalizeTimeFields(CSHORT *FieldToNormalize, CSHORT *CarryField,int Modulus)
291 *FieldToNormalize = (CSHORT) (*FieldToNormalize - Modulus);
292 *CarryField = (CSHORT) (*CarryField + 1);
295 /******************************************************************************
296 * RtlTimeToTimeFields [NTDLL.@]
298 * Parses Time into a TimeFields structure.
301 * liTime [I]: Time to convert to timefields.
302 * TimeFields [O]: Pointer to TIME_FIELDS structure to hold parsed info.
307 VOID WINAPI RtlTimeToTimeFields(
308 const LARGE_INTEGER *liTime,
309 PTIME_FIELDS TimeFields)
312 int SecondsInDay, CurYear;
313 int LeapYear, CurMonth;
315 LONGLONG Time = liTime->QuadPart;
317 /* Extract millisecond from time and convert time into seconds */
318 TimeFields->Milliseconds = (CSHORT) ((Time % TICKSPERSEC) / TICKSPERMSEC);
319 Time = Time / TICKSPERSEC;
321 /* The native version of RtlTimeToTimeFields does not take leap seconds
324 /* Split the time into days and seconds within the day */
325 Days = Time / SECSPERDAY;
326 SecondsInDay = Time % SECSPERDAY;
328 /* compute time of day */
329 TimeFields->Hour = (CSHORT) (SecondsInDay / SECSPERHOUR);
330 SecondsInDay = SecondsInDay % SECSPERHOUR;
331 TimeFields->Minute = (CSHORT) (SecondsInDay / SECSPERMIN);
332 TimeFields->Second = (CSHORT) (SecondsInDay % SECSPERMIN);
334 /* compute day of week */
335 TimeFields->Weekday = (CSHORT) ((EPOCHWEEKDAY + Days) % DAYSPERWEEK);
339 /* FIXME: handle calendar modifications */
341 { LeapYear = IsLeapYear(CurYear);
342 if (Days < (long) YearLengths[LeapYear])
346 Days = Days - (long) YearLengths[LeapYear];
348 TimeFields->Year = (CSHORT) CurYear;
350 /* Compute month of year */
351 Months = MonthLengths[LeapYear];
352 for (CurMonth = 0; Days >= (long) Months[CurMonth]; CurMonth++)
353 Days = Days - (long) Months[CurMonth];
354 TimeFields->Month = (CSHORT) (CurMonth + 1);
355 TimeFields->Day = (CSHORT) (Days + 1);
358 /******************************************************************************
359 * RtlTimeFieldsToTime [NTDLL.@]
361 * Converts a TIME_FIELDS structure to time.
364 * ftTimeFields [I]: Time fields structure to convert.
365 * Time [O]: Converted time.
371 BOOLEAN WINAPI RtlTimeFieldsToTime(
372 PTIME_FIELDS tfTimeFields,
375 int CurYear, CurMonth;
377 TIME_FIELDS TimeFields = *tfTimeFields;
381 /* FIXME: normalize the TIME_FIELDS structure here */
382 while (TimeFields.Second >= SECSPERMIN)
383 { NormalizeTimeFields(&TimeFields.Second, &TimeFields.Minute, SECSPERMIN);
385 while (TimeFields.Minute >= MINSPERHOUR)
386 { NormalizeTimeFields(&TimeFields.Minute, &TimeFields.Hour, MINSPERHOUR);
388 while (TimeFields.Hour >= HOURSPERDAY)
389 { NormalizeTimeFields(&TimeFields.Hour, &TimeFields.Day, HOURSPERDAY);
391 while (TimeFields.Day > MonthLengths[IsLeapYear(TimeFields.Year)][TimeFields.Month - 1])
392 { NormalizeTimeFields(&TimeFields.Day, &TimeFields.Month, SECSPERMIN);
394 while (TimeFields.Month > MONSPERYEAR)
395 { NormalizeTimeFields(&TimeFields.Month, &TimeFields.Year, MONSPERYEAR);
398 /* FIXME: handle calendar corrections here */
399 for (CurYear = EPOCHYEAR; CurYear < TimeFields.Year; CurYear++)
400 { rcTime += YearLengths[IsLeapYear(CurYear)];
402 for (CurMonth = 1; CurMonth < TimeFields.Month; CurMonth++)
403 { rcTime += MonthLengths[IsLeapYear(CurYear)][CurMonth - 1];
405 rcTime += TimeFields.Day - 1;
406 rcTime *= SECSPERDAY;
407 rcTime += TimeFields.Hour * SECSPERHOUR + TimeFields.Minute * SECSPERMIN + TimeFields.Second;
408 rcTime *= TICKSPERSEC;
409 rcTime += TimeFields.Milliseconds * TICKSPERMSEC;
410 Time->QuadPart = rcTime;
414 /************ end of code by Rex Jolliff (rex@lvcablemodem.com) ***************/
416 /******************************************************************************
417 * RtlLocalTimeToSystemTime [NTDLL.@]
419 * Converts local time to system time.
422 * LocalTime [I]: Localtime to convert.
423 * SystemTime [O]: SystemTime of the supplied localtime.
428 NTSTATUS WINAPI RtlLocalTimeToSystemTime( const LARGE_INTEGER *LocalTime,
429 PLARGE_INTEGER SystemTime)
431 TIME_ZONE_INFORMATION tzinfo;
433 TRACE("(%p, %p)\n", LocalTime, SystemTime);
435 RtlQueryTimeZoneInformation(&tzinfo);
436 SystemTime->QuadPart = LocalTime->QuadPart + tzinfo.Bias * 60 * (LONGLONG)10000000;
437 return STATUS_SUCCESS;
440 /******************************************************************************
441 * RtlSystemTimeToLocalTime [NTDLL.@]
443 * Converts system Time to local time.
446 * SystemTime [I]: System time to convert.
447 * LocalTime [O]: Local time of the supplied system time.
452 NTSTATUS WINAPI RtlSystemTimeToLocalTime( const LARGE_INTEGER *SystemTime,
453 PLARGE_INTEGER LocalTime )
455 TIME_ZONE_INFORMATION tzinfo;
457 TRACE("(%p, %p)\n", SystemTime, LocalTime);
459 RtlQueryTimeZoneInformation(&tzinfo);
460 LocalTime->QuadPart = SystemTime->QuadPart - tzinfo.Bias * 60 * (LONGLONG)10000000;
461 return STATUS_SUCCESS;
464 /******************************************************************************
465 * RtlTimeToSecondsSince1970 [NTDLL.@]
467 * Converts Time to seconds since 1970.
470 * time [I]: Time to convert.
471 * res [O]: Pointer to a LONG to recieve the seconds since 1970.
477 BOOLEAN WINAPI RtlTimeToSecondsSince1970( const LARGE_INTEGER *time, PULONG res )
479 ULONGLONG tmp = ((ULONGLONG)time->s.HighPart << 32) | time->s.LowPart;
480 tmp = RtlLargeIntegerDivide( tmp, 10000000, NULL );
481 tmp -= SECS_1601_TO_1970;
482 if (tmp > 0xffffffff) return FALSE;
487 /******************************************************************************
488 * RtlTimeToSecondsSince1980 [NTDLL.@]
490 * Converts Time to seconds since 1980.
493 * time [I]: Time to convert.
494 * res [O]: Pointer to a integer to recieve the time since 1980.
500 BOOLEAN WINAPI RtlTimeToSecondsSince1980( const LARGE_INTEGER *time, LPDWORD res )
502 ULONGLONG tmp = ((ULONGLONG)time->s.HighPart << 32) | time->s.LowPart;
503 tmp = RtlLargeIntegerDivide( tmp, 10000000, NULL );
504 tmp -= SECS_1601_to_1980;
505 if (tmp > 0xffffffff) return FALSE;
510 /******************************************************************************
511 * RtlSecondsSince1970ToTime [NTDLL.@]
513 * Converts seconds since 1970 to time.
516 * time [I]: Seconds since 1970 to convert.
517 * res [O]: Seconds since 1970 in Time.
522 void WINAPI RtlSecondsSince1970ToTime( DWORD time, LARGE_INTEGER *res )
524 ULONGLONG secs = RtlExtendedIntegerMultiply( time + SECS_1601_TO_1970, 10000000 );
525 res->s.LowPart = (DWORD)secs;
526 res->s.HighPart = (DWORD)(secs >> 32);
529 /******************************************************************************
530 * RtlSecondsSince1980ToTime [NTDLL.@]
532 * Converts seconds since 1980 to time.
535 * time [I]: Seconds since 1980 to convert.
536 * res [O]: Seconds since 1980 in Time.
541 void WINAPI RtlSecondsSince1980ToTime( DWORD time, LARGE_INTEGER *res )
543 ULONGLONG secs = RtlExtendedIntegerMultiply( time + SECS_1601_to_1980, 10000000 );
544 res->s.LowPart = (DWORD)secs;
545 res->s.HighPart = (DWORD)(secs >> 32);
548 /******************************************************************************
549 * RtlTimeToElapsedTimeFields [NTDLL.@]
554 void WINAPI RtlTimeToElapsedTimeFields( const LARGE_INTEGER *Time, PTIME_FIELDS TimeFields )
559 time = RtlExtendedLargeIntegerDivide( Time->QuadPart, TICKSPERSEC, &rem );
560 TimeFields->Milliseconds = rem / TICKSPERMSEC;
562 /* time is now in seconds */
563 TimeFields->Year = 0;
564 TimeFields->Month = 0;
565 TimeFields->Day = RtlExtendedLargeIntegerDivide( time, SECSPERDAY, &rem );
567 /* rem is now the remaining seconds in the last day */
568 TimeFields->Second = rem % 60;
570 TimeFields->Minute = rem % 60;
571 TimeFields->Hour = rem / 60;
574 /***********************************************************************
575 * NtQuerySystemTime [NTDLL.@]
576 * ZwQuerySystemTime [NTDLL.@]
578 * Gets the current system time.
581 * time [O]: The current system time.
586 NTSTATUS WINAPI NtQuerySystemTime( PLARGE_INTEGER time )
590 gettimeofday( &now, 0 );
591 time->QuadPart = RtlExtendedIntegerMultiply( now.tv_sec+SECS_1601_TO_1970, 10000000 ) + now.tv_usec * 10;
592 return STATUS_SUCCESS;
595 /***********************************************************************
596 * TIME_GetBias [internal]
598 * Helper function calculates delta local time from UTC.
601 * utc [I]: The current utc time.
602 * pdaylight [I]: Local daylight.
605 * The bias for the current timezone.
607 static int TIME_GetBias(time_t utc, int *pdaylight)
609 struct tm *ptm = localtime(&utc);
610 *pdaylight = ptm->tm_isdst; /* daylight for local timezone */
612 ptm->tm_isdst = *pdaylight; /* use local daylight, not that of Greenwich */
613 return (int)(utc-mktime(ptm));
616 /***********************************************************************
617 * TIME_GetTZAsStr [internal]
619 * Helper function that returns the given timezone as a string.
622 * utc [I]: The current utc time.
623 * bias [I]: The bias of the current timezone.
630 * This could be done with a hash table instead of merely iterating through a
631 * table, however with the small amount of entries (60 or so) I didn't think
634 static const WCHAR* TIME_GetTZAsStr (time_t utc, int bias, int dst)
637 struct tm *ptm = localtime(&utc);
640 if (!strftime (psTZName, 7, "%Z", ptm))
643 for (i=0; i<(sizeof(TZ_INFO) / sizeof(struct tagTZ_INFO)); i++)
645 if ( strcmp(TZ_INFO[i].psTZFromUnix, psTZName) == 0 &&
646 TZ_INFO[i].bias == bias &&
647 TZ_INFO[i].dst == dst
649 return TZ_INFO[i].psTZWindows;
655 /***********************************************************************
656 * RtlQueryTimeZoneInformation [NTDLL.@]
658 * Returns the timezone.
661 * tzinfo [O]: Retrieves the timezone info.
666 NTSTATUS WINAPI RtlQueryTimeZoneInformation(LPTIME_ZONE_INFORMATION tzinfo)
672 memset(tzinfo, 0, sizeof(TIME_ZONE_INFORMATION));
675 bias = TIME_GetBias(gmt, &daylight);
677 tzinfo->Bias = -bias / 60;
678 tzinfo->StandardBias = 0;
679 tzinfo->DaylightBias = -60;
680 psTZ = TIME_GetTZAsStr (gmt, (-bias/60), daylight);
681 if (psTZ) strcpyW( tzinfo->StandardName, psTZ );
682 return STATUS_SUCCESS;
685 /***********************************************************************
686 * RtlSetTimeZoneInformation [NTDLL.@]
688 * Sets the current time zone.
691 * tzinfo [I]: Timezone information used to set timezone.
697 * Uses the obsolete unix timezone structure and tz_dsttime member.
699 NTSTATUS WINAPI RtlSetTimeZoneInformation( const TIME_ZONE_INFORMATION *tzinfo )
703 tz.tz_minuteswest = tzinfo->Bias;
705 tz.tz_dsttime = DST_NONE;
709 if(!settimeofday(NULL, &tz))
710 return STATUS_SUCCESS;
711 return STATUS_PRIVILEGE_NOT_HELD;
714 /***********************************************************************
715 * NtSetSystemTime [NTDLL.@]
716 * ZwSetSystemTime [NTDLL.@]
718 * Sets the system time.
721 * NewTime [I]: The time to set the system time to.
722 * OldTime [O]: Optional (ie. can be NULL). Old Time.
727 NTSTATUS WINAPI NtSetSystemTime(const LARGE_INTEGER *NewTime, LARGE_INTEGER *OldTime)
737 /* Return the old time if necessary */
739 NtQuerySystemTime(OldTime);
741 RtlTimeToTimeFields(NewTime, &tf);
743 /* call gettimeofday to get the current timezone */
744 gettimeofday(&tv, &tz);
746 /* get delta local time from utc */
747 bias = TIME_GetBias(oldsec, &dst);
749 /* get the number of seconds */
750 t.tm_sec = tf.Second;
751 t.tm_min = tf.Minute;
754 t.tm_mon = tf.Month - 1;
755 t.tm_year = tf.Year - 1900;
758 /* correct for timezone and daylight */
761 /* set the new time */
763 tv.tv_usec = tf.Milliseconds * 1000;
765 /* error and sanity check*/
766 if(sec == (time_t)-1 || abs((int)(sec-oldsec)) > SETTIME_MAX_ADJUST) {
769 #ifdef HAVE_SETTIMEOFDAY
770 err = settimeofday(&tv, NULL); /* 0 is OK, -1 is error */
772 return STATUS_SUCCESS;
778 ERR("Cannot set time to %d/%d/%d %d:%d:%d Time adjustment %ld %s\n",
779 tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second,
780 sec-oldsec, err == -1 ? "No Permission" :
781 sec == (time_t)-1 ? "" : "is too large." );
784 return STATUS_INVALID_PARAMETER;
786 return STATUS_PRIVILEGE_NOT_HELD;
788 return STATUS_NOT_IMPLEMENTED;