3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/ex/time.c
7 * PROGRAMMER: David Welch (welch@mcmail.com)
12 /* INCLUDES *****************************************************************/
14 #include <ddk/ntddk.h>
15 #include <internal/ex.h>
16 #include <internal/safe.h>
17 #include <ddk/halfuncs.h>
18 #include <ddk/kefuncs.h>
20 #include <internal/debug.h>
23 #define TICKSPERMINUTE 600000000
25 /* GLOBALS ******************************************************************/
27 /* Note: Bias[minutes] = UTC - local time */
28 TIME_ZONE_INFORMATION _SystemTimeZoneInfo;
31 /* FUNCTIONS ****************************************************************/
34 ExInitTimeZoneInfo (VOID)
36 /* Initialize system time zone information */
37 memset (& _SystemTimeZoneInfo, 0, sizeof(TIME_ZONE_INFORMATION));
39 /* FIXME: Read time zone information from the registry */
45 NtSetSystemTime (IN PLARGE_INTEGER UnsafeNewSystemTime,
46 OUT PLARGE_INTEGER UnsafeOldSystemTime OPTIONAL)
48 * FUNCTION: Sets the system time.
50 * NewTime - Points to a variable that specified the new time
51 * of day in the standard time format.
52 * OldTime - Optionally points to a variable that receives the
53 * old time of day in the standard time format.
58 LARGE_INTEGER OldSystemTime;
59 LARGE_INTEGER NewSystemTime;
61 /* FIXME: Check for SeSystemTimePrivilege */
63 Status = MmCopyFromCaller(&NewSystemTime, UnsafeNewSystemTime,
64 sizeof(NewSystemTime));
65 if (!NT_SUCCESS(Status))
70 if (UnsafeOldSystemTime != NULL)
72 KeQuerySystemTime(&OldSystemTime);
74 HalSetRealTimeClock ((PTIME_FIELDS)&NewSystemTime);
76 if (UnsafeOldSystemTime != NULL)
78 Status = MmCopyToCaller(UnsafeOldSystemTime, &OldSystemTime,
79 sizeof(OldSystemTime));
80 if (!NT_SUCCESS(Status))
85 return(STATUS_SUCCESS);
90 NtQuerySystemTime (OUT TIME* UnsafeCurrentTime)
92 * FUNCTION: Retrieves the system time.
94 * CurrentTime - Points to a variable that receives the current
95 * time of day in the standard time format.
98 LARGE_INTEGER CurrentTime;
101 KeQuerySystemTime(&CurrentTime);
102 Status = MmCopyToCaller(UnsafeCurrentTime, &CurrentTime,
103 sizeof(CurrentTime));
104 if (!NT_SUCCESS(Status))
108 return STATUS_SUCCESS;
114 ExLocalTimeToSystemTime (
115 PLARGE_INTEGER LocalTime,
116 PLARGE_INTEGER SystemTime
119 SystemTime->QuadPart = LocalTime->QuadPart +
120 _SystemTimeZoneInfo.Bias * TICKSPERMINUTE;
126 ExSystemTimeToLocalTime (
127 PLARGE_INTEGER SystemTime,
128 PLARGE_INTEGER LocalTime
131 LocalTime->QuadPart = SystemTime->QuadPart -
132 _SystemTimeZoneInfo.Bias * TICKSPERMINUTE;