Commit d694a376 authored by Rein Klazes's avatar Rein Klazes Committed by Alexandre Julliard

- Reordered some code from the existing helper _GetTimeZoneBias to

make it more general useful (and changed the helper names to TIME_xyz). - Make GetTimeZoneInformation return the correct zone id constants. - Changed some "const LPX_Y_Z" declarations to "const X_Y_Z *".
parent 87fb440e
...@@ -60,143 +60,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(time); ...@@ -60,143 +60,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(time);
ll = (((LONGLONG)((pft)->dwHighDateTime))<<32) + (pft)-> dwLowDateTime ; ll = (((LONGLONG)((pft)->dwHighDateTime))<<32) + (pft)-> dwLowDateTime ;
/*********************************************************************** /***********************************************************************
* SetLocalTime (KERNEL32.@) * TIME_DayLightCompareDate
*
* Set the local time using current time zone and daylight
* savings settings.
*
* RETURNS
* Success: TRUE. The time was set
* Failure: FALSE, if the time was invalid or caller does not have
* permission to change the time.
*/
BOOL WINAPI SetLocalTime(
const SYSTEMTIME *systime) /* [in] The desired local time. */
{
FILETIME ft;
LARGE_INTEGER st, st2;
NTSTATUS status;
SystemTimeToFileTime( systime, &ft );
st.u.LowPart = ft.dwLowDateTime;
st.u.HighPart = ft.dwHighDateTime;
RtlLocalTimeToSystemTime( &st, &st2 );
if ((status = NtSetSystemTime(&st2, NULL)))
SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* GetSystemTimeAdjustment (KERNEL32.@)
*
* Get the period between clock interrupts and the amount the clock
* is adjusted each interrupt so as to keep it in sync with an external source.
*
* RETURNS
* TRUE.
*
* BUGS
* Only the special case of disabled time adjustments is supported.
*/
BOOL WINAPI GetSystemTimeAdjustment(
PDWORD lpTimeAdjustment, /* [out] The clock adjustment per interupt in 100's of nanoseconds. */
PDWORD lpTimeIncrement, /* [out] The time between clock interupts in 100's of nanoseconds. */
PBOOL lpTimeAdjustmentDisabled) /* [out] The clock synchonisation has been disabled. */
{
*lpTimeAdjustment = 0;
*lpTimeIncrement = 0;
*lpTimeAdjustmentDisabled = TRUE;
return TRUE;
}
/***********************************************************************
* SetSystemTime (KERNEL32.@)
*
* Set the system time in utc.
*
* RETURNS
* Success: TRUE. The time was set
* Failure: FALSE, if the time was invalid or caller does not have
* permission to change the time.
*/
BOOL WINAPI SetSystemTime(
const SYSTEMTIME *systime) /* [in] The desired system time. */
{
FILETIME ft;
LARGE_INTEGER t;
NTSTATUS status;
SystemTimeToFileTime( systime, &ft );
t.u.LowPart = ft.dwLowDateTime;
t.u.HighPart = ft.dwHighDateTime;
if ((status = NtSetSystemTime(&t, NULL)))
SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* SetSystemTimeAdjustment (KERNEL32.@)
*
* Enables or disables the timing adjustments to the system's clock.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE.
*/
BOOL WINAPI SetSystemTimeAdjustment(
DWORD dwTimeAdjustment,
BOOL bTimeAdjustmentDisabled)
{
/* Fake function for now... */
FIXME("(%08lx,%d): stub !\n", dwTimeAdjustment, bTimeAdjustmentDisabled);
return TRUE;
}
/***********************************************************************
* GetTimeZoneInformation (KERNEL32.@)
*
* Get information about the current local time zone.
*
* RETURNS
* Success: TIME_ZONE_ID_STANDARD. tzinfo contains the time zone info.
* Failure: TIME_ZONE_ID_INVALID.
* FIXME: return TIME_ZONE_ID_DAYLIGHT when daylight saving is on.
*/
DWORD WINAPI GetTimeZoneInformation(
LPTIME_ZONE_INFORMATION tzinfo) /* [out] Destination for time zone information */
{
NTSTATUS status;
if ((status = RtlQueryTimeZoneInformation(tzinfo)))
SetLastError( RtlNtStatusToDosError(status) );
return TIME_ZONE_ID_STANDARD;
}
/***********************************************************************
* SetTimeZoneInformation (KERNEL32.@)
*
* Change the settings of the current local time zone.
*
* RETURNS
* Success: TRUE. The time zone was updated with the settings from tzinfo
* Failure: FALSE.
*/
BOOL WINAPI SetTimeZoneInformation(
const LPTIME_ZONE_INFORMATION tzinfo) /* [in] The new time zone. */
{
NTSTATUS status;
if ((status = RtlSetTimeZoneInformation(tzinfo)))
SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* _DayLightCompareDate
* *
* Compares two dates without looking at the year * Compares two dates without looking at the year
* *
...@@ -207,10 +71,9 @@ BOOL WINAPI SetTimeZoneInformation( ...@@ -207,10 +71,9 @@ BOOL WINAPI SetTimeZoneInformation(
* 1 if date > compareDate * 1 if date > compareDate
* -2 if an error occures * -2 if an error occures
*/ */
static int TIME_DayLightCompareDate(
static int _DayLightCompareDate( const SYSTEMTIME *date, /* [in] The local time to compare. */
const LPSYSTEMTIME date, /* [in] The local time to compare. */ const SYSTEMTIME *compareDate) /* [in] The daylight saving begin
const LPSYSTEMTIME compareDate) /* [in] The daylight saving begin
or end date */ or end date */
{ {
int limit_day, dayinsecs; int limit_day, dayinsecs;
...@@ -295,96 +158,273 @@ static int _DayLightCompareDate( ...@@ -295,96 +158,273 @@ static int _DayLightCompareDate(
0; /* date is equal to the date limit. */ 0; /* date is equal to the date limit. */
} }
/*********************************************************************** /***********************************************************************
* _GetTimezoneBias * TIME_CompTimeZoneID
* *
* Calculates the local time bias for a given time zone * Computes the local time bias for a given time and time zone
* *
* RETURNS * Returns:
* * TIME_ZONE_ID_INVALID An error occurred
* Returns TRUE when the time zone bias was calculated. * TIME_ZONE_ID_UNKNOWN There are no transition time known
* TIME_ZONE_ID_STANDARD Current time is standard time
* TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
*/ */
static BOOL TIME_CompTimeZoneID (
static BOOL _GetTimezoneBias( const TIME_ZONE_INFORMATION *pTZinfo, /* [in] The time zone data. */
const LPTIME_ZONE_INFORMATION FILETIME *lpFileTime, /* [in] The system or local time. */
lpTimeZoneInformation, /* [in] The time zone data. */ BOOL islocal /* [in] it is local time */
LPSYSTEMTIME lpSysOrLocalTime, /* [in] The system or local time. */
BOOL islocal, /* [in] it is local time */
LONG* pBias /* [out] The calulated bias in minutes */
) )
{ {
int ret; int ret;
BOOL beforeStandardDate, afterDaylightDate; BOOL beforeStandardDate, afterDaylightDate;
BOOL daylightsaving = FALSE; DWORD retval = TIME_ZONE_ID_INVALID;
LONG bias = lpTimeZoneInformation->Bias;
FILETIME ft;
LONGLONG llTime = 0; /* initialized to prevent gcc complaining */ LONGLONG llTime = 0; /* initialized to prevent gcc complaining */
SYSTEMTIME stTemp; SYSTEMTIME SysTime;
LPSYSTEMTIME lpTime = lpSysOrLocalTime; FILETIME ftTemp;
if (lpTimeZoneInformation->DaylightDate.wMonth != 0) if (pTZinfo->DaylightDate.wMonth != 0)
{ {
if (lpTimeZoneInformation->StandardDate.wMonth == 0 || if (pTZinfo->StandardDate.wMonth == 0 ||
lpTimeZoneInformation->StandardDate.wDay<1 || pTZinfo->StandardDate.wDay<1 ||
lpTimeZoneInformation->StandardDate.wDay>5 || pTZinfo->StandardDate.wDay>5 ||
lpTimeZoneInformation->DaylightDate.wDay<1 || pTZinfo->DaylightDate.wDay<1 ||
lpTimeZoneInformation->DaylightDate.wDay>5) pTZinfo->DaylightDate.wDay>5)
{ {
SetLastError(ERROR_INVALID_PARAMETER); SetLastError(ERROR_INVALID_PARAMETER);
return FALSE; return TIME_ZONE_ID_INVALID;
} }
if (!islocal) { if (!islocal) {
if (!SystemTimeToFileTime(lpSysOrLocalTime, &ft)) return -2; FILETIME2LL( lpFileTime, llTime );
FILETIME2LL( &ft, llTime ); llTime -= ( pTZinfo->Bias + pTZinfo->DaylightBias )
llTime -= ( lpTimeZoneInformation->Bias + * (LONGLONG)600000000;
lpTimeZoneInformation->DaylightBias ) * (LONGLONG)600000000; LL2FILETIME( llTime, &ftTemp)
LL2FILETIME( llTime, &ft) lpFileTime = &ftTemp;
FileTimeToSystemTime(&ft, &stTemp);
lpTime = &stTemp;
} }
FileTimeToSystemTime(lpFileTime, &SysTime);
/* check for daylight saving */ /* check for daylight saving */
ret = _DayLightCompareDate(lpTime, &lpTimeZoneInformation->StandardDate); ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->StandardDate);
if (ret == -2) if (ret == -2)
return FALSE; return TIME_ZONE_ID_INVALID;
beforeStandardDate = ret < 0; beforeStandardDate = ret < 0;
if (!islocal) { if (!islocal) {
llTime -= ( lpTimeZoneInformation->StandardBias - llTime -= ( pTZinfo->StandardBias - pTZinfo->DaylightBias )
lpTimeZoneInformation->DaylightBias ) * (LONGLONG)600000000; * (LONGLONG)600000000;
LL2FILETIME( llTime, &ft) LL2FILETIME( llTime, &ftTemp)
FileTimeToSystemTime(&ft, &stTemp); FileTimeToSystemTime(lpFileTime, &SysTime);
lpTime = &stTemp;
} }
ret = _DayLightCompareDate(lpTime, &lpTimeZoneInformation->DaylightDate); ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->DaylightDate);
if (ret == -2) if (ret == -2)
return FALSE; return TIME_ZONE_ID_INVALID;
afterDaylightDate = ret >= 0; afterDaylightDate = ret >= 0;
if( lpTimeZoneInformation->DaylightDate.wMonth < /* Northern */ retval = TIME_ZONE_ID_STANDARD;
lpTimeZoneInformation->StandardDate.wMonth ) { /* hemisphere */ if( pTZinfo->DaylightDate.wMonth < pTZinfo->StandardDate.wMonth ) {
/* Northern hemisphere */
if( beforeStandardDate && afterDaylightDate ) if( beforeStandardDate && afterDaylightDate )
daylightsaving = TRUE; retval = TIME_ZONE_ID_DAYLIGHT;
} else /* Down south */ } else /* Down south */
if( beforeStandardDate || afterDaylightDate ) if( beforeStandardDate || afterDaylightDate )
daylightsaving = TRUE; retval = TIME_ZONE_ID_DAYLIGHT;
} } else
/* No transition date */
retval = TIME_ZONE_ID_UNKNOWN;
return retval;
}
/***********************************************************************
* TIME_TimeZoneID
*
* Calculates whether daylight saving is on now.
*
* Returns:
* TIME_ZONE_ID_INVALID An error occurred
* TIME_ZONE_ID_UNKNOWN There are no transition time known
* TIME_ZONE_ID_STANDARD Current time is standard time
* TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
*/
static DWORD TIME_ZoneID(
const TIME_ZONE_INFORMATION *pTzi /* Timezone info */
)
{
FILETIME ftTime;
GetSystemTimeAsFileTime( &ftTime);
return TIME_CompTimeZoneID( pTzi, &ftTime, FALSE);
}
if (daylightsaving) /***********************************************************************
bias += lpTimeZoneInformation->DaylightBias; * TIME_GetTimezoneBias
else if (lpTimeZoneInformation->StandardDate.wMonth != 0) *
bias += lpTimeZoneInformation->StandardBias; * Calculates the local time bias for a given time zone
*
* RETURNS
*
* Returns TRUE when the time zone bias was calculated.
*/
static BOOL TIME_GetTimezoneBias(
const TIME_ZONE_INFORMATION
*pTZinfo, /* [in] The time zone data. */
FILETIME *lpFileTime, /* [in] The system or local time. */
BOOL islocal, /* [in] it is local time */
LONG *pBias /* [out] The calulated bias in minutes */
)
{
LONG bias = pTZinfo->Bias;
DWORD tzid = TIME_CompTimeZoneID( pTZinfo, lpFileTime, islocal);
if( tzid == TIME_ZONE_ID_INVALID)
return FALSE;
if (tzid == TIME_ZONE_ID_DAYLIGHT)
bias += pTZinfo->DaylightBias;
else if (tzid == TIME_ZONE_ID_STANDARD)
bias += pTZinfo->StandardBias;
*pBias = bias; *pBias = bias;
return TRUE;
}
/***********************************************************************
* SetLocalTime (KERNEL32.@)
*
* Set the local time using current time zone and daylight
* savings settings.
*
* RETURNS
* Success: TRUE. The time was set
* Failure: FALSE, if the time was invalid or caller does not have
* permission to change the time.
*/
BOOL WINAPI SetLocalTime(
const SYSTEMTIME *systime) /* [in] The desired local time. */
{
FILETIME ft;
LARGE_INTEGER st, st2;
NTSTATUS status;
SystemTimeToFileTime( systime, &ft );
st.u.LowPart = ft.dwLowDateTime;
st.u.HighPart = ft.dwHighDateTime;
RtlLocalTimeToSystemTime( &st, &st2 );
if ((status = NtSetSystemTime(&st2, NULL)))
SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* GetSystemTimeAdjustment (KERNEL32.@)
*
* Get the period between clock interrupts and the amount the clock
* is adjusted each interrupt so as to keep it in sync with an external source.
*
* RETURNS
* TRUE.
*
* BUGS
* Only the special case of disabled time adjustments is supported.
*/
BOOL WINAPI GetSystemTimeAdjustment(
PDWORD lpTimeAdjustment, /* [out] The clock adjustment per interupt in 100's of nanoseconds. */
PDWORD lpTimeIncrement, /* [out] The time between clock interupts in 100's of nanoseconds. */
PBOOL lpTimeAdjustmentDisabled) /* [out] The clock synchonisation has been disabled. */
{
*lpTimeAdjustment = 0;
*lpTimeIncrement = 0;
*lpTimeAdjustmentDisabled = TRUE;
return TRUE;
}
/***********************************************************************
* SetSystemTime (KERNEL32.@)
*
* Set the system time in utc.
*
* RETURNS
* Success: TRUE. The time was set
* Failure: FALSE, if the time was invalid or caller does not have
* permission to change the time.
*/
BOOL WINAPI SetSystemTime(
const SYSTEMTIME *systime) /* [in] The desired system time. */
{
FILETIME ft;
LARGE_INTEGER t;
NTSTATUS status;
SystemTimeToFileTime( systime, &ft );
t.u.LowPart = ft.dwLowDateTime;
t.u.HighPart = ft.dwHighDateTime;
if ((status = NtSetSystemTime(&t, NULL)))
SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* SetSystemTimeAdjustment (KERNEL32.@)
*
* Enables or disables the timing adjustments to the system's clock.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE.
*/
BOOL WINAPI SetSystemTimeAdjustment(
DWORD dwTimeAdjustment,
BOOL bTimeAdjustmentDisabled)
{
/* Fake function for now... */
FIXME("(%08lx,%d): stub !\n", dwTimeAdjustment, bTimeAdjustmentDisabled);
return TRUE; return TRUE;
} }
/***********************************************************************
* GetTimeZoneInformation (KERNEL32.@)
*
* Get information about the current local time zone.
*
* RETURNS
* TIME_ZONE_ID_INVALID An error occurred
* TIME_ZONE_ID_UNKNOWN There are no transition time known
* TIME_ZONE_ID_STANDARD Current time is standard time
* TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
*/
DWORD WINAPI GetTimeZoneInformation(
LPTIME_ZONE_INFORMATION tzinfo) /* [out] Destination for time zone information */
{
NTSTATUS status;
if ((status = RtlQueryTimeZoneInformation(tzinfo))) {
SetLastError( RtlNtStatusToDosError(status) );
return TIME_ZONE_ID_INVALID;
}
return TIME_ZoneID( tzinfo );
}
/***********************************************************************
* SetTimeZoneInformation (KERNEL32.@)
*
* Change the settings of the current local time zone.
*
* RETURNS
* Success: TRUE. The time zone was updated with the settings from tzinfo
* Failure: FALSE.
*/
BOOL WINAPI SetTimeZoneInformation(
const TIME_ZONE_INFORMATION *tzinfo) /* [in] The new time zone. */
{
NTSTATUS status;
if ((status = RtlSetTimeZoneInformation(tzinfo)))
SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/*********************************************************************** /***********************************************************************
* SystemTimeToTzSpecificLocalTime (KERNEL32.@) * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
...@@ -420,7 +460,7 @@ BOOL WINAPI SystemTimeToTzSpecificLocalTime( ...@@ -420,7 +460,7 @@ BOOL WINAPI SystemTimeToTzSpecificLocalTime(
if (!SystemTimeToFileTime(lpUniversalTime, &ft)) if (!SystemTimeToFileTime(lpUniversalTime, &ft))
return FALSE; return FALSE;
FILETIME2LL( &ft, llTime) FILETIME2LL( &ft, llTime)
if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, FALSE, &lBias)) if (!TIME_GetTimezoneBias(&tzinfo, &ft, FALSE, &lBias))
return FALSE; return FALSE;
/* convert minutes to 100-nanoseconds-ticks */ /* convert minutes to 100-nanoseconds-ticks */
llTime -= (LONGLONG)lBias * 600000000; llTime -= (LONGLONG)lBias * 600000000;
...@@ -462,7 +502,7 @@ BOOL WINAPI TzSpecificLocalTimeToSystemTime( ...@@ -462,7 +502,7 @@ BOOL WINAPI TzSpecificLocalTimeToSystemTime(
if (!SystemTimeToFileTime(lpLocalTime, &ft)) if (!SystemTimeToFileTime(lpLocalTime, &ft))
return FALSE; return FALSE;
FILETIME2LL( &ft, t) FILETIME2LL( &ft, t)
if (!_GetTimezoneBias(&tzinfo, lpLocalTime, TRUE, &lBias)) if (!TIME_GetTimezoneBias(&tzinfo, &ft, TRUE, &lBias))
return FALSE; return FALSE;
/* convert minutes to 100-nanoseconds-ticks */ /* convert minutes to 100-nanoseconds-ticks */
t += (LONGLONG)lBias * 600000000; t += (LONGLONG)lBias * 600000000;
...@@ -894,12 +934,10 @@ VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) /* [O] Destination for current t ...@@ -894,12 +934,10 @@ VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) /* [O] Destination for current t
*/ */
BOOL WINAPI GetDaylightFlag(void) BOOL WINAPI GetDaylightFlag(void)
{ {
time_t t = time(NULL); TIME_ZONE_INFORMATION tzinfo;
struct tm *ptm = localtime( &t); return GetTimeZoneInformation( &tzinfo) == TIME_ZONE_ID_DAYLIGHT;
return ptm->tm_isdst > 0;
} }
/*********************************************************************** /***********************************************************************
* DosDateTimeToFileTime (KERNEL32.@) * DosDateTimeToFileTime (KERNEL32.@)
*/ */
......
...@@ -1638,7 +1638,7 @@ DWORD WINAPI SetThreadIdealProcessor(HANDLE,DWORD); ...@@ -1638,7 +1638,7 @@ DWORD WINAPI SetThreadIdealProcessor(HANDLE,DWORD);
BOOL WINAPI SetThreadPriority(HANDLE,INT); BOOL WINAPI SetThreadPriority(HANDLE,INT);
BOOL WINAPI SetThreadPriorityBoost(HANDLE,BOOL); BOOL WINAPI SetThreadPriorityBoost(HANDLE,BOOL);
BOOL WINAPI SetThreadToken(PHANDLE,HANDLE); BOOL WINAPI SetThreadToken(PHANDLE,HANDLE);
BOOL WINAPI SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION); BOOL WINAPI SetTimeZoneInformation(const TIME_ZONE_INFORMATION *);
BOOL WINAPI SetVolumeMountPointA(LPCSTR,LPCSTR); BOOL WINAPI SetVolumeMountPointA(LPCSTR,LPCSTR);
BOOL WINAPI SetVolumeMountPointW(LPCSTR,LPCSTR); BOOL WINAPI SetVolumeMountPointW(LPCSTR,LPCSTR);
#define SetVolumeMountPoint WINELIB_NAME_AW(SetVolumeMountPoint) #define SetVolumeMountPoint WINELIB_NAME_AW(SetVolumeMountPoint)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment