1999-03-09 18:47:51 +01:00
|
|
|
/*
|
2002-11-25 02:12:39 +01:00
|
|
|
* Nt time functions.
|
1999-03-09 18:47:51 +01:00
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* RtlTimeToTimeFields, RtlTimeFieldsToTime and defines are taken from ReactOS and
|
2003-08-19 02:56:34 +02:00
|
|
|
* adapted to wine with special permissions of the author. This code is
|
|
|
|
* Copyright 2002 Rex Jolliff (rex@lvcablemodem.com)
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* Copyright 1999 Juergen Schmied
|
2007-08-07 13:01:16 +02:00
|
|
|
* Copyright 2007 Dmitry Timoshkov
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-11-27 21:14:45 +01:00
|
|
|
#include <stdlib.h>
|
2007-07-29 14:31:00 +02:00
|
|
|
#include <errno.h>
|
1999-03-25 16:57:35 +01:00
|
|
|
#include <string.h>
|
2004-09-08 01:01:34 +02:00
|
|
|
#include <limits.h>
|
2000-10-01 03:40:42 +02:00
|
|
|
#include <time.h>
|
2003-01-07 21:36:20 +01:00
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2020-05-21 18:55:54 +02:00
|
|
|
#define NONAMELESSUNION
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2020-05-21 17:07:20 +02:00
|
|
|
#include "ddk/wdm.h"
|
2017-01-26 17:05:10 +01:00
|
|
|
#include "wine/exception.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2003-04-03 00:48:59 +02:00
|
|
|
#include "ntdll_misc.h"
|
1999-04-19 16:56:29 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
|
1999-03-09 18:47:51 +01:00
|
|
|
|
|
|
|
#define TICKSPERSEC 10000000
|
|
|
|
#define TICKSPERMSEC 10000
|
|
|
|
#define SECSPERDAY 86400
|
|
|
|
#define SECSPERHOUR 3600
|
|
|
|
#define SECSPERMIN 60
|
|
|
|
#define MINSPERHOUR 60
|
|
|
|
#define HOURSPERDAY 24
|
2002-12-13 21:53:04 +01:00
|
|
|
#define EPOCHWEEKDAY 1 /* Jan 1, 1601 was Monday */
|
1999-03-09 18:47:51 +01:00
|
|
|
#define DAYSPERWEEK 7
|
|
|
|
#define MONSPERYEAR 12
|
2004-02-24 02:01:27 +01:00
|
|
|
#define DAYSPERQUADRICENTENNIUM (365 * 400 + 97)
|
|
|
|
#define DAYSPERNORMALQUADRENNIUM (365 * 4 + 1)
|
1999-03-09 18:47:51 +01:00
|
|
|
|
2000-10-01 03:40:42 +02:00
|
|
|
/* 1601 to 1970 is 369 years plus 89 leap days */
|
2003-03-31 03:37:04 +02:00
|
|
|
#define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
|
|
|
|
#define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
|
2000-10-01 03:40:42 +02:00
|
|
|
/* 1601 to 1980 is 379 years plus 91 leap days */
|
2003-03-31 03:37:04 +02:00
|
|
|
#define SECS_1601_TO_1980 ((379 * 365 + 91) * (ULONGLONG)SECSPERDAY)
|
|
|
|
#define TICKS_1601_TO_1980 (SECS_1601_TO_1980 * TICKSPERSEC)
|
2000-10-01 03:40:42 +02:00
|
|
|
|
|
|
|
|
1999-03-09 18:47:51 +01:00
|
|
|
static const int MonthLengths[2][MONSPERYEAR] =
|
|
|
|
{
|
|
|
|
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
|
|
|
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
|
|
|
};
|
|
|
|
|
2013-10-29 21:54:12 +01:00
|
|
|
static inline BOOL IsLeapYear(int Year)
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2013-10-29 21:54:12 +01:00
|
|
|
return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0);
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
|
|
|
|
2013-01-25 17:27:52 +01:00
|
|
|
|
1999-03-09 18:47:51 +01:00
|
|
|
/******************************************************************************
|
2002-11-25 02:12:39 +01:00
|
|
|
* RtlTimeToTimeFields [NTDLL.@]
|
|
|
|
*
|
2003-08-19 02:56:34 +02:00
|
|
|
* Convert a time into a TIME_FIELDS structure.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* PARAMS
|
2003-08-19 02:56:34 +02:00
|
|
|
* liTime [I] Time to convert.
|
|
|
|
* TimeFields [O] Destination for the converted time.
|
1999-03-09 18:47:51 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* RETURNS
|
2002-11-25 02:12:39 +01:00
|
|
|
* Nothing.
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
|
|
|
VOID WINAPI RtlTimeToTimeFields(
|
2002-11-25 02:12:39 +01:00
|
|
|
const LARGE_INTEGER *liTime,
|
1999-03-09 18:47:51 +01:00
|
|
|
PTIME_FIELDS TimeFields)
|
|
|
|
{
|
2004-11-06 04:53:53 +01:00
|
|
|
int SecondsInDay;
|
|
|
|
long int cleaps, years, yearday, months;
|
1999-03-09 18:47:51 +01:00
|
|
|
long int Days;
|
2004-11-06 04:53:53 +01:00
|
|
|
LONGLONG Time;
|
1999-03-09 18:47:51 +01:00
|
|
|
|
|
|
|
/* Extract millisecond from time and convert time into seconds */
|
2004-11-06 04:53:53 +01:00
|
|
|
TimeFields->Milliseconds =
|
|
|
|
(CSHORT) (( liTime->QuadPart % TICKSPERSEC) / TICKSPERMSEC);
|
|
|
|
Time = liTime->QuadPart / TICKSPERSEC;
|
1999-03-09 18:47:51 +01:00
|
|
|
|
2002-11-06 22:57:23 +01:00
|
|
|
/* The native version of RtlTimeToTimeFields does not take leap seconds
|
|
|
|
* into account */
|
1999-03-09 18:47:51 +01:00
|
|
|
|
|
|
|
/* Split the time into days and seconds within the day */
|
|
|
|
Days = Time / SECSPERDAY;
|
|
|
|
SecondsInDay = Time % SECSPERDAY;
|
|
|
|
|
|
|
|
/* compute time of day */
|
|
|
|
TimeFields->Hour = (CSHORT) (SecondsInDay / SECSPERHOUR);
|
|
|
|
SecondsInDay = SecondsInDay % SECSPERHOUR;
|
|
|
|
TimeFields->Minute = (CSHORT) (SecondsInDay / SECSPERMIN);
|
|
|
|
TimeFields->Second = (CSHORT) (SecondsInDay % SECSPERMIN);
|
|
|
|
|
|
|
|
/* compute day of week */
|
|
|
|
TimeFields->Weekday = (CSHORT) ((EPOCHWEEKDAY + Days) % DAYSPERWEEK);
|
|
|
|
|
2004-11-06 04:53:53 +01:00
|
|
|
/* compute year, month and day of month. */
|
|
|
|
cleaps=( 3 * ((4 * Days + 1227) / DAYSPERQUADRICENTENNIUM) + 3 ) / 4;
|
|
|
|
Days += 28188 + cleaps;
|
|
|
|
years = (20 * Days - 2442) / (5 * DAYSPERNORMALQUADRENNIUM);
|
|
|
|
yearday = Days - (years * DAYSPERNORMALQUADRENNIUM)/4;
|
|
|
|
months = (64 * yearday) / 1959;
|
|
|
|
/* the result is based on a year starting on March.
|
|
|
|
* To convert take 12 from Januari and Februari and
|
|
|
|
* increase the year by one. */
|
|
|
|
if( months < 14 ) {
|
|
|
|
TimeFields->Month = months - 1;
|
|
|
|
TimeFields->Year = years + 1524;
|
|
|
|
} else {
|
|
|
|
TimeFields->Month = months - 13;
|
|
|
|
TimeFields->Year = years + 1525;
|
|
|
|
}
|
|
|
|
/* calculation of day of month is based on the wonderful
|
|
|
|
* sequence of INT( n * 30.6): it reproduces the
|
|
|
|
* 31-30-31-30-31-31 month lengths exactly for small n's */
|
|
|
|
TimeFields->Day = yearday - (1959 * months) / 64 ;
|
|
|
|
return;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
2002-11-06 22:57:23 +01:00
|
|
|
|
1999-03-09 18:47:51 +01:00
|
|
|
/******************************************************************************
|
2002-11-25 02:12:39 +01:00
|
|
|
* RtlTimeFieldsToTime [NTDLL.@]
|
|
|
|
*
|
2003-08-19 02:56:34 +02:00
|
|
|
* Convert a TIME_FIELDS structure into a time.
|
1999-03-09 18:47:51 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* PARAMS
|
2003-08-19 02:56:34 +02:00
|
|
|
* ftTimeFields [I] TIME_FIELDS structure to convert.
|
|
|
|
* Time [O] Destination for the converted time.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* RETURNS
|
2003-08-19 02:56:34 +02:00
|
|
|
* Success: TRUE.
|
|
|
|
* Failure: FALSE.
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
|
|
|
BOOLEAN WINAPI RtlTimeFieldsToTime(
|
|
|
|
PTIME_FIELDS tfTimeFields,
|
|
|
|
PLARGE_INTEGER Time)
|
|
|
|
{
|
2004-11-06 04:53:53 +01:00
|
|
|
int month, year, cleaps, day;
|
1999-03-09 18:47:51 +01:00
|
|
|
|
|
|
|
/* FIXME: normalize the TIME_FIELDS structure here */
|
2004-11-06 04:53:53 +01:00
|
|
|
/* No, native just returns 0 (error) if the fields are not */
|
|
|
|
if( tfTimeFields->Milliseconds< 0 || tfTimeFields->Milliseconds > 999 ||
|
|
|
|
tfTimeFields->Second < 0 || tfTimeFields->Second > 59 ||
|
|
|
|
tfTimeFields->Minute < 0 || tfTimeFields->Minute > 59 ||
|
|
|
|
tfTimeFields->Hour < 0 || tfTimeFields->Hour > 23 ||
|
|
|
|
tfTimeFields->Month < 1 || tfTimeFields->Month > 12 ||
|
|
|
|
tfTimeFields->Day < 1 ||
|
|
|
|
tfTimeFields->Day > MonthLengths
|
|
|
|
[ tfTimeFields->Month ==2 || IsLeapYear(tfTimeFields->Year)]
|
|
|
|
[ tfTimeFields->Month - 1] ||
|
|
|
|
tfTimeFields->Year < 1601 )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* now calculate a day count from the date
|
|
|
|
* First start counting years from March. This way the leap days
|
|
|
|
* are added at the end of the year, not somewhere in the middle.
|
|
|
|
* Formula's become so much less complicate that way.
|
|
|
|
* To convert: add 12 to the month numbers of Jan and Feb, and
|
|
|
|
* take 1 from the year */
|
|
|
|
if(tfTimeFields->Month < 3) {
|
|
|
|
month = tfTimeFields->Month + 13;
|
|
|
|
year = tfTimeFields->Year - 1;
|
|
|
|
} else {
|
|
|
|
month = tfTimeFields->Month + 1;
|
|
|
|
year = tfTimeFields->Year;
|
|
|
|
}
|
|
|
|
cleaps = (3 * (year / 100) + 3) / 4; /* nr of "century leap years"*/
|
|
|
|
day = (36525 * year) / 100 - cleaps + /* year * dayperyr, corrected */
|
|
|
|
(1959 * month) / 64 + /* months * daypermonth */
|
|
|
|
tfTimeFields->Day - /* day of the month */
|
|
|
|
584817 ; /* zero that on 1601-01-01 */
|
|
|
|
/* done */
|
|
|
|
|
|
|
|
Time->QuadPart = (((((LONGLONG) day * HOURSPERDAY +
|
|
|
|
tfTimeFields->Hour) * MINSPERHOUR +
|
|
|
|
tfTimeFields->Minute) * SECSPERMIN +
|
|
|
|
tfTimeFields->Second ) * 1000 +
|
|
|
|
tfTimeFields->Milliseconds ) * TICKSPERMSEC;
|
|
|
|
|
|
|
|
return TRUE;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
2002-11-25 02:12:39 +01:00
|
|
|
|
2004-02-26 06:26:34 +01:00
|
|
|
|
2002-12-11 01:19:56 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* RtlLocalTimeToSystemTime [NTDLL.@]
|
|
|
|
*
|
2003-08-19 02:56:34 +02:00
|
|
|
* Convert a local time into system time.
|
2002-12-11 01:19:56 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* PARAMS
|
2003-08-19 02:56:34 +02:00
|
|
|
* LocalTime [I] Local time to convert.
|
|
|
|
* SystemTime [O] Destination for the converted time.
|
2002-12-11 01:19:56 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* RETURNS
|
2003-08-19 02:56:34 +02:00
|
|
|
* Success: STATUS_SUCCESS.
|
|
|
|
* Failure: An NTSTATUS error code indicating the problem.
|
2002-12-11 01:19:56 +01:00
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlLocalTimeToSystemTime( const LARGE_INTEGER *LocalTime,
|
|
|
|
PLARGE_INTEGER SystemTime)
|
|
|
|
{
|
2020-06-25 12:30:00 +02:00
|
|
|
SYSTEM_TIMEOFDAY_INFORMATION info;
|
2002-12-11 01:19:56 +01:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", LocalTime, SystemTime);
|
|
|
|
|
2020-06-25 12:30:00 +02:00
|
|
|
NtQuerySystemInformation( SystemTimeOfDayInformation, &info, sizeof(info), NULL );
|
|
|
|
SystemTime->QuadPart = LocalTime->QuadPart + info.TimeZoneBias.QuadPart;
|
2002-12-11 01:19:56 +01:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
1999-03-09 18:47:51 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
2002-11-25 02:12:39 +01:00
|
|
|
* RtlSystemTimeToLocalTime [NTDLL.@]
|
|
|
|
*
|
2003-08-19 02:56:34 +02:00
|
|
|
* Convert a system time into a local time.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* PARAMS
|
|
|
|
* SystemTime [I] System time to convert.
|
2003-08-19 02:56:34 +02:00
|
|
|
* LocalTime [O] Destination for the converted time.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* RETURNS
|
2003-08-19 02:56:34 +02:00
|
|
|
* Success: STATUS_SUCCESS.
|
|
|
|
* Failure: An NTSTATUS error code indicating the problem.
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2002-12-11 01:19:56 +01:00
|
|
|
NTSTATUS WINAPI RtlSystemTimeToLocalTime( const LARGE_INTEGER *SystemTime,
|
|
|
|
PLARGE_INTEGER LocalTime )
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2020-06-25 12:30:00 +02:00
|
|
|
SYSTEM_TIMEOFDAY_INFORMATION info;
|
2002-12-11 01:19:56 +01:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", SystemTime, LocalTime);
|
1999-03-09 18:47:51 +01:00
|
|
|
|
2020-06-25 12:30:00 +02:00
|
|
|
NtQuerySystemInformation( SystemTimeOfDayInformation, &info, sizeof(info), NULL );
|
|
|
|
LocalTime->QuadPart = SystemTime->QuadPart - info.TimeZoneBias.QuadPart;
|
2002-12-11 01:19:56 +01:00
|
|
|
return STATUS_SUCCESS;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
2000-07-29 23:56:59 +02:00
|
|
|
|
1999-03-09 18:47:51 +01:00
|
|
|
/******************************************************************************
|
2002-11-25 02:12:39 +01:00
|
|
|
* RtlTimeToSecondsSince1970 [NTDLL.@]
|
|
|
|
*
|
2003-08-19 02:56:34 +02:00
|
|
|
* Convert a time into a count of seconds since 1970.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* PARAMS
|
2003-08-19 02:56:34 +02:00
|
|
|
* Time [I] Time to convert.
|
|
|
|
* Seconds [O] Destination for the converted time.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* RETURNS
|
2003-08-19 02:56:34 +02:00
|
|
|
* Success: TRUE.
|
|
|
|
* Failure: FALSE, if the resulting value will not fit in a DWORD.
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2003-08-19 02:56:34 +02:00
|
|
|
BOOLEAN WINAPI RtlTimeToSecondsSince1970( const LARGE_INTEGER *Time, LPDWORD Seconds )
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2012-10-30 11:43:05 +01:00
|
|
|
ULONGLONG tmp = Time->QuadPart / TICKSPERSEC - SECS_1601_TO_1970;
|
2000-10-01 03:40:42 +02:00
|
|
|
if (tmp > 0xffffffff) return FALSE;
|
2012-10-30 11:43:05 +01:00
|
|
|
*Seconds = tmp;
|
2000-07-29 23:56:59 +02:00
|
|
|
return TRUE;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2002-11-25 02:12:39 +01:00
|
|
|
* RtlTimeToSecondsSince1980 [NTDLL.@]
|
|
|
|
*
|
2003-08-19 02:56:34 +02:00
|
|
|
* Convert a time into a count of seconds since 1980.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* PARAMS
|
2003-08-19 02:56:34 +02:00
|
|
|
* Time [I] Time to convert.
|
|
|
|
* Seconds [O] Destination for the converted time.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* RETURNS
|
2003-08-19 02:56:34 +02:00
|
|
|
* Success: TRUE.
|
|
|
|
* Failure: FALSE, if the resulting value will not fit in a DWORD.
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2003-08-19 02:56:34 +02:00
|
|
|
BOOLEAN WINAPI RtlTimeToSecondsSince1980( const LARGE_INTEGER *Time, LPDWORD Seconds )
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2012-10-30 11:43:05 +01:00
|
|
|
ULONGLONG tmp = Time->QuadPart / TICKSPERSEC - SECS_1601_TO_1980;
|
2000-10-01 03:40:42 +02:00
|
|
|
if (tmp > 0xffffffff) return FALSE;
|
2012-10-30 11:43:05 +01:00
|
|
|
*Seconds = tmp;
|
2000-07-29 23:56:59 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2002-11-25 02:12:39 +01:00
|
|
|
* RtlSecondsSince1970ToTime [NTDLL.@]
|
|
|
|
*
|
2003-08-19 02:56:34 +02:00
|
|
|
* Convert a count of seconds since 1970 to a time.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* PARAMS
|
2003-08-19 02:56:34 +02:00
|
|
|
* Seconds [I] Time to convert.
|
|
|
|
* Time [O] Destination for the converted time.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* RETURNS
|
2002-11-25 02:12:39 +01:00
|
|
|
* Nothing.
|
2000-07-29 23:56:59 +02:00
|
|
|
*/
|
2003-08-19 02:56:34 +02:00
|
|
|
void WINAPI RtlSecondsSince1970ToTime( DWORD Seconds, LARGE_INTEGER *Time )
|
2000-07-29 23:56:59 +02:00
|
|
|
{
|
2012-10-30 11:43:05 +01:00
|
|
|
Time->QuadPart = Seconds * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
|
2000-07-29 23:56:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2002-11-25 02:12:39 +01:00
|
|
|
* RtlSecondsSince1980ToTime [NTDLL.@]
|
|
|
|
*
|
2003-08-19 02:56:34 +02:00
|
|
|
* Convert a count of seconds since 1980 to a time.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* PARAMS
|
2003-08-19 02:56:34 +02:00
|
|
|
* Seconds [I] Time to convert.
|
|
|
|
* Time [O] Destination for the converted time.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* RETURNS
|
2002-11-25 02:12:39 +01:00
|
|
|
* Nothing.
|
2000-07-29 23:56:59 +02:00
|
|
|
*/
|
2003-08-19 02:56:34 +02:00
|
|
|
void WINAPI RtlSecondsSince1980ToTime( DWORD Seconds, LARGE_INTEGER *Time )
|
2000-07-29 23:56:59 +02:00
|
|
|
{
|
2012-10-30 11:43:05 +01:00
|
|
|
Time->QuadPart = Seconds * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1980;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2002-11-25 02:12:39 +01:00
|
|
|
* RtlTimeToElapsedTimeFields [NTDLL.@]
|
|
|
|
*
|
2003-08-19 02:56:34 +02:00
|
|
|
* Convert a time to a count of elapsed seconds.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* Time [I] Time to convert.
|
|
|
|
* TimeFields [O] Destination for the converted time.
|
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* RETURNS
|
2002-11-25 02:12:39 +01:00
|
|
|
* Nothing.
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
2002-12-18 03:31:33 +01:00
|
|
|
void WINAPI RtlTimeToElapsedTimeFields( const LARGE_INTEGER *Time, PTIME_FIELDS TimeFields )
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
2002-12-18 03:31:33 +01:00
|
|
|
LONGLONG time;
|
2005-09-02 16:47:36 +02:00
|
|
|
INT rem;
|
2002-12-18 03:31:33 +01:00
|
|
|
|
2009-08-24 12:50:11 +02:00
|
|
|
time = Time->QuadPart / TICKSPERSEC;
|
|
|
|
TimeFields->Milliseconds = (Time->QuadPart % TICKSPERSEC) / TICKSPERMSEC;
|
2002-12-18 03:31:33 +01:00
|
|
|
|
|
|
|
/* time is now in seconds */
|
|
|
|
TimeFields->Year = 0;
|
|
|
|
TimeFields->Month = 0;
|
2009-08-24 12:50:11 +02:00
|
|
|
TimeFields->Day = time / SECSPERDAY;
|
2002-12-18 03:31:33 +01:00
|
|
|
|
|
|
|
/* rem is now the remaining seconds in the last day */
|
2009-08-24 12:50:11 +02:00
|
|
|
rem = time % SECSPERDAY;
|
2002-12-18 03:31:33 +01:00
|
|
|
TimeFields->Second = rem % 60;
|
|
|
|
rem /= 60;
|
|
|
|
TimeFields->Minute = rem % 60;
|
|
|
|
TimeFields->Hour = rem / 60;
|
1999-03-09 18:47:51 +01:00
|
|
|
}
|
2000-10-01 03:40:42 +02:00
|
|
|
|
2019-05-14 10:53:42 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlGetSystemTimePrecise [NTDLL.@]
|
|
|
|
*
|
|
|
|
* Get a more accurate current system time.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The current system time.
|
|
|
|
*/
|
|
|
|
LONGLONG WINAPI RtlGetSystemTimePrecise( void )
|
|
|
|
{
|
2020-06-25 18:07:38 +02:00
|
|
|
return unix_funcs->RtlGetSystemTimePrecise();
|
2019-05-14 10:53:42 +02:00
|
|
|
}
|
|
|
|
|
2019-09-09 12:08:27 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* RtlQueryPerformanceCounter [NTDLL.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DECLSPEC_HOTPATCH RtlQueryPerformanceCounter( LARGE_INTEGER *counter )
|
|
|
|
{
|
2020-07-21 15:51:38 +02:00
|
|
|
NtQueryPerformanceCounter( counter, NULL );
|
2019-09-09 12:08:27 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* RtlQueryPerformanceFrequency [NTDLL.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DECLSPEC_HOTPATCH RtlQueryPerformanceFrequency( LARGE_INTEGER *frequency )
|
|
|
|
{
|
|
|
|
frequency->QuadPart = TICKSPERSEC;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-04-19 21:21:52 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtGetTickCount (NTDLL.@)
|
|
|
|
* ZwGetTickCount (NTDLL.@)
|
|
|
|
*/
|
2020-05-21 18:55:54 +02:00
|
|
|
ULONG WINAPI DECLSPEC_HOTPATCH NtGetTickCount(void)
|
2006-04-19 21:21:52 +02:00
|
|
|
{
|
2020-05-21 18:55:54 +02:00
|
|
|
/* note: we ignore TickCountMultiplier */
|
|
|
|
return user_shared_data->u.TickCount.LowPart;
|
2006-04-19 21:21:52 +02:00
|
|
|
}
|
|
|
|
|
2002-11-25 02:12:39 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlQueryTimeZoneInformation [NTDLL.@]
|
|
|
|
*
|
2003-08-19 02:56:34 +02:00
|
|
|
* Get information about the current timezone.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* PARAMS
|
2003-08-19 02:56:34 +02:00
|
|
|
* tzinfo [O] Destination for the retrieved timezone info.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* RETURNS
|
2003-08-19 02:56:34 +02:00
|
|
|
* Success: STATUS_SUCCESS.
|
|
|
|
* Failure: An NTSTATUS error code indicating the problem.
|
2002-11-25 02:12:39 +01:00
|
|
|
*/
|
2015-05-08 16:34:10 +02:00
|
|
|
NTSTATUS WINAPI RtlQueryTimeZoneInformation(RTL_TIME_ZONE_INFORMATION *ret)
|
|
|
|
{
|
2021-03-30 13:23:13 +02:00
|
|
|
return NtQuerySystemInformation( SystemCurrentTimeZoneInformation, ret, sizeof(*ret), NULL );
|
2015-05-08 16:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlQueryDynamicTimeZoneInformation [NTDLL.@]
|
|
|
|
*
|
|
|
|
* Get information about the current timezone.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* tzinfo [O] Destination for the retrieved timezone info.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: STATUS_SUCCESS.
|
|
|
|
* Failure: An NTSTATUS error code indicating the problem.
|
|
|
|
*/
|
2020-06-25 15:28:26 +02:00
|
|
|
NTSTATUS WINAPI RtlQueryDynamicTimeZoneInformation(RTL_DYNAMIC_TIME_ZONE_INFORMATION *ret)
|
2002-11-25 02:12:39 +01:00
|
|
|
{
|
2020-06-25 15:28:26 +02:00
|
|
|
return NtQuerySystemInformation( SystemDynamicTimeZoneInformation, ret, sizeof(*ret), NULL );
|
2002-11-25 02:12:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlSetTimeZoneInformation [NTDLL.@]
|
|
|
|
*
|
2003-08-19 02:56:34 +02:00
|
|
|
* Set the current time zone information.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* PARAMS
|
2003-08-19 02:56:34 +02:00
|
|
|
* tzinfo [I] Timezone information to set.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* RETURNS
|
2003-08-19 02:56:34 +02:00
|
|
|
* Success: STATUS_SUCCESS.
|
|
|
|
* Failure: An NTSTATUS error code indicating the problem.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
|
|
|
*/
|
2005-06-20 20:37:17 +02:00
|
|
|
NTSTATUS WINAPI RtlSetTimeZoneInformation( const RTL_TIME_ZONE_INFORMATION *tzinfo )
|
2002-11-25 02:12:39 +01:00
|
|
|
{
|
|
|
|
return STATUS_PRIVILEGE_NOT_HELD;
|
|
|
|
}
|
|
|
|
|
2014-04-02 14:43:50 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlQueryUnbiasedInterruptTime [NTDLL.@]
|
|
|
|
*/
|
2019-12-16 18:44:07 +01:00
|
|
|
BOOL WINAPI RtlQueryUnbiasedInterruptTime(ULONGLONG *time)
|
2014-04-02 14:43:50 +02:00
|
|
|
{
|
2020-05-21 17:07:20 +02:00
|
|
|
ULONG high, low;
|
|
|
|
|
2019-12-16 18:44:07 +01:00
|
|
|
if (!time)
|
|
|
|
{
|
|
|
|
RtlSetLastWin32ErrorAndNtStatusFromNtStatus( STATUS_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-05-21 17:07:20 +02:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
high = user_shared_data->InterruptTime.High1Time;
|
|
|
|
low = user_shared_data->InterruptTime.LowPart;
|
|
|
|
}
|
|
|
|
while (high != user_shared_data->InterruptTime.High2Time);
|
|
|
|
/* FIXME: should probably subtract InterruptTimeBias */
|
|
|
|
*time = (ULONGLONG)high << 32 | low;
|
2019-12-16 18:44:07 +01:00
|
|
|
return TRUE;
|
2014-04-02 14:43:50 +02:00
|
|
|
}
|