1 /* $Id: time.c,v 1.24 2004/11/06 16:04:58 ekohl Exp $
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 *****************************************************************/
15 #include <internal/debug.h>
18 #define TICKSPERMINUTE 600000000
20 /* GLOBALS ******************************************************************/
22 /* Note: Bias[minutes] = UTC - local time */
23 TIME_ZONE_INFORMATION ExpTimeZoneInfo
;
24 LARGE_INTEGER ExpTimeZoneBias
;
28 /* FUNCTIONS ****************************************************************/
31 ExpInitTimeZoneInfo(VOID
)
35 /* Read time zone information from the registry */
36 Status
= RtlQueryTimeZoneInformation(&ExpTimeZoneInfo
);
37 if (!NT_SUCCESS(Status
))
39 memset(&ExpTimeZoneInfo
, 0, sizeof(TIME_ZONE_INFORMATION
));
41 ExpTimeZoneBias
.QuadPart
= (LONGLONG
)0;
42 ExpTimeZoneId
= TIME_ZONE_ID_UNKNOWN
;
46 /* FIXME: Calculate transition dates */
48 ExpTimeZoneBias
.QuadPart
=
49 ((LONGLONG
)(ExpTimeZoneInfo
.Bias
+ ExpTimeZoneInfo
.StandardBias
)) * TICKSPERMINUTE
;
50 ExpTimeZoneId
= TIME_ZONE_ID_STANDARD
;
53 SharedUserData
->TimeZoneBias
.High1Time
= ExpTimeZoneBias
.u
.HighPart
;
54 SharedUserData
->TimeZoneBias
.High2Time
= ExpTimeZoneBias
.u
.HighPart
;
55 SharedUserData
->TimeZoneBias
.LowPart
= ExpTimeZoneBias
.u
.LowPart
;
56 SharedUserData
->TimeZoneId
= ExpTimeZoneId
;
61 * FUNCTION: Sets the system time.
63 * NewTime - Points to a variable that specified the new time
64 * of day in the standard time format.
65 * OldTime - Optionally points to a variable that receives the
66 * old time of day in the standard time format.
70 NtSetSystemTime(IN PLARGE_INTEGER UnsafeNewSystemTime
,
71 OUT PLARGE_INTEGER UnsafeOldSystemTime OPTIONAL
)
74 LARGE_INTEGER OldSystemTime
;
75 LARGE_INTEGER NewSystemTime
;
76 LARGE_INTEGER LocalTime
;
77 TIME_FIELDS TimeFields
;
79 /* FIXME: Check for SeSystemTimePrivilege */
81 if (UnsafeNewSystemTime
== NULL
)
83 /* FIXME: update time zone settings */
85 return STATUS_SUCCESS
;
88 Status
= MmCopyFromCaller(&NewSystemTime
, UnsafeNewSystemTime
,
89 sizeof(NewSystemTime
));
90 if (!NT_SUCCESS(Status
))
95 if (UnsafeOldSystemTime
!= NULL
)
97 KeQuerySystemTime(&OldSystemTime
);
99 ExSystemTimeToLocalTime(&NewSystemTime
,
101 RtlTimeToTimeFields(&LocalTime
,
103 HalSetRealTimeClock(&TimeFields
);
105 /* FIXME: set system time */
110 if (UnsafeOldSystemTime
!= NULL
)
112 Status
= MmCopyToCaller(UnsafeOldSystemTime
, &OldSystemTime
,
113 sizeof(OldSystemTime
));
114 if (!NT_SUCCESS(Status
))
119 return(STATUS_SUCCESS
);
124 * FUNCTION: Retrieves the system time.
126 * CurrentTime - Points to a variable that receives the current
127 * time of day in the standard time format.
130 NtQuerySystemTime(OUT PLARGE_INTEGER UnsafeCurrentTime
)
132 LARGE_INTEGER CurrentTime
;
135 KeQuerySystemTime(&CurrentTime
);
136 Status
= MmCopyToCaller(UnsafeCurrentTime
, &CurrentTime
,
137 sizeof(CurrentTime
));
138 if (!NT_SUCCESS(Status
))
142 return STATUS_SUCCESS
;
151 ExLocalTimeToSystemTime (
152 PLARGE_INTEGER LocalTime
,
153 PLARGE_INTEGER SystemTime
156 SystemTime
->QuadPart
=
159 LocalTime
->QuadPart
+ ExpTimeZoneBias
.QuadPart
;
169 ExSetTimerResolution (
170 IN ULONG DesiredTime
,
171 IN BOOLEAN SetResolution
183 ExSystemTimeToLocalTime (
184 PLARGE_INTEGER SystemTime
,
185 PLARGE_INTEGER LocalTime
188 LocalTime
->QuadPart
=
189 SystemTime
->QuadPart
;
191 SystemTime
->QuadPart
- ExpTimeZoneBias
.QuadPart
;