[NDK] Replace the SYSTEMTIME fields StandardDate and DaylightDate in RTL_TIME_ZONE_IN...
[reactos.git] / dll / win32 / kernel32 / wine / timezone.c
index ae0e053..8869848 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
- * FILE:            lib/kernel32/misc/time.c
+ * FILE:            dll/win32/kernel32/wine/timezone.c
  * PURPOSE:         Time conversion functions
  * PROGRAMMER:      Ariadne
  *                  DOSDATE and DOSTIME structures from Onno Hovers
@@ -32,7 +32,7 @@ static const int MonthLengths[2][12] =
     { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
 };
 
-/* STATIC FUNTIONS **********************************************************/
+/* STATIC FUNCTIONS **********************************************************/
 
 static inline int IsLeapYear(int Year)
 {
@@ -120,7 +120,7 @@ static
 DWORD
 TIME_CompTimeZoneID( const TIME_ZONE_INFORMATION *pTZinfo, FILETIME *lpFileTime, BOOL islocal )
 {
-    int ret;
+    int ret, year;
     BOOL beforeStandardDate, afterDaylightDate;
     DWORD retval = TIME_ZONE_ID_INVALID;
     LONGLONG llTime = 0; /* initialized to prevent gcc complaining */
@@ -145,20 +145,29 @@ TIME_CompTimeZoneID( const TIME_ZONE_INFORMATION *pTZinfo, FILETIME *lpFileTime,
 
         if (!islocal) {
             FILETIME2LL( lpFileTime, llTime );
-            llTime -= ( pTZinfo->Bias + pTZinfo->DaylightBias )
-                * (LONGLONG)TICKSPERMIN;
+            llTime -= pTZinfo->Bias * (LONGLONG)TICKSPERMIN;
             LL2FILETIME( llTime, &ftTemp)
             lpFileTime = &ftTemp;
         }
 
         FileTimeToSystemTime(lpFileTime, &SysTime);
+        year = SysTime.wYear;
+
+        if (!islocal) {
+            llTime -= pTZinfo->DaylightBias * (LONGLONG)TICKSPERMIN;
+            LL2FILETIME( llTime, &ftTemp)
+            FileTimeToSystemTime(lpFileTime, &SysTime);
+        }
         
-         /* check for daylight savings */
-        ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->StandardDate);
-        if (ret == -2)
-          return TIME_ZONE_ID_INVALID;
+        /* check for daylight savings */
+        if(year == SysTime.wYear) {
+            ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->StandardDate);
+            if (ret == -2)
+                return TIME_ZONE_ID_INVALID;
 
-        beforeStandardDate = ret < 0;
+            beforeStandardDate = ret < 0;
+        } else
+            beforeStandardDate = SysTime.wYear < year;
 
         if (!islocal) {
             llTime -= ( pTZinfo->StandardBias - pTZinfo->DaylightBias )
@@ -167,11 +176,14 @@ TIME_CompTimeZoneID( const TIME_ZONE_INFORMATION *pTZinfo, FILETIME *lpFileTime,
             FileTimeToSystemTime(lpFileTime, &SysTime);
         }
 
-        ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->DaylightDate);
-        if (ret == -2)
-          return TIME_ZONE_ID_INVALID;
+        if(year == SysTime.wYear) {
+            ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->DaylightDate);
+            if (ret == -2)
+                return TIME_ZONE_ID_INVALID;
 
-        afterDaylightDate = ret >= 0;
+            afterDaylightDate = ret >= 0;
+        } else
+            afterDaylightDate = SysTime.wYear > year;
 
         retval = TIME_ZONE_ID_STANDARD;
         if( pTZinfo->DaylightDate.wMonth <  pTZinfo->StandardDate.wMonth ) {
@@ -249,13 +261,14 @@ DWORD
 WINAPI
 GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
 {
+    RTL_TIME_ZONE_INFORMATION TimeZoneInformation;
     NTSTATUS Status;
 
     DPRINT("GetTimeZoneInformation()\n");
 
     Status = NtQuerySystemInformation(SystemCurrentTimeZoneInformation,
-                                      lpTimeZoneInformation,
-                                      sizeof(TIME_ZONE_INFORMATION),
+                                      &TimeZoneInformation,
+                                      sizeof(RTL_TIME_ZONE_INFORMATION),
                                       NULL);
     if (!NT_SUCCESS(Status))
     {
@@ -263,6 +276,32 @@ GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
         return TIME_ZONE_ID_INVALID;
     }
 
+    lpTimeZoneInformation->Bias = TimeZoneInformation.Bias;
+
+    wcsncpy(lpTimeZoneInformation->StandardName,
+            TimeZoneInformation.StandardName,
+            ARRAYSIZE(lpTimeZoneInformation->StandardName));
+    lpTimeZoneInformation->StandardDate.wYear = TimeZoneInformation.StandardDate.Year;
+    lpTimeZoneInformation->StandardDate.wMonth = TimeZoneInformation.StandardDate.Month;
+    lpTimeZoneInformation->StandardDate.wDay = TimeZoneInformation.StandardDate.Day;
+    lpTimeZoneInformation->StandardDate.wHour = TimeZoneInformation.StandardDate.Hour;
+    lpTimeZoneInformation->StandardDate.wMinute = TimeZoneInformation.StandardDate.Minute;
+    lpTimeZoneInformation->StandardDate.wSecond = TimeZoneInformation.StandardDate.Second;
+    lpTimeZoneInformation->StandardDate.wDayOfWeek = TimeZoneInformation.StandardDate.Weekday;
+    lpTimeZoneInformation->StandardBias = TimeZoneInformation.StandardBias;
+
+    wcsncpy(lpTimeZoneInformation->DaylightName,
+            TimeZoneInformation.DaylightName,
+            ARRAYSIZE(lpTimeZoneInformation->DaylightName));
+    lpTimeZoneInformation->DaylightDate.wYear = TimeZoneInformation.DaylightDate.Year;
+    lpTimeZoneInformation->DaylightDate.wMonth = TimeZoneInformation.DaylightDate.Month;
+    lpTimeZoneInformation->DaylightDate.wDay = TimeZoneInformation.DaylightDate.Day;
+    lpTimeZoneInformation->DaylightDate.wHour = TimeZoneInformation.DaylightDate.Hour;
+    lpTimeZoneInformation->DaylightDate.wMinute = TimeZoneInformation.DaylightDate.Minute;
+    lpTimeZoneInformation->DaylightDate.wSecond = TimeZoneInformation.DaylightDate.Second;
+    lpTimeZoneInformation->DaylightDate.wDayOfWeek = TimeZoneInformation.DaylightDate.Weekday;
+    lpTimeZoneInformation->DaylightBias = TimeZoneInformation.DaylightBias;
+
     return TIME_ZoneID(lpTimeZoneInformation);
 }
 
@@ -274,11 +313,38 @@ BOOL
 WINAPI
 SetTimeZoneInformation(CONST TIME_ZONE_INFORMATION *lpTimeZoneInformation)
 {
+    RTL_TIME_ZONE_INFORMATION TimeZoneInformation;
     NTSTATUS Status;
 
     DPRINT("SetTimeZoneInformation()\n");
 
-    Status = RtlSetTimeZoneInformation((LPTIME_ZONE_INFORMATION)lpTimeZoneInformation);
+    TimeZoneInformation.Bias = lpTimeZoneInformation->Bias;
+
+    wcsncpy(TimeZoneInformation.StandardName,
+            lpTimeZoneInformation->StandardName,
+            ARRAYSIZE(TimeZoneInformation.StandardName));
+    TimeZoneInformation.StandardDate.Year = lpTimeZoneInformation->StandardDate.wYear;
+    TimeZoneInformation.StandardDate.Month = lpTimeZoneInformation->StandardDate.wMonth;
+    TimeZoneInformation.StandardDate.Day = lpTimeZoneInformation->StandardDate.wDay;
+    TimeZoneInformation.StandardDate.Hour = lpTimeZoneInformation->StandardDate.wHour;
+    TimeZoneInformation.StandardDate.Minute = lpTimeZoneInformation->StandardDate.wMinute;
+    TimeZoneInformation.StandardDate.Second = lpTimeZoneInformation->StandardDate.wSecond;
+    TimeZoneInformation.StandardDate.Weekday = lpTimeZoneInformation->StandardDate.wDayOfWeek;
+    TimeZoneInformation.StandardBias = lpTimeZoneInformation->StandardBias;
+
+    wcsncpy(TimeZoneInformation.DaylightName,
+            lpTimeZoneInformation->DaylightName,
+            ARRAYSIZE(TimeZoneInformation.DaylightName));
+    TimeZoneInformation.DaylightDate.Year = lpTimeZoneInformation->DaylightDate.wYear;
+    TimeZoneInformation.DaylightDate.Month = lpTimeZoneInformation->DaylightDate.wMonth;
+    TimeZoneInformation.DaylightDate.Day = lpTimeZoneInformation->DaylightDate.wDay;
+    TimeZoneInformation.DaylightDate.Hour = lpTimeZoneInformation->DaylightDate.wHour;
+    TimeZoneInformation.DaylightDate.Minute = lpTimeZoneInformation->DaylightDate.wMinute;
+    TimeZoneInformation.DaylightDate.Second = lpTimeZoneInformation->DaylightDate.wSecond;
+    TimeZoneInformation.DaylightDate.Weekday = lpTimeZoneInformation->DaylightDate.wDayOfWeek;
+    TimeZoneInformation.DaylightBias = lpTimeZoneInformation->DaylightBias;
+
+    Status = RtlSetTimeZoneInformation(&TimeZoneInformation);
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("RtlSetTimeZoneInformation() failed (Status %lx)\n", Status);
@@ -287,8 +353,8 @@ SetTimeZoneInformation(CONST TIME_ZONE_INFORMATION *lpTimeZoneInformation)
     }
 
     Status = NtSetSystemInformation(SystemCurrentTimeZoneInformation,
-                                    (PVOID)lpTimeZoneInformation,
-                                    sizeof(TIME_ZONE_INFORMATION));
+                                    (PVOID)&TimeZoneInformation,
+                                    sizeof(RTL_TIME_ZONE_INFORMATION));
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("NtSetSystemInformation() failed (Status %lx)\n", Status);