/*
* 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
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
-/* STATIC FUNTIONS **********************************************************/
+/* STATIC FUNCTIONS **********************************************************/
static inline int IsLeapYear(int Year)
{
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 */
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 )
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 ) {
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))
{
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);
}
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);
}
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);