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 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
43 #define SETTIME_MAX_ADJUST 120
45 /* This structure is used to store strings that represent all of the time zones
46 * in the world. (This is used to help GetTimeZoneInformation)
50 const char *psTZFromUnix;
51 WCHAR psTZWindows[32];
56 static const struct tagTZ_INFO TZ_INFO[] =
59 {'D','a','t','e','l','i','n','e',' ','S','t','a','n','d','a','r','d',' ',
60 'T','i','m','e','\0'}, -720, 0},
62 {'S','a','m','o','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
65 {'H','a','w','a','i','i','a','n',' ','S','t','a','n','d','a','r','d',' ',
66 'T','i','m','e','\0'}, 600, 0},
68 {'A','l','a','s','k','a','n',' ','S','t','a','n','d','a','r','d',' ','T',
69 'i','m','e','\0'}, 480, 1},
71 {'P','a','c','i','f','i','c',' ','S','t','a','n','d','a','r','d',' ','T',
72 'i','m','e','\0'}, 420, 1},
74 {'U','S',' ','M','o','u','n','t','a','i','n',' ','S','t','a','n','d','a',
75 'r','d',' ','T','i','m','e','\0'}, 420, 0},
77 {'M','o','u','n','t','a','i','n',' ','S','t','a','n','d','a','r','d',' ',
78 'T','i','m','e','\0'}, 360, 1},
80 {'C','e','n','t','r','a','l',' ','A','m','e','r','i','c','a',' ','S','t',
81 'a','n','d','a','r','d',' ','T','i','m','e','\0'}, 360, 0},
83 {'C','e','n','t','r','a','l',' ','S','t','a','n','d','a','r','d',' ','T',
84 'i','m','e','\0'}, 300, 1},
86 {'S','A',' ','P','a','c','i','f','i','c',' ','S','t','a','n','d','a','r',
87 'd',' ','T','i','m','e','\0'}, 300, 0},
89 {'E','a','s','t','e','r','n',' ','S','t','a','n','d','a','r','d',' ','T',
90 'i','m','e','\0'}, 240, 1},
92 {'U','S',' ','E','a','s','t','e','r','n',' ','S','t','a','n','d','a','r',
93 'd',' ','T','i','m','e','\0'}, 300, 0},
95 {'A','t','l','a','n','t','i','c',' ','S','t','a','n','d','a','r','d',' ',
96 'T','i','m','e','\0'}, 180, 1},
98 {'S','A',' ','W','e','s','t','e','r','n',' ','S','t','a','n','d','a','r',
99 'd',' ','T','i','m','e','\0'}, 240, 0},
101 {'P','a','c','i','f','i','c',' ','S','A',' ','S','t','a','n','d','a','r',
102 'd',' ','T','i','m','e','\0'}, 240, 0},
104 {'N','e','w','f','o','u','n','d','l','a','n','d',' ','S','t','a','n','d',
105 'a','r','d',' ','T','i','m','e','\0'}, 150, 1},
107 {'E','.',' ','S','o','u','t','h',' ','A','m','e','r','i','c','a',' ','S',
108 't','a','n','d','a','r','d',' ','T','i','m','e','\0'}, 180, 0},
110 {'S','A',' ','E','a','s','t','e','r','n',' ','S','t','a','n','d','a','r',
111 'd',' ','T','i','m','e','\0'}, 180, 0},
113 {'G','r','e','e','n','l','a','n','d',' ','S','t','a','n','d','a','r','d',
114 ' ','T','i','m','e','\0'}, 120, 1},
116 {'M','i','d','-','A','t','l','a','n','t','i','c',' ','S','t','a','n','d',
117 'a','r','d',' ','T','i','m','e','\0'}, 120, 0},
119 {'A','z','o','r','e','s',' ','S','t','a','n','d','a','r','d',' ','T','i',
120 'm','e','\0'}, 0, 1},
122 {'C','a','p','e',' ','V','e','r','d','e',' ','S','t','a','n','d','a','r',
123 'd',' ','T','i','m','e','\0'}, 60, 0},
125 {'G','r','e','e','n','w','i','c','h',' ','S','t','a','n','d','a','r','d',
126 ' ','T','i','m','e','\0'}, 0, 0},
128 {'G','M','T',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'},
131 {'G','M','T',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'},
134 {'C','e','n','t','r','a','l',' ','E','u','r','o','p','e',' ','S','t','a',
135 'n','d','a','r','d',' ','T','i','m','e','\0'}, -120, 1},
137 {'W','.',' ','C','e','n','t','r','a','l',' ','A','f','r','i','c','a',' ',
138 'S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, -60, 0},
140 {'E','.',' ','E','u','r','o','p','e',' ','S','t','a','n','d','a','r','d',
141 ' ','T','i','m','e','\0'}, -180, 1},
143 {'E','g','y','p','t',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
146 {'S','o','u','t','h',' ','A','f','r','i','c','a',' ','S','t','a','n','d',
147 'a','r','d',' ','T','i','m','e','\0'}, -120, 0},
149 {'I','s','r','a','e','l',' ','S','t','a','n','d','a','r','d',' ','T','i',
150 'm','e','\0'}, -120, 0},
152 {'A','r','a','b','i','c',' ','S','t','a','n','d','a','r','d',' ','T','i',
153 'm','e','\0'}, -240, 1},
155 {'A','r','a','b',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e',
158 {'R','u','s','s','i','a','n',' ','S','t','a','n','d','a','r','d',' ','T',
159 'i','m','e','\0'}, -240, 1},
161 {'E','.',' ','A','f','r','i','c','a',' ','S','t','a','n','d','a','r','d',
162 ' ','T','i','m','e','\0'}, -180, 0},
164 {'I','r','a','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e',
167 {'A','r','a','b','i','a','n',' ','S','t','a','n','d','a','r','d',' ','T',
168 'i','m','e','\0'}, -240, 0},
170 {'C','a','u','c','a','s','u','s',' ','S','t','a','n','d','a','r','d',' ',
171 'T','i','m','e','\0'}, -300, 1},
173 {'A','f','g','h','a','n','i','s','t','a','n',' ','S','t','a','n','d','a',
174 'r','d',' ','T','i','m','e','\0'}, -270, 0},
176 {'E','k','a','t','e','r','i','n','b','u','r','g',' ','S','t','a','n','d',
177 'a','r','d',' ','T','i','m','e','\0'}, -360, 1},
179 {'W','e','s','t',' ','A','s','i','a',' ','S','t','a','n','d','a','r','d',
180 ' ','T','i','m','e','\0'}, -300, 0},
182 {'I','n','d','i','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
185 {'N','e','p','a','l',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
188 {'N','.',' ','C','e','n','t','r','a','l',' ','A','s','i','a',' ','S','t',
189 'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -420, 1},
191 {'C','e','n','t','r','a','l',' ','A','s','i','a',' ','S','t','a','n','d',
192 'a','r','d',' ','T','i','m','e','\0'}, -360, 0},
194 {'S','r','i',' ','L','a','n','k','a',' ','S','t','a','n','d','a','r','d',
195 ' ','T','i','m','e','\0'}, -360, 0},
197 {'M','y','a','n','m','a','r',' ','S','t','a','n','d','a','r','d',' ','T',
198 'i','m','e','\0'}, -390, 0},
200 {'S','E',' ','A','s','i','a',' ','S','t','a','n','d','a','r','d',' ','T',
201 'i','m','e','\0'}, -420, 0},
203 {'N','o','r','t','h',' ','A','s','i','a',' ','S','t','a','n','d','a','r',
204 'd',' ','T','i','m','e','\0'}, -480, 1},
206 {'C','h','i','n','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
209 {'N','o','r','t','h',' ','A','s','i','a',' ','E','a','s','t',' ','S','t',
210 'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -540, 1},
212 {'M','a','l','a','y',' ','P','e','n','i','n','s','u','l','a',' ','S','t',
213 'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -480, 0},
215 {'W','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a','n','d',
216 'a','r','d',' ','T','i','m','e','\0'}, -480, 0},
218 {'T','o','k','y','o',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
221 {'K','o','r','e','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
224 {'Y','a','k','u','t','s','k',' ','S','t','a','n','d','a','r','d',' ','T',
225 'i','m','e','\0'}, -600, 1},
227 {'C','e','n','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a',
228 'n','d','a','r','d',' ','T','i','m','e','\0'}, -570, 0},
230 {'E','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a','n','d',
231 'a','r','d',' ','T','i','m','e','\0'}, -600, 0},
233 {'W','e','s','t',' ','P','a','c','i','f','i','c',' ','S','t','a','n','d',
234 'a','r','d',' ','T','i','m','e','\0'}, -600, 0},
236 {'V','l','a','d','i','v','o','s','t','o','k',' ','S','t','a','n','d','a',
237 'r','d',' ','T','i','m','e','\0'}, -660, 1},
239 {'C','e','n','t','r','a','l',' ','P','a','c','i','f','i','c',' ','S','t',
240 'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -720, 1},
242 {'N','e','w',' ','Z','e','a','l','a','n','d',' ','S','t','a','n','d','a',
243 'r','d',' ','T','i','m','e','\0'}, -720, 0},
245 {'F','i','j','i',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e',
248 {'T','o','n','g','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
252 /*********** start of code by Rex Jolliff (rex@lvcablemodem.com) **************/
254 #define TICKSPERSEC 10000000
255 #define TICKSPERMSEC 10000
256 #define SECSPERDAY 86400
257 #define SECSPERHOUR 3600
258 #define SECSPERMIN 60
259 #define MINSPERHOUR 60
260 #define HOURSPERDAY 24
261 #define EPOCHWEEKDAY 1 /* Jan 1, 1601 was Monday */
262 #define DAYSPERWEEK 7
263 #define EPOCHYEAR 1601
264 #define DAYSPERNORMALYEAR 365
265 #define DAYSPERLEAPYEAR 366
266 #define MONSPERYEAR 12
268 /* 1601 to 1970 is 369 years plus 89 leap days */
269 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)86400)
270 /* 1601 to 1980 is 379 years plus 91 leap days */
271 #define SECS_1601_to_1980 ((379 * 365 + 91) * (ULONGLONG)86400)
274 static const int YearLengths[2] = {DAYSPERNORMALYEAR, DAYSPERLEAPYEAR};
275 static const int MonthLengths[2][MONSPERYEAR] =
277 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
278 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
281 static inline int IsLeapYear(int Year)
283 return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
286 static inline void NormalizeTimeFields(CSHORT *FieldToNormalize, CSHORT *CarryField,int Modulus)
288 *FieldToNormalize = (CSHORT) (*FieldToNormalize - Modulus);
289 *CarryField = (CSHORT) (*CarryField + 1);
292 /******************************************************************************
293 * RtlTimeToTimeFields [NTDLL.@]
295 * Parses Time into a TimeFields structure.
298 * liTime [I]: Time to convert to timefields.
299 * TimeFields [O]: Pointer to TIME_FIELDS structure to hold parsed info.
304 VOID WINAPI RtlTimeToTimeFields(
305 const LARGE_INTEGER *liTime,
306 PTIME_FIELDS TimeFields)
309 int SecondsInDay, CurYear;
310 int LeapYear, CurMonth;
312 LONGLONG Time = liTime->QuadPart;
314 /* Extract millisecond from time and convert time into seconds */
315 TimeFields->Milliseconds = (CSHORT) ((Time % TICKSPERSEC) / TICKSPERMSEC);
316 Time = Time / TICKSPERSEC;
318 /* The native version of RtlTimeToTimeFields does not take leap seconds
321 /* Split the time into days and seconds within the day */
322 Days = Time / SECSPERDAY;
323 SecondsInDay = Time % SECSPERDAY;
325 /* compute time of day */
326 TimeFields->Hour = (CSHORT) (SecondsInDay / SECSPERHOUR);
327 SecondsInDay = SecondsInDay % SECSPERHOUR;
328 TimeFields->Minute = (CSHORT) (SecondsInDay / SECSPERMIN);
329 TimeFields->Second = (CSHORT) (SecondsInDay % SECSPERMIN);
331 /* compute day of week */
332 TimeFields->Weekday = (CSHORT) ((EPOCHWEEKDAY + Days) % DAYSPERWEEK);
336 /* FIXME: handle calendar modifications */
338 { LeapYear = IsLeapYear(CurYear);
339 if (Days < (long) YearLengths[LeapYear])
343 Days = Days - (long) YearLengths[LeapYear];
345 TimeFields->Year = (CSHORT) CurYear;
347 /* Compute month of year */
348 Months = MonthLengths[LeapYear];
349 for (CurMonth = 0; Days >= (long) Months[CurMonth]; CurMonth++)
350 Days = Days - (long) Months[CurMonth];
351 TimeFields->Month = (CSHORT) (CurMonth + 1);
352 TimeFields->Day = (CSHORT) (Days + 1);
355 /******************************************************************************
356 * RtlTimeFieldsToTime [NTDLL.@]
358 * Converts a TIME_FIELDS structure to time.
361 * ftTimeFields [I]: Time fields structure to convert.
362 * Time [O]: Converted time.
368 BOOLEAN WINAPI RtlTimeFieldsToTime(
369 PTIME_FIELDS tfTimeFields,
372 int CurYear, CurMonth;
374 TIME_FIELDS TimeFields = *tfTimeFields;
378 /* FIXME: normalize the TIME_FIELDS structure here */
379 while (TimeFields.Second >= SECSPERMIN)
380 { NormalizeTimeFields(&TimeFields.Second, &TimeFields.Minute, SECSPERMIN);
382 while (TimeFields.Minute >= MINSPERHOUR)
383 { NormalizeTimeFields(&TimeFields.Minute, &TimeFields.Hour, MINSPERHOUR);
385 while (TimeFields.Hour >= HOURSPERDAY)
386 { NormalizeTimeFields(&TimeFields.Hour, &TimeFields.Day, HOURSPERDAY);
388 while (TimeFields.Day > MonthLengths[IsLeapYear(TimeFields.Year)][TimeFields.Month - 1])
389 { NormalizeTimeFields(&TimeFields.Day, &TimeFields.Month, SECSPERMIN);
391 while (TimeFields.Month > MONSPERYEAR)
392 { NormalizeTimeFields(&TimeFields.Month, &TimeFields.Year, MONSPERYEAR);
395 /* FIXME: handle calendar corrections here */
396 for (CurYear = EPOCHYEAR; CurYear < TimeFields.Year; CurYear++)
397 { rcTime += YearLengths[IsLeapYear(CurYear)];
399 for (CurMonth = 1; CurMonth < TimeFields.Month; CurMonth++)
400 { rcTime += MonthLengths[IsLeapYear(CurYear)][CurMonth - 1];
402 rcTime += TimeFields.Day - 1;
403 rcTime *= SECSPERDAY;
404 rcTime += TimeFields.Hour * SECSPERHOUR + TimeFields.Minute * SECSPERMIN + TimeFields.Second;
405 rcTime *= TICKSPERSEC;
406 rcTime += TimeFields.Milliseconds * TICKSPERMSEC;
407 Time->QuadPart = rcTime;
411 /************ end of code by Rex Jolliff (rex@lvcablemodem.com) ***************/
413 /******************************************************************************
414 * RtlLocalTimeToSystemTime [NTDLL.@]
416 * Converts local time to system time.
419 * LocalTime [I]: Localtime to convert.
420 * SystemTime [O]: SystemTime of the supplied localtime.
425 NTSTATUS WINAPI RtlLocalTimeToSystemTime( const LARGE_INTEGER *LocalTime,
426 PLARGE_INTEGER SystemTime)
428 TIME_ZONE_INFORMATION tzinfo;
430 TRACE("(%p, %p)\n", LocalTime, SystemTime);
432 RtlQueryTimeZoneInformation(&tzinfo);
433 SystemTime->QuadPart = LocalTime->QuadPart + tzinfo.Bias * 60 * (LONGLONG)10000000;
434 return STATUS_SUCCESS;
437 /******************************************************************************
438 * RtlSystemTimeToLocalTime [NTDLL.@]
440 * Converts system Time to local time.
443 * SystemTime [I]: System time to convert.
444 * LocalTime [O]: Local time of the supplied system time.
449 NTSTATUS WINAPI RtlSystemTimeToLocalTime( const LARGE_INTEGER *SystemTime,
450 PLARGE_INTEGER LocalTime )
452 TIME_ZONE_INFORMATION tzinfo;
454 TRACE("(%p, %p)\n", SystemTime, LocalTime);
456 RtlQueryTimeZoneInformation(&tzinfo);
457 LocalTime->QuadPart = SystemTime->QuadPart - tzinfo.Bias * 60 * (LONGLONG)10000000;
458 return STATUS_SUCCESS;
461 /******************************************************************************
462 * RtlTimeToSecondsSince1970 [NTDLL.@]
464 * Converts Time to seconds since 1970.
467 * time [I]: Time to convert.
468 * res [O]: Pointer to a LONG to recieve the seconds since 1970.
474 BOOLEAN WINAPI RtlTimeToSecondsSince1970( const LARGE_INTEGER *time, PULONG res )
476 ULONGLONG tmp = ((ULONGLONG)time->s.HighPart << 32) | time->s.LowPart;
477 tmp = RtlLargeIntegerDivide( tmp, 10000000, NULL );
478 tmp -= SECS_1601_TO_1970;
479 if (tmp > 0xffffffff) return FALSE;
484 /******************************************************************************
485 * RtlTimeToSecondsSince1980 [NTDLL.@]
487 * Converts Time to seconds since 1980.
490 * time [I]: Time to convert.
491 * res [O]: Pointer to a integer to recieve the time since 1980.
497 BOOLEAN WINAPI RtlTimeToSecondsSince1980( const LARGE_INTEGER *time, LPDWORD res )
499 ULONGLONG tmp = ((ULONGLONG)time->s.HighPart << 32) | time->s.LowPart;
500 tmp = RtlLargeIntegerDivide( tmp, 10000000, NULL );
501 tmp -= SECS_1601_to_1980;
502 if (tmp > 0xffffffff) return FALSE;
507 /******************************************************************************
508 * RtlSecondsSince1970ToTime [NTDLL.@]
510 * Converts seconds since 1970 to time.
513 * time [I]: Seconds since 1970 to convert.
514 * res [O]: Seconds since 1970 in Time.
519 void WINAPI RtlSecondsSince1970ToTime( DWORD time, LARGE_INTEGER *res )
521 ULONGLONG secs = RtlExtendedIntegerMultiply( time + SECS_1601_TO_1970, 10000000 );
522 res->s.LowPart = (DWORD)secs;
523 res->s.HighPart = (DWORD)(secs >> 32);
526 /******************************************************************************
527 * RtlSecondsSince1980ToTime [NTDLL.@]
529 * Converts seconds since 1980 to time.
532 * time [I]: Seconds since 1980 to convert.
533 * res [O]: Seconds since 1980 in Time.
538 void WINAPI RtlSecondsSince1980ToTime( DWORD time, LARGE_INTEGER *res )
540 ULONGLONG secs = RtlExtendedIntegerMultiply( time + SECS_1601_to_1980, 10000000 );
541 res->s.LowPart = (DWORD)secs;
542 res->s.HighPart = (DWORD)(secs >> 32);
545 /******************************************************************************
546 * RtlTimeToElapsedTimeFields [NTDLL.@]
560 VOID WINAPI RtlTimeToElapsedTimeFields(
561 PLARGE_INTEGER liTime,
562 PTIME_FIELDS TimeFields)
564 FIXME("(%p,%p): stub\n",liTime,TimeFields);
567 /***********************************************************************
568 * NtQuerySystemTime [NTDLL.@]
569 * ZwQuerySystemTime [NTDLL.@]
571 * Gets the current system time.
574 * time [O]: The current system time.
579 NTSTATUS WINAPI NtQuerySystemTime( PLARGE_INTEGER time )
583 gettimeofday( &now, 0 );
584 time->QuadPart = RtlExtendedIntegerMultiply( now.tv_sec+SECS_1601_TO_1970, 10000000 ) + now.tv_usec * 10;
585 return STATUS_SUCCESS;
588 /***********************************************************************
589 * TIME_GetBias [internal]
591 * Helper function calculates delta local time from UTC.
594 * utc [I]: The current utc time.
595 * pdaylight [I]: Local daylight.
598 * The bias for the current timezone.
600 static int TIME_GetBias(time_t utc, int *pdaylight)
602 struct tm *ptm = localtime(&utc);
603 *pdaylight = ptm->tm_isdst; /* daylight for local timezone */
605 ptm->tm_isdst = *pdaylight; /* use local daylight, not that of Greenwich */
606 return (int)(utc-mktime(ptm));
609 /***********************************************************************
610 * TIME_GetTZAsStr [internal]
612 * Helper function that returns the given timezone as a string.
615 * utc [I]: The current utc time.
616 * bias [I]: The bias of the current timezone.
623 * This could be done with a hash table instead of merely iterating through a
624 * table, however with the small amount of entries (60 or so) I didn't think
627 static const WCHAR* TIME_GetTZAsStr (time_t utc, int bias, int dst)
630 struct tm *ptm = localtime(&utc);
633 if (!strftime (psTZName, 7, "%Z", ptm))
636 for (i=0; i<(sizeof(TZ_INFO) / sizeof(struct tagTZ_INFO)); i++)
638 if ( strcmp(TZ_INFO[i].psTZFromUnix, psTZName) == 0 &&
639 TZ_INFO[i].bias == bias &&
640 TZ_INFO[i].dst == dst
642 return TZ_INFO[i].psTZWindows;
648 /***********************************************************************
649 * RtlQueryTimeZoneInformation [NTDLL.@]
651 * Returns the timezone.
654 * tzinfo [O]: Retrieves the timezone info.
659 NTSTATUS WINAPI RtlQueryTimeZoneInformation(LPTIME_ZONE_INFORMATION tzinfo)
665 memset(tzinfo, 0, sizeof(TIME_ZONE_INFORMATION));
668 bias = TIME_GetBias(gmt, &daylight);
670 tzinfo->Bias = -bias / 60;
671 tzinfo->StandardBias = 0;
672 tzinfo->DaylightBias = -60;
673 psTZ = TIME_GetTZAsStr (gmt, (-bias/60), daylight);
674 if (psTZ) strcpyW( tzinfo->StandardName, psTZ );
675 return STATUS_SUCCESS;
678 /***********************************************************************
679 * RtlSetTimeZoneInformation [NTDLL.@]
681 * Sets the current time zone.
684 * tzinfo [I]: Timezone information used to set timezone.
690 * Uses the obsolete unix timezone structure and tz_dsttime member.
692 NTSTATUS WINAPI RtlSetTimeZoneInformation( const TIME_ZONE_INFORMATION *tzinfo )
696 tz.tz_minuteswest = tzinfo->Bias;
698 tz.tz_dsttime = DST_NONE;
702 if(!settimeofday(NULL, &tz))
703 return STATUS_SUCCESS;
704 return STATUS_PRIVILEGE_NOT_HELD;
707 /***********************************************************************
708 * NtSetSystemTime [NTDLL.@]
709 * ZwSetSystemTime [NTDLL.@]
711 * Sets the system time.
714 * NewTime [I]: The time to set the system time to.
715 * OldTime [O]: Optional (ie. can be NULL). Old Time.
720 NTSTATUS WINAPI NtSetSystemTime(const LARGE_INTEGER *NewTime, LARGE_INTEGER *OldTime)
730 /* Return the old time if necessary */
732 NtQuerySystemTime(OldTime);
734 RtlTimeToTimeFields(NewTime, &tf);
736 /* call gettimeofday to get the current timezone */
737 gettimeofday(&tv, &tz);
739 /* get delta local time from utc */
740 bias = TIME_GetBias(oldsec, &dst);
742 /* get the number of seconds */
743 t.tm_sec = tf.Second;
744 t.tm_min = tf.Minute;
747 t.tm_mon = tf.Month - 1;
748 t.tm_year = tf.Year - 1900;
751 /* correct for timezone and daylight */
754 /* set the new time */
756 tv.tv_usec = tf.Milliseconds * 1000;
758 /* error and sanity check*/
759 if(sec == (time_t)-1 || abs((int)(sec-oldsec)) > SETTIME_MAX_ADJUST) {
762 #ifdef HAVE_SETTIMEOFDAY
763 err = settimeofday(&tv, NULL); /* 0 is OK, -1 is error */
765 return STATUS_SUCCESS;
771 ERR("Cannot set time to %d/%d/%d %d:%d:%d Time adjustment %ld %s\n",
772 tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second,
773 sec-oldsec, err == -1 ? "No Permission" :
774 sec == (time_t)-1 ? "" : "is too large." );
777 return STATUS_INVALID_PARAMETER;
779 return STATUS_PRIVILEGE_NOT_HELD;
781 return STATUS_NOT_IMPLEMENTED;