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
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1999-03-09 18:47:51 +01:00
|
|
|
*/
|
|
|
|
|
2002-08-17 02:43:16 +02:00
|
|
|
#include "config.h"
|
2002-08-31 21:04:14 +02:00
|
|
|
#include "wine/port.h"
|
2002-08-17 02:43:16 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-11-27 21:14:45 +01:00
|
|
|
#include <stdlib.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>
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2003-01-07 21:36:20 +01:00
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2002-11-25 02:12:39 +01:00
|
|
|
#include "wine/unicode.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
|
|
|
|
2005-06-25 20:00:57 +02:00
|
|
|
static RTL_CRITICAL_SECTION TIME_GetBias_section;
|
|
|
|
static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
|
2004-02-27 01:43:20 +01:00
|
|
|
{
|
|
|
|
0, 0, &TIME_GetBias_section,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
2005-09-09 12:19:44 +02:00
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": TIME_GetBias_section") }
|
2004-02-27 01:43:20 +01:00
|
|
|
};
|
2005-06-25 20:00:57 +02:00
|
|
|
static RTL_CRITICAL_SECTION TIME_GetBias_section = { &critsect_debug, -1, 0, 0, 0, 0 };
|
2004-02-27 01:43:20 +01:00
|
|
|
|
2004-10-18 23:19:28 +02:00
|
|
|
/* TimeZone registry key values */
|
|
|
|
static const WCHAR TZInformationKeyW[] = { 'M','a','c','h','i','n','e','\\',
|
|
|
|
'S','Y','S','T','E','M','\\','C','u','r','r','e','n','t','C','o','n','t','r',
|
|
|
|
'o','l','S','e','t','\\','C','o','n','t','r','o','l','\\','T','i','m','e','z',
|
|
|
|
'o','n','e','I','n','f','o','r','m','a','t','i','o','n', 0};
|
|
|
|
static const WCHAR TZStandardStartW[] = {
|
|
|
|
'S','t','a','n','d','a','r','d','s','t','a','r','t', 0};
|
|
|
|
static const WCHAR TZDaylightStartW[] = {
|
|
|
|
'D','a','y','l','i','g','h','t','s','t','a','r','t', 0};
|
|
|
|
static const WCHAR TZDaylightBiasW[] = {
|
|
|
|
'D','a','y','l','i','g','h','t','B','i','a','s', 0};
|
|
|
|
static const WCHAR TZStandardBiasW[] = {
|
|
|
|
'S','t','a','n','d','a','r','d','B','i','a','s', 0};
|
|
|
|
static const WCHAR TZBiasW[] = {'B','i','a','s', 0};
|
|
|
|
static const WCHAR TZDaylightNameW[] = {
|
|
|
|
'D','a','y','l','i','g','h','t','N','a','m','e', 0};
|
|
|
|
static const WCHAR TZStandardNameW[] = {
|
|
|
|
'S','t','a','n','d','a','r','d','N','a','m','e', 0};
|
|
|
|
|
2004-02-27 01:43:20 +01:00
|
|
|
|
2002-11-25 02:12:39 +01:00
|
|
|
#define SETTIME_MAX_ADJUST 120
|
|
|
|
|
|
|
|
/* This structure is used to store strings that represent all of the time zones
|
|
|
|
* in the world. (This is used to help GetTimeZoneInformation)
|
|
|
|
*/
|
|
|
|
struct tagTZ_INFO
|
|
|
|
{
|
|
|
|
const char *psTZFromUnix;
|
|
|
|
WCHAR psTZWindows[32];
|
|
|
|
int bias;
|
|
|
|
int dst;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tagTZ_INFO TZ_INFO[] =
|
|
|
|
{
|
|
|
|
{"MHT",
|
|
|
|
{'D','a','t','e','l','i','n','e',' ','S','t','a','n','d','a','r','d',' ',
|
|
|
|
'T','i','m','e','\0'}, -720, 0},
|
|
|
|
{"SST",
|
|
|
|
{'S','a','m','o','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
|
|
|
|
'e','\0'}, 660, 0},
|
|
|
|
{"HST",
|
|
|
|
{'H','a','w','a','i','i','a','n',' ','S','t','a','n','d','a','r','d',' ',
|
|
|
|
'T','i','m','e','\0'}, 600, 0},
|
2005-11-08 11:57:50 +01:00
|
|
|
{"AKST",
|
|
|
|
{'A','l','a','s','k','a','n',' ','S','t','a','n','d','a','r','d',' ',
|
|
|
|
'T','i','m','e',0}, 540, 0 },
|
2002-11-25 02:12:39 +01:00
|
|
|
{"AKDT",
|
|
|
|
{'A','l','a','s','k','a','n',' ','S','t','a','n','d','a','r','d',' ','T',
|
|
|
|
'i','m','e','\0'}, 480, 1},
|
2004-11-02 06:22:01 +01:00
|
|
|
{"PST",
|
|
|
|
{'P','a','c','i','f','i','c',' ','S','t','a','n','d','a','r','d',' ','T',
|
|
|
|
'i','m','e','\0'}, 480, 0},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"PDT",
|
|
|
|
{'P','a','c','i','f','i','c',' ','S','t','a','n','d','a','r','d',' ','T',
|
|
|
|
'i','m','e','\0'}, 420, 1},
|
|
|
|
{"MST",
|
|
|
|
{'U','S',' ','M','o','u','n','t','a','i','n',' ','S','t','a','n','d','a',
|
|
|
|
'r','d',' ','T','i','m','e','\0'}, 420, 0},
|
|
|
|
{"MDT",
|
|
|
|
{'M','o','u','n','t','a','i','n',' ','S','t','a','n','d','a','r','d',' ',
|
|
|
|
'T','i','m','e','\0'}, 360, 1},
|
|
|
|
{"CST",
|
|
|
|
{'C','e','n','t','r','a','l',' ','A','m','e','r','i','c','a',' ','S','t',
|
|
|
|
'a','n','d','a','r','d',' ','T','i','m','e','\0'}, 360, 0},
|
|
|
|
{"CDT",
|
|
|
|
{'C','e','n','t','r','a','l',' ','S','t','a','n','d','a','r','d',' ','T',
|
|
|
|
'i','m','e','\0'}, 300, 1},
|
|
|
|
{"COT",
|
|
|
|
{'S','A',' ','P','a','c','i','f','i','c',' ','S','t','a','n','d','a','r',
|
|
|
|
'd',' ','T','i','m','e','\0'}, 300, 0},
|
2005-11-08 11:57:50 +01:00
|
|
|
{"PET",
|
|
|
|
{'S','A',' ','P','a','c','i','f','i','c',' ','S','t','a','n','d','a','r',
|
|
|
|
'd',' ','T','i','m','e',0}, 300, 0 },
|
2002-11-25 02:12:39 +01:00
|
|
|
{"EDT",
|
|
|
|
{'E','a','s','t','e','r','n',' ','S','t','a','n','d','a','r','d',' ','T',
|
|
|
|
'i','m','e','\0'}, 240, 1},
|
|
|
|
{"EST",
|
|
|
|
{'U','S',' ','E','a','s','t','e','r','n',' ','S','t','a','n','d','a','r',
|
|
|
|
'd',' ','T','i','m','e','\0'}, 300, 0},
|
2005-03-14 11:04:30 +01:00
|
|
|
{"ECT",
|
|
|
|
{'E','a','s','t','e','r','n',' ','C','e','n','t','r','a','l',' ','S','t','a','n','d','a','r',
|
|
|
|
'd',' ','T','i','m','e','\0'}, 300, 0},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"ADT",
|
|
|
|
{'A','t','l','a','n','t','i','c',' ','S','t','a','n','d','a','r','d',' ',
|
|
|
|
'T','i','m','e','\0'}, 180, 1},
|
|
|
|
{"VET",
|
|
|
|
{'S','A',' ','W','e','s','t','e','r','n',' ','S','t','a','n','d','a','r',
|
|
|
|
'd',' ','T','i','m','e','\0'}, 240, 0},
|
|
|
|
{"CLT",
|
|
|
|
{'P','a','c','i','f','i','c',' ','S','A',' ','S','t','a','n','d','a','r',
|
|
|
|
'd',' ','T','i','m','e','\0'}, 240, 0},
|
2005-11-08 11:57:50 +01:00
|
|
|
{"CLST",
|
|
|
|
{'P','a','c','i','f','i','c',' ','S','A',' ','S','t','a','n','d','a','r',
|
|
|
|
'd',' ','T','i','m','e',0}, 180, 1},
|
|
|
|
{"AST",
|
|
|
|
{'A','t','l','a','n','t','i','c',' ','S','t','a','n','d','a','r','d',' ',
|
|
|
|
'T','i','m','e',0}, 240, 0 },
|
2002-11-25 02:12:39 +01:00
|
|
|
{"NDT",
|
|
|
|
{'N','e','w','f','o','u','n','d','l','a','n','d',' ','S','t','a','n','d',
|
|
|
|
'a','r','d',' ','T','i','m','e','\0'}, 150, 1},
|
2005-11-08 11:57:50 +01:00
|
|
|
{"NST",
|
|
|
|
{'N','e','w','f','o','u','n','d','l','a','n','d',' ','S','t','a','n','d',
|
|
|
|
'a','r','d',' ','T','i','m','e',0}, 210, 0 },
|
2002-11-25 02:12:39 +01:00
|
|
|
{"BRT",
|
2005-02-14 12:03:05 +01:00
|
|
|
{'B','r','a','z','i','l','i','a','n',' ','S','t','a','n','d','a','r','d',
|
|
|
|
' ','T','i','m','e','\0'}, 180, 0},
|
2005-01-06 20:35:35 +01:00
|
|
|
{"BRST",
|
2005-02-14 12:03:05 +01:00
|
|
|
{'B','r','a','z','i','l','i','a','n',' ','S','u','m','m','e','r',
|
|
|
|
' ','T','i','m','e','\0'}, 120, 1},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"ART",
|
|
|
|
{'S','A',' ','E','a','s','t','e','r','n',' ','S','t','a','n','d','a','r',
|
|
|
|
'd',' ','T','i','m','e','\0'}, 180, 0},
|
|
|
|
{"WGST",
|
|
|
|
{'G','r','e','e','n','l','a','n','d',' ','S','t','a','n','d','a','r','d',
|
|
|
|
' ','T','i','m','e','\0'}, 120, 1},
|
|
|
|
{"GST",
|
|
|
|
{'M','i','d','-','A','t','l','a','n','t','i','c',' ','S','t','a','n','d',
|
|
|
|
'a','r','d',' ','T','i','m','e','\0'}, 120, 0},
|
2005-11-08 11:57:50 +01:00
|
|
|
{"AZOT",
|
|
|
|
{'A','z','o','r','e','s',' ','S','t','a','n','d','a','r','d',' ','T','i',
|
|
|
|
'm','e',0}, 60, 0},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"AZOST",
|
|
|
|
{'A','z','o','r','e','s',' ','S','t','a','n','d','a','r','d',' ','T','i',
|
|
|
|
'm','e','\0'}, 0, 1},
|
|
|
|
{"CVT",
|
|
|
|
{'C','a','p','e',' ','V','e','r','d','e',' ','S','t','a','n','d','a','r',
|
|
|
|
'd',' ','T','i','m','e','\0'}, 60, 0},
|
2005-05-07 16:50:56 +02:00
|
|
|
{"WEST",
|
|
|
|
{'W','e','s','t','e','r','n',' ','E','u','r','o','p','e','a','n',' ','S','u','m','m','e','r',' ','T','i','m','e','\0'}, -60, 1},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"WET",
|
|
|
|
{'G','r','e','e','n','w','i','c','h',' ','S','t','a','n','d','a','r','d',
|
|
|
|
' ','T','i','m','e','\0'}, 0, 0},
|
|
|
|
{"BST",
|
|
|
|
{'G','M','T',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'},
|
|
|
|
-60, 1},
|
2005-05-10 10:25:30 +02:00
|
|
|
{"IST",
|
|
|
|
{'I','r','i','s','h',' ','S','u','m','m','e','r',' ','T','i','m','e','\0'},
|
|
|
|
-60, 1},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"GMT",
|
|
|
|
{'G','M','T',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'},
|
|
|
|
0, 0},
|
2004-10-04 21:29:16 +02:00
|
|
|
{"UTC",
|
|
|
|
{'G','M','T',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'},
|
|
|
|
0, 0},
|
2004-11-02 06:28:01 +01:00
|
|
|
{"CET",
|
|
|
|
{'C','e','n','t','r','a','l',' ','E','u','r','o','p','e','a','n',' ',
|
|
|
|
'T','i','m','e','\0'}, -60, 0},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"CEST",
|
|
|
|
{'C','e','n','t','r','a','l',' ','E','u','r','o','p','e',' ','S','t','a',
|
|
|
|
'n','d','a','r','d',' ','T','i','m','e','\0'}, -120, 1},
|
2004-09-06 23:26:37 +02:00
|
|
|
{"MET",
|
|
|
|
{'C','e','n','t','r','a','l',' ','E','u','r','o','p','e',' ','S','t','a',
|
|
|
|
'n','d','a','r','d',' ','T','i','m','e','\0'}, -60, 0},
|
|
|
|
{"MEST",
|
|
|
|
{'C','e','n','t','r','a','l',' ','E','u','r','o','p','e',' ','D','a','y',
|
|
|
|
'l','i','g','h','t',' ','T','i','m','e','\0'}, -120, 1},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"WAT",
|
|
|
|
{'W','.',' ','C','e','n','t','r','a','l',' ','A','f','r','i','c','a',' ',
|
|
|
|
'S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, -60, 0},
|
|
|
|
{"EEST",
|
|
|
|
{'E','.',' ','E','u','r','o','p','e',' ','S','t','a','n','d','a','r','d',
|
|
|
|
' ','T','i','m','e','\0'}, -180, 1},
|
|
|
|
{"EET",
|
|
|
|
{'E','g','y','p','t',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
|
|
|
|
'e','\0'}, -120, 0},
|
|
|
|
{"CAT",
|
2004-12-06 12:39:34 +01:00
|
|
|
{'C','e','n','t','r','a','l',' ','A','f','r','i','c','a','n',' '
|
|
|
|
,'T','i','m','e','\0'}, -120, 0},
|
|
|
|
{"SAST",
|
2002-11-25 02:12:39 +01:00
|
|
|
{'S','o','u','t','h',' ','A','f','r','i','c','a',' ','S','t','a','n','d',
|
|
|
|
'a','r','d',' ','T','i','m','e','\0'}, -120, 0},
|
|
|
|
{"IST",
|
|
|
|
{'I','s','r','a','e','l',' ','S','t','a','n','d','a','r','d',' ','T','i',
|
|
|
|
'm','e','\0'}, -120, 0},
|
2004-11-02 20:25:05 +01:00
|
|
|
{"MSK",
|
|
|
|
{'R','u','s','s','i','a','n',' ','S','t','a','n','d','a','r','d',' ','T',
|
|
|
|
'i','m','e','\0'}, -180, 0},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"ADT",
|
|
|
|
{'A','r','a','b','i','c',' ','S','t','a','n','d','a','r','d',' ','T','i',
|
|
|
|
'm','e','\0'}, -240, 1},
|
|
|
|
{"AST",
|
|
|
|
{'A','r','a','b',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e',
|
|
|
|
'\0'}, -180, 0},
|
|
|
|
{"MSD",
|
|
|
|
{'R','u','s','s','i','a','n',' ','S','t','a','n','d','a','r','d',' ','T',
|
|
|
|
'i','m','e','\0'}, -240, 1},
|
|
|
|
{"EAT",
|
|
|
|
{'E','.',' ','A','f','r','i','c','a',' ','S','t','a','n','d','a','r','d',
|
|
|
|
' ','T','i','m','e','\0'}, -180, 0},
|
2005-11-08 11:57:50 +01:00
|
|
|
{"IRST",
|
|
|
|
{'I','r','a','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e',
|
|
|
|
0},-210, 0 },
|
2002-11-25 02:12:39 +01:00
|
|
|
{"IRST",
|
|
|
|
{'I','r','a','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e',
|
|
|
|
'\0'}, -270, 1},
|
|
|
|
{"GST",
|
|
|
|
{'A','r','a','b','i','a','n',' ','S','t','a','n','d','a','r','d',' ','T',
|
|
|
|
'i','m','e','\0'}, -240, 0},
|
2005-11-08 11:57:50 +01:00
|
|
|
{"AZT",
|
|
|
|
{'C','a','u','c','a','s','u','s',' ','S','t','a','n','d','a','r','d',' ',
|
|
|
|
'T','i','m','e',0}, -240, 0 },
|
2002-11-25 02:12:39 +01:00
|
|
|
{"AZST",
|
|
|
|
{'C','a','u','c','a','s','u','s',' ','S','t','a','n','d','a','r','d',' ',
|
|
|
|
'T','i','m','e','\0'}, -300, 1},
|
|
|
|
{"AFT",
|
|
|
|
{'A','f','g','h','a','n','i','s','t','a','n',' ','S','t','a','n','d','a',
|
|
|
|
'r','d',' ','T','i','m','e','\0'}, -270, 0},
|
2005-01-20 11:52:57 +01:00
|
|
|
{"SAMT",
|
|
|
|
{'S','a','m','a','r','a',' ','S','t','a','n','d','a','r','d',' ','T','i',
|
|
|
|
'm','e','\0'}, -270, 1},
|
2006-02-07 16:51:51 +01:00
|
|
|
{"YEKT",
|
|
|
|
{'U','r','a','l','s',' ','S','t','a','n','d','a','r','d',
|
|
|
|
' ','T','i','m','e',' ','(','W','i','n','t','e','r',')','\0'}, -300, 0},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"YEKST",
|
2006-02-07 16:51:51 +01:00
|
|
|
{'U','r','a','l','s',' ','D','a','y','l','i','g','h','t',
|
|
|
|
' ','T','i','m','e',' ','(','S','u','m','m','e','r',')','\0'}, -360, 1},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"PKT",
|
|
|
|
{'W','e','s','t',' ','A','s','i','a',' ','S','t','a','n','d','a','r','d',
|
|
|
|
' ','T','i','m','e','\0'}, -300, 0},
|
|
|
|
{"IST",
|
|
|
|
{'I','n','d','i','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
|
|
|
|
'e','\0'}, -330, 0},
|
|
|
|
{"NPT",
|
|
|
|
{'N','e','p','a','l',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
|
|
|
|
'e','\0'}, -345, 0},
|
|
|
|
{"ALMST",
|
|
|
|
{'N','.',' ','C','e','n','t','r','a','l',' ','A','s','i','a',' ','S','t',
|
|
|
|
'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -420, 1},
|
|
|
|
{"BDT",
|
|
|
|
{'C','e','n','t','r','a','l',' ','A','s','i','a',' ','S','t','a','n','d',
|
|
|
|
'a','r','d',' ','T','i','m','e','\0'}, -360, 0},
|
|
|
|
{"LKT",
|
|
|
|
{'S','r','i',' ','L','a','n','k','a',' ','S','t','a','n','d','a','r','d',
|
|
|
|
' ','T','i','m','e','\0'}, -360, 0},
|
|
|
|
{"MMT",
|
|
|
|
{'M','y','a','n','m','a','r',' ','S','t','a','n','d','a','r','d',' ','T',
|
|
|
|
'i','m','e','\0'}, -390, 0},
|
|
|
|
{"ICT",
|
|
|
|
{'S','E',' ','A','s','i','a',' ','S','t','a','n','d','a','r','d',' ','T',
|
|
|
|
'i','m','e','\0'}, -420, 0},
|
2005-11-08 11:57:50 +01:00
|
|
|
{"KRAT",
|
|
|
|
{'N','o','r','t','h',' ','A','s','i','a',' ','S','t','a','n','d','a','r',
|
|
|
|
'd',' ','T','i','m','e',0}, -420, 0},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"KRAST",
|
|
|
|
{'N','o','r','t','h',' ','A','s','i','a',' ','S','t','a','n','d','a','r',
|
|
|
|
'd',' ','T','i','m','e','\0'}, -480, 1},
|
2005-11-08 11:57:50 +01:00
|
|
|
{"IRKT",
|
|
|
|
{'N','o','r','t','h',' ','A','s','i','a',' ','E','a','s','t',' ','S','t',
|
|
|
|
'a','n','d','a','r','d',' ','T','i','m','e',0}, -480, 0},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"CST",
|
|
|
|
{'C','h','i','n','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
|
|
|
|
'e','\0'}, -480, 0},
|
|
|
|
{"IRKST",
|
|
|
|
{'N','o','r','t','h',' ','A','s','i','a',' ','E','a','s','t',' ','S','t',
|
|
|
|
'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -540, 1},
|
|
|
|
{"SGT",
|
|
|
|
{'M','a','l','a','y',' ','P','e','n','i','n','s','u','l','a',' ','S','t',
|
|
|
|
'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -480, 0},
|
|
|
|
{"WST",
|
|
|
|
{'W','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a','n','d',
|
|
|
|
'a','r','d',' ','T','i','m','e','\0'}, -480, 0},
|
|
|
|
{"JST",
|
|
|
|
{'T','o','k','y','o',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
|
|
|
|
'e','\0'}, -540, 0},
|
|
|
|
{"KST",
|
|
|
|
{'K','o','r','e','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
|
|
|
|
'e','\0'}, -540, 0},
|
|
|
|
{"YAKST",
|
|
|
|
{'Y','a','k','u','t','s','k',' ','S','t','a','n','d','a','r','d',' ','T',
|
|
|
|
'i','m','e','\0'}, -600, 1},
|
|
|
|
{"CST",
|
|
|
|
{'C','e','n','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a',
|
|
|
|
'n','d','a','r','d',' ','T','i','m','e','\0'}, -570, 0},
|
2005-11-03 14:21:23 +01:00
|
|
|
{"CST",
|
|
|
|
{'C','e','n','.',' ','A','u','s','t','r','a','l','i','a',' ','D','a','y',
|
|
|
|
'l','i','g','h','t',' ','T','i','m','e','\0'}, -630, 1},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"EST",
|
|
|
|
{'E','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a','n','d',
|
|
|
|
'a','r','d',' ','T','i','m','e','\0'}, -600, 0},
|
2005-01-27 12:11:54 +01:00
|
|
|
{"EST",
|
|
|
|
{'E','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a','n','d',
|
|
|
|
'a','r','d',' ','T','i','m','e','\0'}, -660, 1},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"GST",
|
|
|
|
{'W','e','s','t',' ','P','a','c','i','f','i','c',' ','S','t','a','n','d',
|
|
|
|
'a','r','d',' ','T','i','m','e','\0'}, -600, 0},
|
2005-11-08 11:57:50 +01:00
|
|
|
{"VLAT",
|
|
|
|
{'V','l','a','d','i','v','o','s','t','o','k',' ','S','t','a','n','d','a',
|
|
|
|
'r','d',' ','T','i','m','e',0}, -600, 0 },
|
|
|
|
{"ChST",
|
|
|
|
{'W','e','s','t',' ','P','a','c','i','f','i','c',' ','S','t','a','n','d',
|
|
|
|
'a','r','d',' ','T','i','m','e',0}, -600, 0},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"VLAST",
|
|
|
|
{'V','l','a','d','i','v','o','s','t','o','k',' ','S','t','a','n','d','a',
|
|
|
|
'r','d',' ','T','i','m','e','\0'}, -660, 1},
|
2005-11-08 11:57:50 +01:00
|
|
|
{"MAGT",
|
|
|
|
{'C','e','n','t','r','a','l',' ','P','a','c','i','f','i','c',' ','S','t',
|
|
|
|
'a','n','d','a','r','d',' ','T','i','m','e',0}, -660, 0},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"MAGST",
|
|
|
|
{'C','e','n','t','r','a','l',' ','P','a','c','i','f','i','c',' ','S','t',
|
|
|
|
'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -720, 1},
|
|
|
|
{"NZST",
|
|
|
|
{'N','e','w',' ','Z','e','a','l','a','n','d',' ','S','t','a','n','d','a',
|
|
|
|
'r','d',' ','T','i','m','e','\0'}, -720, 0},
|
2005-02-22 15:49:59 +01:00
|
|
|
{"NZDT",
|
|
|
|
{'N','e','w',' ','Z','e','a','l','a','n','d',' ','D','a','y','l','i','g',
|
|
|
|
'h','t',' ','T','i','m','e','\0'}, -780, 1},
|
2002-11-25 02:12:39 +01:00
|
|
|
{"FJT",
|
|
|
|
{'F','i','j','i',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e',
|
|
|
|
'\0'}, -720, 0},
|
|
|
|
{"TOT",
|
|
|
|
{'T','o','n','g','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m',
|
2004-11-21 16:34:28 +01:00
|
|
|
'e','\0'}, -780, 0},
|
2005-11-08 11:57:50 +01:00
|
|
|
{"NOVT",
|
|
|
|
{'N','.',' ','C','e','n','t','r','a','l',' ','A','s','i','a',' ','S','t',
|
|
|
|
'a','n','d','a','r','d',' ','T','i','m','e',0 }, -360, 0},
|
2004-11-21 16:34:28 +01:00
|
|
|
{"NOVT",
|
|
|
|
{'N','o','v','o','s','i','b','i','r','s','k',' ','S','t','a','n','d','a',
|
2005-03-22 19:17:31 +01:00
|
|
|
'r','d',' ','T','i','m','e','\0'}, -360, 1},
|
|
|
|
{"ANAT",
|
|
|
|
{'A','n','a','d','y','r',' ','S','t','a','n','d','a','r','d',' ','T','i',
|
2005-05-04 11:45:48 +02:00
|
|
|
'm','e','\0'}, -720, 1},
|
|
|
|
{"HKT",
|
|
|
|
{'H','o','n','g',' ','K','o','n','g',' ','S','t','a','n','d','a','r','d',
|
2005-05-12 11:54:39 +02:00
|
|
|
' ','T','i','m','e','\0'}, -480, 0},
|
|
|
|
{"UYT",
|
2005-09-26 11:55:59 +02:00
|
|
|
{'U','r','u','g','u','a','y','a','n',' ','T','i','m','e','\0'}, 180, 0},
|
|
|
|
{"MYT",
|
|
|
|
{'M','a','l','a','y','s','i','a','n',' ','T','i','m','e','\0'}, -480, 0},
|
2005-10-10 20:03:56 +02:00
|
|
|
{"PHT",
|
|
|
|
{'P','h','i','l','i','p','p','i','n','e',' ','T','i','m','e','\0'}, -480, 0},
|
2005-09-26 11:55:59 +02:00
|
|
|
{"NOVST",
|
|
|
|
{'N','o','v','o','s','i','b','i','r','s','k',' ','S','u','m','m','e','r',
|
|
|
|
' ','T','i','m','e','\0'}, -480, 1}
|
2002-11-25 02:12:39 +01:00
|
|
|
};
|
|
|
|
|
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 EPOCHYEAR 1601
|
|
|
|
#define DAYSPERNORMALYEAR 365
|
|
|
|
#define DAYSPERLEAPYEAR 366
|
|
|
|
#define MONSPERYEAR 12
|
2004-02-24 02:01:27 +01:00
|
|
|
#define DAYSPERQUADRICENTENNIUM (365 * 400 + 97)
|
|
|
|
#define DAYSPERNORMALCENTURY (365 * 100 + 24)
|
|
|
|
#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)
|
2004-09-08 01:01:34 +02:00
|
|
|
/* max ticks that can be represented as Unix time */
|
|
|
|
#define TICKS_1601_TO_UNIX_MAX ((SECS_1601_TO_1970 + INT_MAX) * 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 }
|
|
|
|
};
|
|
|
|
|
1999-05-08 14:50:36 +02:00
|
|
|
static inline int IsLeapYear(int Year)
|
1999-03-09 18:47:51 +01:00
|
|
|
{
|
|
|
|
return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2003-03-31 03:37:04 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* NTDLL_get_server_timeout
|
|
|
|
*
|
|
|
|
* Convert a NTDLL timeout into a timeval struct to send to the server.
|
|
|
|
*/
|
2003-04-03 00:48:59 +02:00
|
|
|
void NTDLL_get_server_timeout( abs_time_t *when, const LARGE_INTEGER *timeout )
|
2003-03-31 03:37:04 +02:00
|
|
|
{
|
|
|
|
UINT remainder;
|
|
|
|
|
|
|
|
if (!timeout) /* infinite timeout */
|
|
|
|
{
|
2003-04-03 00:48:59 +02:00
|
|
|
when->sec = when->usec = 0;
|
2003-03-31 03:37:04 +02:00
|
|
|
}
|
|
|
|
else if (timeout->QuadPart <= 0) /* relative timeout */
|
|
|
|
{
|
2003-04-03 00:48:59 +02:00
|
|
|
struct timeval tv;
|
2004-09-08 01:01:34 +02:00
|
|
|
|
|
|
|
if (-timeout->QuadPart > (LONGLONG)INT_MAX * TICKSPERSEC)
|
|
|
|
when->sec = when->usec = INT_MAX;
|
|
|
|
else
|
2003-03-31 03:37:04 +02:00
|
|
|
{
|
2004-09-08 01:01:34 +02:00
|
|
|
ULONG sec = RtlEnlargedUnsignedDivide( -timeout->QuadPart, TICKSPERSEC, &remainder );
|
|
|
|
gettimeofday( &tv, 0 );
|
|
|
|
when->sec = tv.tv_sec + sec;
|
|
|
|
if ((when->usec = tv.tv_usec + (remainder / 10)) >= 1000000)
|
|
|
|
{
|
|
|
|
when->usec -= 1000000;
|
|
|
|
when->sec++;
|
|
|
|
}
|
|
|
|
if (when->sec < tv.tv_sec) /* overflow */
|
|
|
|
when->sec = when->usec = INT_MAX;
|
2003-03-31 03:37:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* absolute time */
|
|
|
|
{
|
2004-09-08 01:01:34 +02:00
|
|
|
if (timeout->QuadPart < TICKS_1601_TO_1970)
|
|
|
|
when->sec = when->usec = 0;
|
|
|
|
else if (timeout->QuadPart > TICKS_1601_TO_UNIX_MAX)
|
|
|
|
when->sec = when->usec = INT_MAX;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
when->sec = RtlEnlargedUnsignedDivide( timeout->QuadPart - TICKS_1601_TO_1970,
|
|
|
|
TICKSPERSEC, &remainder );
|
|
|
|
when->usec = remainder / 10;
|
|
|
|
}
|
2003-03-31 03:37:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-13 22:10:58 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* NTDLL_from_server_timeout
|
|
|
|
*
|
|
|
|
* Convert a timeval struct from the server into an NTDLL timeout.
|
|
|
|
*/
|
|
|
|
void NTDLL_from_server_timeout( LARGE_INTEGER *timeout, const abs_time_t *when )
|
|
|
|
{
|
|
|
|
timeout->QuadPart = when->sec * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
|
|
|
|
timeout->QuadPart += when->usec * 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
/***********************************************************************
|
|
|
|
* TIME_GetBias [internal]
|
|
|
|
*
|
|
|
|
* Helper function calculates delta local time from UTC.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* utc [I] The current utc time.
|
|
|
|
* pdaylight [I] Local daylight.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The bias for the current timezone.
|
|
|
|
*/
|
|
|
|
static int TIME_GetBias(time_t utc, int *pdaylight)
|
|
|
|
{
|
2004-02-27 01:43:20 +01:00
|
|
|
struct tm *ptm;
|
|
|
|
static time_t last_utc;
|
|
|
|
static int last_bias;
|
2004-03-01 22:23:18 +01:00
|
|
|
static int last_daylight;
|
2004-02-27 01:43:20 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &TIME_GetBias_section );
|
|
|
|
if(utc == last_utc)
|
2004-03-01 22:23:18 +01:00
|
|
|
{
|
|
|
|
*pdaylight = last_daylight;
|
2004-02-27 01:43:20 +01:00
|
|
|
ret = last_bias;
|
2004-03-01 22:23:18 +01:00
|
|
|
} else
|
2004-02-27 01:43:20 +01:00
|
|
|
{
|
|
|
|
ptm = localtime(&utc);
|
2004-03-01 22:23:18 +01:00
|
|
|
*pdaylight = last_daylight =
|
|
|
|
ptm->tm_isdst; /* daylight for local timezone */
|
2004-02-27 01:43:20 +01:00
|
|
|
ptm = gmtime(&utc);
|
|
|
|
ptm->tm_isdst = *pdaylight; /* use local daylight, not that of Greenwich */
|
|
|
|
last_utc = utc;
|
|
|
|
ret = last_bias = (int)(utc-mktime(ptm));
|
|
|
|
}
|
|
|
|
RtlLeaveCriticalSection( &TIME_GetBias_section );
|
|
|
|
return ret;
|
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)
|
|
|
|
{
|
2004-02-26 06:26:34 +01:00
|
|
|
time_t gmt;
|
|
|
|
int bias, daylight;
|
2002-12-11 01:19:56 +01:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", LocalTime, SystemTime);
|
|
|
|
|
2004-02-26 06:26:34 +01:00
|
|
|
gmt = time(NULL);
|
|
|
|
bias = TIME_GetBias(gmt, &daylight);
|
|
|
|
|
2005-02-08 13:13:36 +01:00
|
|
|
SystemTime->QuadPart = LocalTime->QuadPart - bias * (LONGLONG)TICKSPERSEC;
|
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
|
|
|
{
|
2004-02-26 06:26:34 +01:00
|
|
|
time_t gmt;
|
|
|
|
int bias, daylight;
|
2002-12-11 01:19:56 +01:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", SystemTime, LocalTime);
|
1999-03-09 18:47:51 +01:00
|
|
|
|
2004-02-26 06:26:34 +01:00
|
|
|
gmt = time(NULL);
|
|
|
|
bias = TIME_GetBias(gmt, &daylight);
|
|
|
|
|
2005-02-08 13:13:36 +01:00
|
|
|
LocalTime->QuadPart = SystemTime->QuadPart + bias * (LONGLONG)TICKSPERSEC;
|
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
|
|
|
{
|
2004-01-23 02:51:33 +01:00
|
|
|
ULONGLONG tmp = ((ULONGLONG)Time->u.HighPart << 32) | Time->u.LowPart;
|
2005-02-08 13:13:36 +01:00
|
|
|
tmp = RtlLargeIntegerDivide( tmp, TICKSPERSEC, NULL );
|
2000-10-01 03:40:42 +02:00
|
|
|
tmp -= SECS_1601_TO_1970;
|
|
|
|
if (tmp > 0xffffffff) return FALSE;
|
2003-08-19 02:56:34 +02:00
|
|
|
*Seconds = (DWORD)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
|
|
|
{
|
2004-01-23 02:51:33 +01:00
|
|
|
ULONGLONG tmp = ((ULONGLONG)Time->u.HighPart << 32) | Time->u.LowPart;
|
2005-02-08 13:13:36 +01:00
|
|
|
tmp = RtlLargeIntegerDivide( tmp, TICKSPERSEC, NULL );
|
2003-03-31 03:37:04 +02:00
|
|
|
tmp -= SECS_1601_TO_1980;
|
2000-10-01 03:40:42 +02:00
|
|
|
if (tmp > 0xffffffff) return FALSE;
|
2003-08-19 02:56:34 +02:00
|
|
|
*Seconds = (DWORD)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
|
|
|
{
|
2003-08-19 02:56:34 +02:00
|
|
|
ULONGLONG secs = Seconds * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
|
2004-01-23 02:51:33 +01:00
|
|
|
Time->u.LowPart = (DWORD)secs;
|
|
|
|
Time->u.HighPart = (DWORD)(secs >> 32);
|
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
|
|
|
{
|
2003-08-19 02:56:34 +02:00
|
|
|
ULONGLONG secs = Seconds * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1980;
|
2004-01-23 02:51:33 +01:00
|
|
|
Time->u.LowPart = (DWORD)secs;
|
|
|
|
Time->u.HighPart = (DWORD)(secs >> 32);
|
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
|
|
|
|
|
|
|
time = RtlExtendedLargeIntegerDivide( Time->QuadPart, TICKSPERSEC, &rem );
|
|
|
|
TimeFields->Milliseconds = rem / TICKSPERMSEC;
|
|
|
|
|
|
|
|
/* time is now in seconds */
|
|
|
|
TimeFields->Year = 0;
|
|
|
|
TimeFields->Month = 0;
|
|
|
|
TimeFields->Day = RtlExtendedLargeIntegerDivide( time, SECSPERDAY, &rem );
|
|
|
|
|
|
|
|
/* rem is now the remaining seconds in the last day */
|
|
|
|
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
|
|
|
|
|
|
|
/***********************************************************************
|
2002-11-25 02:12:39 +01:00
|
|
|
* NtQuerySystemTime [NTDLL.@]
|
|
|
|
* ZwQuerySystemTime [NTDLL.@]
|
|
|
|
*
|
2003-08-19 02:56:34 +02:00
|
|
|
* Get the current system 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
|
|
|
* Time [O] Destination for the current system 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.
|
2000-10-01 03:40:42 +02:00
|
|
|
*/
|
2003-08-19 02:56:34 +02:00
|
|
|
NTSTATUS WINAPI NtQuerySystemTime( PLARGE_INTEGER Time )
|
2000-10-01 03:40:42 +02:00
|
|
|
{
|
|
|
|
struct timeval now;
|
|
|
|
|
|
|
|
gettimeofday( &now, 0 );
|
2003-08-19 02:56:34 +02:00
|
|
|
Time->QuadPart = now.tv_sec * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970;
|
|
|
|
Time->QuadPart += now.tv_usec * 10;
|
2002-09-13 00:07:02 +02:00
|
|
|
return STATUS_SUCCESS;
|
2000-10-01 03:40:42 +02:00
|
|
|
}
|
2002-11-25 02:12:39 +01:00
|
|
|
|
2005-07-14 12:32:46 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* NtQueryPerformanceCounter [NTDLL.@]
|
|
|
|
*
|
|
|
|
* Note: Windows uses a timer clocked at a multiple of 1193182 Hz. There is a
|
|
|
|
* good number of applications that crash when the returned frequency is either
|
|
|
|
* lower or higher then what Windows gives. Also too high counter values are
|
|
|
|
* reported to give problems.
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtQueryPerformanceCounter( PLARGE_INTEGER Counter, PLARGE_INTEGER Frequency )
|
|
|
|
{
|
|
|
|
struct timeval now;
|
|
|
|
|
|
|
|
if (!Counter) return STATUS_ACCESS_VIOLATION;
|
|
|
|
gettimeofday( &now, 0 );
|
|
|
|
/* convert a counter that increments at a rate of 1 MHz
|
|
|
|
* to one of 1.193182 MHz, with some care for arithmetic
|
|
|
|
* overflow ( will not overflow for 5000 years ) and
|
|
|
|
* good accuracy ( 105/88 = 1.19318182) */
|
|
|
|
Counter->QuadPart = (((now.tv_sec - server_start_time) * (ULONGLONG)1000000 + now.tv_usec) * 105) / 88;
|
|
|
|
if (Frequency) Frequency->QuadPart = 1193182;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2002-11-25 02:12:39 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* TIME_GetTZAsStr [internal]
|
|
|
|
*
|
|
|
|
* Helper function that returns the given timezone as a string.
|
|
|
|
*
|
2003-03-18 19:35:48 +01:00
|
|
|
* PARAMS
|
|
|
|
* utc [I] The current utc time.
|
|
|
|
* bias [I] The bias of the current timezone.
|
|
|
|
* dst [I] ??
|
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
|
|
|
* Timezone name.
|
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
* This could be done with a hash table instead of merely iterating through a
|
|
|
|
* table, however with the small amount of entries (60 or so) I didn't think
|
|
|
|
* it was worth it.
|
|
|
|
*/
|
|
|
|
static const WCHAR* TIME_GetTZAsStr (time_t utc, int bias, int dst)
|
|
|
|
{
|
|
|
|
char psTZName[7];
|
|
|
|
struct tm *ptm = localtime(&utc);
|
2004-08-14 01:53:44 +02:00
|
|
|
unsigned int i;
|
2002-11-25 02:12:39 +01:00
|
|
|
|
|
|
|
if (!strftime (psTZName, 7, "%Z", ptm))
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
for (i=0; i<(sizeof(TZ_INFO) / sizeof(struct tagTZ_INFO)); i++)
|
|
|
|
{
|
|
|
|
if ( strcmp(TZ_INFO[i].psTZFromUnix, psTZName) == 0 &&
|
|
|
|
TZ_INFO[i].bias == bias &&
|
|
|
|
TZ_INFO[i].dst == dst
|
|
|
|
)
|
|
|
|
return TZ_INFO[i].psTZWindows;
|
|
|
|
}
|
2005-02-14 12:03:05 +01:00
|
|
|
FIXME("Can't match system time zone name \"%s\", bias=%d and dst=%d "
|
|
|
|
"to an entry in TZ_INFO. Please add appropriate entry to "
|
|
|
|
"TZ_INFO and submit as patch to wine-patches\n",psTZName,bias,dst);
|
2003-08-19 02:56:34 +02:00
|
|
|
return NULL;
|
2002-11-25 02:12:39 +01:00
|
|
|
}
|
|
|
|
|
2004-10-18 23:19:28 +02:00
|
|
|
/*** TIME_GetTimeZoneInfoFromReg: helper for GetTimeZoneInformation ***/
|
|
|
|
|
|
|
|
|
2005-06-20 20:37:17 +02:00
|
|
|
static int TIME_GetTimeZoneInfoFromReg(RTL_TIME_ZONE_INFORMATION *tzinfo)
|
2004-10-18 23:19:28 +02:00
|
|
|
{
|
|
|
|
BYTE buf[90];
|
|
|
|
KEY_VALUE_PARTIAL_INFORMATION * KpInfo =
|
|
|
|
(KEY_VALUE_PARTIAL_INFORMATION *) buf;
|
2005-06-17 15:58:33 +02:00
|
|
|
HANDLE hkey;
|
2004-10-18 23:19:28 +02:00
|
|
|
DWORD size;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.Attributes = 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
RtlInitUnicodeString( &nameW, TZInformationKeyW);
|
|
|
|
if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) {
|
|
|
|
|
|
|
|
#define GTZIFR_N( valkey, tofield) \
|
|
|
|
RtlInitUnicodeString( &nameW, valkey );\
|
|
|
|
if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, KpInfo,\
|
|
|
|
sizeof(buf), &size )) { \
|
|
|
|
if( size >= (sizeof((tofield)) + \
|
2005-09-21 11:46:28 +02:00
|
|
|
offsetof(KEY_VALUE_PARTIAL_INFORMATION,Data))) { \
|
2004-10-18 23:19:28 +02:00
|
|
|
memcpy(&(tofield), \
|
|
|
|
KpInfo->Data, sizeof(tofield)); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define GTZIFR_S( valkey, tofield) \
|
|
|
|
RtlInitUnicodeString( &nameW, valkey );\
|
|
|
|
if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, KpInfo,\
|
|
|
|
sizeof(buf), &size )) { \
|
2005-04-21 19:18:50 +02:00
|
|
|
size_t len = (strlenW( (WCHAR*)KpInfo->Data ) + 1) * sizeof(WCHAR); \
|
|
|
|
if (len > sizeof(tofield)) len = sizeof(tofield); \
|
|
|
|
memcpy( tofield, KpInfo->Data, len ); \
|
|
|
|
tofield[(len/sizeof(WCHAR))-1] = 0; \
|
2004-10-18 23:19:28 +02:00
|
|
|
}
|
2005-04-21 19:18:50 +02:00
|
|
|
|
2004-10-18 23:19:28 +02:00
|
|
|
GTZIFR_N( TZStandardStartW, tzinfo->StandardDate)
|
|
|
|
GTZIFR_N( TZDaylightStartW, tzinfo->DaylightDate)
|
|
|
|
GTZIFR_N( TZBiasW, tzinfo->Bias)
|
|
|
|
GTZIFR_N( TZStandardBiasW, tzinfo->StandardBias)
|
|
|
|
GTZIFR_N( TZDaylightBiasW, tzinfo->DaylightBias)
|
|
|
|
GTZIFR_S( TZStandardNameW, tzinfo->StandardName)
|
|
|
|
GTZIFR_S( TZDaylightNameW, tzinfo->DaylightName)
|
|
|
|
|
|
|
|
#undef GTZIFR_N
|
|
|
|
#undef GTZIFR_S
|
|
|
|
NtClose( hkey );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2005-06-20 20:37:17 +02:00
|
|
|
NTSTATUS WINAPI RtlQueryTimeZoneInformation(RTL_TIME_ZONE_INFORMATION *tzinfo)
|
2002-11-25 02:12:39 +01:00
|
|
|
{
|
|
|
|
time_t gmt;
|
|
|
|
int bias, daylight;
|
|
|
|
const WCHAR *psTZ;
|
|
|
|
|
2005-06-20 20:37:17 +02:00
|
|
|
memset(tzinfo, 0, sizeof(RTL_TIME_ZONE_INFORMATION));
|
2002-11-25 02:12:39 +01:00
|
|
|
|
2004-10-18 23:19:28 +02:00
|
|
|
if( !TIME_GetTimeZoneInfoFromReg(tzinfo)) {
|
|
|
|
|
|
|
|
gmt = time(NULL);
|
|
|
|
bias = TIME_GetBias(gmt, &daylight);
|
2002-11-25 02:12:39 +01:00
|
|
|
|
2004-10-18 23:19:28 +02:00
|
|
|
tzinfo->Bias = -bias / 60;
|
|
|
|
tzinfo->StandardBias = 0;
|
|
|
|
tzinfo->DaylightBias = -60;
|
|
|
|
tzinfo->StandardName[0]='\0';
|
|
|
|
tzinfo->DaylightName[0]='\0';
|
|
|
|
psTZ = TIME_GetTZAsStr (gmt, (-bias/60), daylight);
|
|
|
|
if (psTZ) strcpyW( tzinfo->StandardName, psTZ );
|
|
|
|
}
|
2002-11-25 02:12:39 +01:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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
|
|
|
*
|
2003-08-19 02:56:34 +02:00
|
|
|
* BUGS
|
2002-11-25 02:12:39 +01:00
|
|
|
* Uses the obsolete unix timezone structure and tz_dsttime member.
|
|
|
|
*/
|
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
|
|
|
{
|
2004-03-11 01:46:09 +01:00
|
|
|
#ifdef HAVE_SETTIMEOFDAY
|
2002-11-25 02:12:39 +01:00
|
|
|
struct timezone tz;
|
|
|
|
|
|
|
|
tz.tz_minuteswest = tzinfo->Bias;
|
|
|
|
#ifdef DST_NONE
|
|
|
|
tz.tz_dsttime = DST_NONE;
|
|
|
|
#else
|
|
|
|
tz.tz_dsttime = 0;
|
|
|
|
#endif
|
|
|
|
if(!settimeofday(NULL, &tz))
|
|
|
|
return STATUS_SUCCESS;
|
2004-03-11 01:46:09 +01:00
|
|
|
#endif
|
2002-11-25 02:12:39 +01:00
|
|
|
return STATUS_PRIVILEGE_NOT_HELD;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* NtSetSystemTime [NTDLL.@]
|
|
|
|
* ZwSetSystemTime [NTDLL.@]
|
|
|
|
*
|
2003-08-19 02:56:34 +02:00
|
|
|
* Set the system time.
|
2002-11-25 02:12:39 +01:00
|
|
|
*
|
2003-08-19 02:56:34 +02:00
|
|
|
* PARAMS
|
|
|
|
* NewTime [I] The time to set.
|
|
|
|
* OldTime [O] Optional destination for the previous system 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.
|
2002-11-25 02:12:39 +01:00
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtSetSystemTime(const LARGE_INTEGER *NewTime, LARGE_INTEGER *OldTime)
|
|
|
|
{
|
|
|
|
TIME_FIELDS tf;
|
|
|
|
struct timeval tv;
|
|
|
|
struct timezone tz;
|
|
|
|
struct tm t;
|
|
|
|
time_t sec, oldsec;
|
|
|
|
int dst, bias;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* Return the old time if necessary */
|
|
|
|
if(OldTime)
|
|
|
|
NtQuerySystemTime(OldTime);
|
|
|
|
|
|
|
|
RtlTimeToTimeFields(NewTime, &tf);
|
|
|
|
|
|
|
|
/* call gettimeofday to get the current timezone */
|
|
|
|
gettimeofday(&tv, &tz);
|
|
|
|
oldsec = tv.tv_sec;
|
|
|
|
/* get delta local time from utc */
|
|
|
|
bias = TIME_GetBias(oldsec, &dst);
|
|
|
|
|
|
|
|
/* get the number of seconds */
|
|
|
|
t.tm_sec = tf.Second;
|
|
|
|
t.tm_min = tf.Minute;
|
|
|
|
t.tm_hour = tf.Hour;
|
|
|
|
t.tm_mday = tf.Day;
|
|
|
|
t.tm_mon = tf.Month - 1;
|
|
|
|
t.tm_year = tf.Year - 1900;
|
|
|
|
t.tm_isdst = dst;
|
|
|
|
sec = mktime (&t);
|
|
|
|
/* correct for timezone and daylight */
|
|
|
|
sec += bias;
|
|
|
|
|
|
|
|
/* set the new time */
|
|
|
|
tv.tv_sec = sec;
|
|
|
|
tv.tv_usec = tf.Milliseconds * 1000;
|
|
|
|
|
|
|
|
/* error and sanity check*/
|
|
|
|
if(sec == (time_t)-1 || abs((int)(sec-oldsec)) > SETTIME_MAX_ADJUST) {
|
|
|
|
err = 2;
|
|
|
|
} else {
|
|
|
|
#ifdef HAVE_SETTIMEOFDAY
|
|
|
|
err = settimeofday(&tv, NULL); /* 0 is OK, -1 is error */
|
|
|
|
if(err == 0)
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
#else
|
|
|
|
err = 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("Cannot set time to %d/%d/%d %d:%d:%d Time adjustment %ld %s\n",
|
|
|
|
tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second,
|
2003-10-02 06:29:30 +02:00
|
|
|
(long)(sec-oldsec),
|
|
|
|
err == -1 ? "No Permission"
|
|
|
|
: sec == (time_t)-1 ? "" : "is too large." );
|
2002-11-25 02:12:39 +01:00
|
|
|
|
|
|
|
if(err == 2)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
else if(err == -1)
|
|
|
|
return STATUS_PRIVILEGE_NOT_HELD;
|
|
|
|
else
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|