:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / ntoskrnl / ex / time.c
1 /* $Id$
2  *
3  * COPYRIGHT:       See COPYING in the top level directory
4  * PROJECT:         ReactOS kernel
5  * FILE:            ntoskrnl/ex/time.c
6  * PURPOSE:         Time
7  * PROGRAMMER:      David Welch (welch@mcmail.com)
8  * UPDATE HISTORY:
9  *                  Created 22/05/98
10  */
11
12 /* INCLUDES *****************************************************************/
13
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>
19
20 #include <internal/debug.h>
21
22
23 #define TICKSPERMINUTE  600000000
24
25 /* GLOBALS ******************************************************************/
26
27 /* Note: Bias[minutes] = UTC - local time */
28 TIME_ZONE_INFORMATION _SystemTimeZoneInfo;
29
30
31 /* FUNCTIONS ****************************************************************/
32
33 VOID
34 ExInitTimeZoneInfo (VOID)
35 {
36   /* Initialize system time zone information */
37   memset (& _SystemTimeZoneInfo, 0, sizeof(TIME_ZONE_INFORMATION));
38
39   /* FIXME: Read time zone information from the registry */
40
41 }
42
43
44 NTSTATUS STDCALL
45 NtSetSystemTime (IN     PLARGE_INTEGER  UnsafeNewSystemTime,
46                  OUT    PLARGE_INTEGER  UnsafeOldSystemTime     OPTIONAL)
47      /*
48       * FUNCTION: Sets the system time.
49       * PARAMETERS:
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.
54       * RETURNS: Status
55       */
56 {
57   NTSTATUS Status;
58   LARGE_INTEGER OldSystemTime;
59   LARGE_INTEGER NewSystemTime;
60
61   /* FIXME: Check for SeSystemTimePrivilege */
62
63   Status = MmCopyFromCaller(&NewSystemTime, UnsafeNewSystemTime,
64                             sizeof(NewSystemTime));
65   if (!NT_SUCCESS(Status))
66     {
67       return(Status);
68     }
69   
70   if (UnsafeOldSystemTime != NULL)
71     {
72       KeQuerySystemTime(&OldSystemTime);
73     }
74   HalSetRealTimeClock ((PTIME_FIELDS)&NewSystemTime);
75
76   if (UnsafeOldSystemTime != NULL)
77     {
78       Status = MmCopyToCaller(UnsafeOldSystemTime, &OldSystemTime,
79                               sizeof(OldSystemTime));
80       if (!NT_SUCCESS(Status))
81         {
82           return(Status);
83         }
84     }
85   return(STATUS_SUCCESS);
86 }
87
88
89 NTSTATUS STDCALL
90 NtQuerySystemTime (OUT TIME* UnsafeCurrentTime)
91      /*
92       * FUNCTION: Retrieves the system time.
93       * PARAMETERS:
94       *          CurrentTime - Points to a variable that receives the current
95       *          time of day in the standard time format.
96       */
97 {
98   LARGE_INTEGER CurrentTime;
99   NTSTATUS Status;
100
101   KeQuerySystemTime(&CurrentTime);
102   Status = MmCopyToCaller(UnsafeCurrentTime, &CurrentTime,
103                           sizeof(CurrentTime));
104   if (!NT_SUCCESS(Status))
105     {
106       return(Status);
107     }
108   return STATUS_SUCCESS;
109 }
110
111
112 VOID
113 STDCALL
114 ExLocalTimeToSystemTime (
115         PLARGE_INTEGER  LocalTime, 
116         PLARGE_INTEGER  SystemTime
117         )
118 {
119    SystemTime->QuadPart = LocalTime->QuadPart +
120                           _SystemTimeZoneInfo.Bias * TICKSPERMINUTE;
121 }
122
123
124 VOID
125 STDCALL
126 ExSystemTimeToLocalTime (
127         PLARGE_INTEGER  SystemTime,
128         PLARGE_INTEGER  LocalTime
129         )
130 {
131    LocalTime->QuadPart = SystemTime->QuadPart -
132                          _SystemTimeZoneInfo.Bias * TICKSPERMINUTE;
133 }
134
135 /* EOF */