Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 1 | /* |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 2 | * Nt time functions. |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 3 | * |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 4 | * RtlTimeToTimeFields, RtlTimeFieldsToTime and defines are taken from ReactOS and |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 5 | * adapted to wine with special permissions of the author. This code is |
| 6 | * Copyright 2002 Rex Jolliff (rex@lvcablemodem.com) |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 7 | * |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 8 | * Copyright 1999 Juergen Schmied |
| 9 | * |
| 10 | * This library is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Lesser General Public |
| 12 | * License as published by the Free Software Foundation; either |
| 13 | * version 2.1 of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This library is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * Lesser General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public |
| 21 | * License along with this library; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 23 | */ |
| 24 | |
Patrik Stridvall | d016f81 | 2002-08-17 00:43:16 +0000 | [diff] [blame] | 25 | #include "config.h" |
Patrik Stridvall | 51e6c0c | 2002-08-31 19:04:14 +0000 | [diff] [blame] | 26 | #include "wine/port.h" |
Patrik Stridvall | d016f81 | 2002-08-17 00:43:16 +0000 | [diff] [blame] | 27 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 28 | #include <stdarg.h> |
Vincent Béron | ea966aa | 2002-11-27 20:14:45 +0000 | [diff] [blame] | 29 | #include <stdlib.h> |
David Luyer | 26cd7a1 | 1999-03-25 15:57:35 +0000 | [diff] [blame] | 30 | #include <string.h> |
Alexandre Julliard | 25b23a0 | 2004-09-07 23:01:34 +0000 | [diff] [blame] | 31 | #include <limits.h> |
Alexandre Julliard | d76f9f9 | 2000-10-01 01:40:42 +0000 | [diff] [blame] | 32 | #include <time.h> |
Patrik Stridvall | d016f81 | 2002-08-17 00:43:16 +0000 | [diff] [blame] | 33 | #ifdef HAVE_SYS_TIME_H |
| 34 | # include <sys/time.h> |
| 35 | #endif |
| 36 | #ifdef HAVE_UNISTD_H |
| 37 | # include <unistd.h> |
| 38 | #endif |
Dimitrie O. Paun | 297f3d8 | 2003-01-07 20:36:20 +0000 | [diff] [blame] | 39 | |
| 40 | #define NONAMELESSUNION |
| 41 | #define NONAMELESSSTRUCT |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 42 | #include "windef.h" |
| 43 | #include "winbase.h" |
| 44 | #include "winreg.h" |
Patrik Stridvall | 9c1de6d | 2002-09-12 22:07:02 +0000 | [diff] [blame] | 45 | #include "winternl.h" |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 46 | #include "wine/unicode.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 47 | #include "wine/debug.h" |
Alexandre Julliard | 462172a | 2003-04-02 22:48:59 +0000 | [diff] [blame] | 48 | #include "ntdll_misc.h" |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 49 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 50 | WINE_DEFAULT_DEBUG_CHANNEL(ntdll); |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 51 | |
Huw Davies | 67e2d6c | 2004-02-27 00:43:20 +0000 | [diff] [blame] | 52 | static CRITICAL_SECTION TIME_GetBias_section; |
| 53 | static CRITICAL_SECTION_DEBUG critsect_debug = |
| 54 | { |
| 55 | 0, 0, &TIME_GetBias_section, |
| 56 | { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, |
| 57 | 0, 0, { 0, (DWORD)(__FILE__ ": TIME_GetBias_section") } |
| 58 | }; |
| 59 | static CRITICAL_SECTION TIME_GetBias_section = { &critsect_debug, -1, 0, 0, 0, 0 }; |
| 60 | |
Rein Klazes | c5c93d1 | 2004-10-18 21:19:28 +0000 | [diff] [blame^] | 61 | /* TimeZone registry key values */ |
| 62 | static const WCHAR TZInformationKeyW[] = { 'M','a','c','h','i','n','e','\\', |
| 63 | 'S','Y','S','T','E','M','\\','C','u','r','r','e','n','t','C','o','n','t','r', |
| 64 | 'o','l','S','e','t','\\','C','o','n','t','r','o','l','\\','T','i','m','e','z', |
| 65 | 'o','n','e','I','n','f','o','r','m','a','t','i','o','n', 0}; |
| 66 | static const WCHAR TZStandardStartW[] = { |
| 67 | 'S','t','a','n','d','a','r','d','s','t','a','r','t', 0}; |
| 68 | static const WCHAR TZDaylightStartW[] = { |
| 69 | 'D','a','y','l','i','g','h','t','s','t','a','r','t', 0}; |
| 70 | static const WCHAR TZDaylightBiasW[] = { |
| 71 | 'D','a','y','l','i','g','h','t','B','i','a','s', 0}; |
| 72 | static const WCHAR TZStandardBiasW[] = { |
| 73 | 'S','t','a','n','d','a','r','d','B','i','a','s', 0}; |
| 74 | static const WCHAR TZBiasW[] = {'B','i','a','s', 0}; |
| 75 | static const WCHAR TZDaylightNameW[] = { |
| 76 | 'D','a','y','l','i','g','h','t','N','a','m','e', 0}; |
| 77 | static const WCHAR TZStandardNameW[] = { |
| 78 | 'S','t','a','n','d','a','r','d','N','a','m','e', 0}; |
| 79 | |
Huw Davies | 67e2d6c | 2004-02-27 00:43:20 +0000 | [diff] [blame] | 80 | |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 81 | #define SETTIME_MAX_ADJUST 120 |
| 82 | |
| 83 | /* This structure is used to store strings that represent all of the time zones |
| 84 | * in the world. (This is used to help GetTimeZoneInformation) |
| 85 | */ |
| 86 | struct tagTZ_INFO |
| 87 | { |
| 88 | const char *psTZFromUnix; |
| 89 | WCHAR psTZWindows[32]; |
| 90 | int bias; |
| 91 | int dst; |
| 92 | }; |
| 93 | |
| 94 | static const struct tagTZ_INFO TZ_INFO[] = |
| 95 | { |
| 96 | {"MHT", |
| 97 | {'D','a','t','e','l','i','n','e',' ','S','t','a','n','d','a','r','d',' ', |
| 98 | 'T','i','m','e','\0'}, -720, 0}, |
| 99 | {"SST", |
| 100 | {'S','a','m','o','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m', |
| 101 | 'e','\0'}, 660, 0}, |
| 102 | {"HST", |
| 103 | {'H','a','w','a','i','i','a','n',' ','S','t','a','n','d','a','r','d',' ', |
| 104 | 'T','i','m','e','\0'}, 600, 0}, |
| 105 | {"AKDT", |
| 106 | {'A','l','a','s','k','a','n',' ','S','t','a','n','d','a','r','d',' ','T', |
| 107 | 'i','m','e','\0'}, 480, 1}, |
| 108 | {"PDT", |
| 109 | {'P','a','c','i','f','i','c',' ','S','t','a','n','d','a','r','d',' ','T', |
| 110 | 'i','m','e','\0'}, 420, 1}, |
| 111 | {"MST", |
| 112 | {'U','S',' ','M','o','u','n','t','a','i','n',' ','S','t','a','n','d','a', |
| 113 | 'r','d',' ','T','i','m','e','\0'}, 420, 0}, |
| 114 | {"MDT", |
| 115 | {'M','o','u','n','t','a','i','n',' ','S','t','a','n','d','a','r','d',' ', |
| 116 | 'T','i','m','e','\0'}, 360, 1}, |
| 117 | {"CST", |
| 118 | {'C','e','n','t','r','a','l',' ','A','m','e','r','i','c','a',' ','S','t', |
| 119 | 'a','n','d','a','r','d',' ','T','i','m','e','\0'}, 360, 0}, |
| 120 | {"CDT", |
| 121 | {'C','e','n','t','r','a','l',' ','S','t','a','n','d','a','r','d',' ','T', |
| 122 | 'i','m','e','\0'}, 300, 1}, |
| 123 | {"COT", |
| 124 | {'S','A',' ','P','a','c','i','f','i','c',' ','S','t','a','n','d','a','r', |
| 125 | 'd',' ','T','i','m','e','\0'}, 300, 0}, |
| 126 | {"EDT", |
| 127 | {'E','a','s','t','e','r','n',' ','S','t','a','n','d','a','r','d',' ','T', |
| 128 | 'i','m','e','\0'}, 240, 1}, |
| 129 | {"EST", |
| 130 | {'U','S',' ','E','a','s','t','e','r','n',' ','S','t','a','n','d','a','r', |
| 131 | 'd',' ','T','i','m','e','\0'}, 300, 0}, |
| 132 | {"ADT", |
| 133 | {'A','t','l','a','n','t','i','c',' ','S','t','a','n','d','a','r','d',' ', |
| 134 | 'T','i','m','e','\0'}, 180, 1}, |
| 135 | {"VET", |
| 136 | {'S','A',' ','W','e','s','t','e','r','n',' ','S','t','a','n','d','a','r', |
| 137 | 'd',' ','T','i','m','e','\0'}, 240, 0}, |
| 138 | {"CLT", |
| 139 | {'P','a','c','i','f','i','c',' ','S','A',' ','S','t','a','n','d','a','r', |
| 140 | 'd',' ','T','i','m','e','\0'}, 240, 0}, |
| 141 | {"NDT", |
| 142 | {'N','e','w','f','o','u','n','d','l','a','n','d',' ','S','t','a','n','d', |
| 143 | 'a','r','d',' ','T','i','m','e','\0'}, 150, 1}, |
| 144 | {"BRT", |
| 145 | {'E','.',' ','S','o','u','t','h',' ','A','m','e','r','i','c','a',' ','S', |
| 146 | 't','a','n','d','a','r','d',' ','T','i','m','e','\0'}, 180, 0}, |
| 147 | {"ART", |
| 148 | {'S','A',' ','E','a','s','t','e','r','n',' ','S','t','a','n','d','a','r', |
| 149 | 'd',' ','T','i','m','e','\0'}, 180, 0}, |
| 150 | {"WGST", |
| 151 | {'G','r','e','e','n','l','a','n','d',' ','S','t','a','n','d','a','r','d', |
| 152 | ' ','T','i','m','e','\0'}, 120, 1}, |
| 153 | {"GST", |
| 154 | {'M','i','d','-','A','t','l','a','n','t','i','c',' ','S','t','a','n','d', |
| 155 | 'a','r','d',' ','T','i','m','e','\0'}, 120, 0}, |
| 156 | {"AZOST", |
| 157 | {'A','z','o','r','e','s',' ','S','t','a','n','d','a','r','d',' ','T','i', |
| 158 | 'm','e','\0'}, 0, 1}, |
| 159 | {"CVT", |
| 160 | {'C','a','p','e',' ','V','e','r','d','e',' ','S','t','a','n','d','a','r', |
| 161 | 'd',' ','T','i','m','e','\0'}, 60, 0}, |
| 162 | {"WET", |
| 163 | {'G','r','e','e','n','w','i','c','h',' ','S','t','a','n','d','a','r','d', |
| 164 | ' ','T','i','m','e','\0'}, 0, 0}, |
| 165 | {"BST", |
| 166 | {'G','M','T',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 167 | -60, 1}, |
| 168 | {"GMT", |
| 169 | {'G','M','T',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 170 | 0, 0}, |
Filip Navara | 63c6359 | 2004-10-04 19:29:16 +0000 | [diff] [blame] | 171 | {"UTC", |
| 172 | {'G','M','T',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 173 | 0, 0}, |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 174 | {"CEST", |
| 175 | {'C','e','n','t','r','a','l',' ','E','u','r','o','p','e',' ','S','t','a', |
| 176 | 'n','d','a','r','d',' ','T','i','m','e','\0'}, -120, 1}, |
Uwe Bonnes | d349908 | 2004-09-06 21:26:37 +0000 | [diff] [blame] | 177 | {"MET", |
| 178 | {'C','e','n','t','r','a','l',' ','E','u','r','o','p','e',' ','S','t','a', |
| 179 | 'n','d','a','r','d',' ','T','i','m','e','\0'}, -60, 0}, |
| 180 | {"MEST", |
| 181 | {'C','e','n','t','r','a','l',' ','E','u','r','o','p','e',' ','D','a','y', |
| 182 | 'l','i','g','h','t',' ','T','i','m','e','\0'}, -120, 1}, |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 183 | {"WAT", |
| 184 | {'W','.',' ','C','e','n','t','r','a','l',' ','A','f','r','i','c','a',' ', |
| 185 | 'S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, -60, 0}, |
| 186 | {"EEST", |
| 187 | {'E','.',' ','E','u','r','o','p','e',' ','S','t','a','n','d','a','r','d', |
| 188 | ' ','T','i','m','e','\0'}, -180, 1}, |
| 189 | {"EET", |
| 190 | {'E','g','y','p','t',' ','S','t','a','n','d','a','r','d',' ','T','i','m', |
| 191 | 'e','\0'}, -120, 0}, |
| 192 | {"CAT", |
| 193 | {'S','o','u','t','h',' ','A','f','r','i','c','a',' ','S','t','a','n','d', |
| 194 | 'a','r','d',' ','T','i','m','e','\0'}, -120, 0}, |
| 195 | {"IST", |
| 196 | {'I','s','r','a','e','l',' ','S','t','a','n','d','a','r','d',' ','T','i', |
| 197 | 'm','e','\0'}, -120, 0}, |
| 198 | {"ADT", |
| 199 | {'A','r','a','b','i','c',' ','S','t','a','n','d','a','r','d',' ','T','i', |
| 200 | 'm','e','\0'}, -240, 1}, |
| 201 | {"AST", |
| 202 | {'A','r','a','b',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e', |
| 203 | '\0'}, -180, 0}, |
| 204 | {"MSD", |
| 205 | {'R','u','s','s','i','a','n',' ','S','t','a','n','d','a','r','d',' ','T', |
| 206 | 'i','m','e','\0'}, -240, 1}, |
| 207 | {"EAT", |
| 208 | {'E','.',' ','A','f','r','i','c','a',' ','S','t','a','n','d','a','r','d', |
| 209 | ' ','T','i','m','e','\0'}, -180, 0}, |
| 210 | {"IRST", |
| 211 | {'I','r','a','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e', |
| 212 | '\0'}, -270, 1}, |
| 213 | {"GST", |
| 214 | {'A','r','a','b','i','a','n',' ','S','t','a','n','d','a','r','d',' ','T', |
| 215 | 'i','m','e','\0'}, -240, 0}, |
| 216 | {"AZST", |
| 217 | {'C','a','u','c','a','s','u','s',' ','S','t','a','n','d','a','r','d',' ', |
| 218 | 'T','i','m','e','\0'}, -300, 1}, |
| 219 | {"AFT", |
| 220 | {'A','f','g','h','a','n','i','s','t','a','n',' ','S','t','a','n','d','a', |
| 221 | 'r','d',' ','T','i','m','e','\0'}, -270, 0}, |
| 222 | {"YEKST", |
| 223 | {'E','k','a','t','e','r','i','n','b','u','r','g',' ','S','t','a','n','d', |
| 224 | 'a','r','d',' ','T','i','m','e','\0'}, -360, 1}, |
| 225 | {"PKT", |
| 226 | {'W','e','s','t',' ','A','s','i','a',' ','S','t','a','n','d','a','r','d', |
| 227 | ' ','T','i','m','e','\0'}, -300, 0}, |
| 228 | {"IST", |
| 229 | {'I','n','d','i','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m', |
| 230 | 'e','\0'}, -330, 0}, |
| 231 | {"NPT", |
| 232 | {'N','e','p','a','l',' ','S','t','a','n','d','a','r','d',' ','T','i','m', |
| 233 | 'e','\0'}, -345, 0}, |
| 234 | {"ALMST", |
| 235 | {'N','.',' ','C','e','n','t','r','a','l',' ','A','s','i','a',' ','S','t', |
| 236 | 'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -420, 1}, |
| 237 | {"BDT", |
| 238 | {'C','e','n','t','r','a','l',' ','A','s','i','a',' ','S','t','a','n','d', |
| 239 | 'a','r','d',' ','T','i','m','e','\0'}, -360, 0}, |
| 240 | {"LKT", |
| 241 | {'S','r','i',' ','L','a','n','k','a',' ','S','t','a','n','d','a','r','d', |
| 242 | ' ','T','i','m','e','\0'}, -360, 0}, |
| 243 | {"MMT", |
| 244 | {'M','y','a','n','m','a','r',' ','S','t','a','n','d','a','r','d',' ','T', |
| 245 | 'i','m','e','\0'}, -390, 0}, |
| 246 | {"ICT", |
| 247 | {'S','E',' ','A','s','i','a',' ','S','t','a','n','d','a','r','d',' ','T', |
| 248 | 'i','m','e','\0'}, -420, 0}, |
| 249 | {"KRAST", |
| 250 | {'N','o','r','t','h',' ','A','s','i','a',' ','S','t','a','n','d','a','r', |
| 251 | 'd',' ','T','i','m','e','\0'}, -480, 1}, |
| 252 | {"CST", |
| 253 | {'C','h','i','n','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m', |
| 254 | 'e','\0'}, -480, 0}, |
| 255 | {"IRKST", |
| 256 | {'N','o','r','t','h',' ','A','s','i','a',' ','E','a','s','t',' ','S','t', |
| 257 | 'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -540, 1}, |
| 258 | {"SGT", |
| 259 | {'M','a','l','a','y',' ','P','e','n','i','n','s','u','l','a',' ','S','t', |
| 260 | 'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -480, 0}, |
| 261 | {"WST", |
| 262 | {'W','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a','n','d', |
| 263 | 'a','r','d',' ','T','i','m','e','\0'}, -480, 0}, |
| 264 | {"JST", |
| 265 | {'T','o','k','y','o',' ','S','t','a','n','d','a','r','d',' ','T','i','m', |
| 266 | 'e','\0'}, -540, 0}, |
| 267 | {"KST", |
| 268 | {'K','o','r','e','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m', |
| 269 | 'e','\0'}, -540, 0}, |
| 270 | {"YAKST", |
| 271 | {'Y','a','k','u','t','s','k',' ','S','t','a','n','d','a','r','d',' ','T', |
| 272 | 'i','m','e','\0'}, -600, 1}, |
| 273 | {"CST", |
| 274 | {'C','e','n','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a', |
| 275 | 'n','d','a','r','d',' ','T','i','m','e','\0'}, -570, 0}, |
| 276 | {"EST", |
| 277 | {'E','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a','n','d', |
| 278 | 'a','r','d',' ','T','i','m','e','\0'}, -600, 0}, |
| 279 | {"GST", |
| 280 | {'W','e','s','t',' ','P','a','c','i','f','i','c',' ','S','t','a','n','d', |
| 281 | 'a','r','d',' ','T','i','m','e','\0'}, -600, 0}, |
| 282 | {"VLAST", |
| 283 | {'V','l','a','d','i','v','o','s','t','o','k',' ','S','t','a','n','d','a', |
| 284 | 'r','d',' ','T','i','m','e','\0'}, -660, 1}, |
| 285 | {"MAGST", |
| 286 | {'C','e','n','t','r','a','l',' ','P','a','c','i','f','i','c',' ','S','t', |
| 287 | 'a','n','d','a','r','d',' ','T','i','m','e','\0'}, -720, 1}, |
| 288 | {"NZST", |
| 289 | {'N','e','w',' ','Z','e','a','l','a','n','d',' ','S','t','a','n','d','a', |
| 290 | 'r','d',' ','T','i','m','e','\0'}, -720, 0}, |
| 291 | {"FJT", |
| 292 | {'F','i','j','i',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e', |
| 293 | '\0'}, -720, 0}, |
| 294 | {"TOT", |
| 295 | {'T','o','n','g','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m', |
| 296 | 'e','\0'}, -780, 0} |
| 297 | }; |
| 298 | |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 299 | #define TICKSPERSEC 10000000 |
| 300 | #define TICKSPERMSEC 10000 |
| 301 | #define SECSPERDAY 86400 |
| 302 | #define SECSPERHOUR 3600 |
| 303 | #define SECSPERMIN 60 |
| 304 | #define MINSPERHOUR 60 |
| 305 | #define HOURSPERDAY 24 |
Alexandre Julliard | dcc3afd | 2002-12-13 20:53:04 +0000 | [diff] [blame] | 306 | #define EPOCHWEEKDAY 1 /* Jan 1, 1601 was Monday */ |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 307 | #define DAYSPERWEEK 7 |
| 308 | #define EPOCHYEAR 1601 |
| 309 | #define DAYSPERNORMALYEAR 365 |
| 310 | #define DAYSPERLEAPYEAR 366 |
| 311 | #define MONSPERYEAR 12 |
Huw Davies | 166faa4 | 2004-02-24 01:01:27 +0000 | [diff] [blame] | 312 | #define DAYSPERQUADRICENTENNIUM (365 * 400 + 97) |
| 313 | #define DAYSPERNORMALCENTURY (365 * 100 + 24) |
| 314 | #define DAYSPERNORMALQUADRENNIUM (365 * 4 + 1) |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 315 | |
Alexandre Julliard | d76f9f9 | 2000-10-01 01:40:42 +0000 | [diff] [blame] | 316 | /* 1601 to 1970 is 369 years plus 89 leap days */ |
Alexandre Julliard | fbef57c | 2003-03-31 01:37:04 +0000 | [diff] [blame] | 317 | #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY) |
| 318 | #define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC) |
Alexandre Julliard | d76f9f9 | 2000-10-01 01:40:42 +0000 | [diff] [blame] | 319 | /* 1601 to 1980 is 379 years plus 91 leap days */ |
Alexandre Julliard | fbef57c | 2003-03-31 01:37:04 +0000 | [diff] [blame] | 320 | #define SECS_1601_TO_1980 ((379 * 365 + 91) * (ULONGLONG)SECSPERDAY) |
| 321 | #define TICKS_1601_TO_1980 (SECS_1601_TO_1980 * TICKSPERSEC) |
Alexandre Julliard | 25b23a0 | 2004-09-07 23:01:34 +0000 | [diff] [blame] | 322 | /* max ticks that can be represented as Unix time */ |
| 323 | #define TICKS_1601_TO_UNIX_MAX ((SECS_1601_TO_1970 + INT_MAX) * TICKSPERSEC) |
Alexandre Julliard | d76f9f9 | 2000-10-01 01:40:42 +0000 | [diff] [blame] | 324 | |
| 325 | |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 326 | static const int MonthLengths[2][MONSPERYEAR] = |
| 327 | { |
| 328 | { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, |
| 329 | { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } |
| 330 | }; |
| 331 | |
Alexandre Julliard | 9aef077 | 2004-04-02 20:28:07 +0000 | [diff] [blame] | 332 | static const int YearDays[2][MONSPERYEAR+1] = |
| 333 | { |
| 334 | { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, |
| 335 | { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } |
| 336 | }; |
| 337 | |
Patrik Stridvall | 896889f | 1999-05-08 12:50:36 +0000 | [diff] [blame] | 338 | static inline int IsLeapYear(int Year) |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 339 | { |
| 340 | return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0; |
| 341 | } |
| 342 | |
Patrik Stridvall | 896889f | 1999-05-08 12:50:36 +0000 | [diff] [blame] | 343 | static inline void NormalizeTimeFields(CSHORT *FieldToNormalize, CSHORT *CarryField,int Modulus) |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 344 | { |
| 345 | *FieldToNormalize = (CSHORT) (*FieldToNormalize - Modulus); |
| 346 | *CarryField = (CSHORT) (*CarryField + 1); |
| 347 | } |
| 348 | |
Alexandre Julliard | fbef57c | 2003-03-31 01:37:04 +0000 | [diff] [blame] | 349 | /*********************************************************************** |
| 350 | * NTDLL_get_server_timeout |
| 351 | * |
| 352 | * Convert a NTDLL timeout into a timeval struct to send to the server. |
| 353 | */ |
Alexandre Julliard | 462172a | 2003-04-02 22:48:59 +0000 | [diff] [blame] | 354 | void NTDLL_get_server_timeout( abs_time_t *when, const LARGE_INTEGER *timeout ) |
Alexandre Julliard | fbef57c | 2003-03-31 01:37:04 +0000 | [diff] [blame] | 355 | { |
| 356 | UINT remainder; |
| 357 | |
| 358 | if (!timeout) /* infinite timeout */ |
| 359 | { |
Alexandre Julliard | 462172a | 2003-04-02 22:48:59 +0000 | [diff] [blame] | 360 | when->sec = when->usec = 0; |
Alexandre Julliard | fbef57c | 2003-03-31 01:37:04 +0000 | [diff] [blame] | 361 | } |
| 362 | else if (timeout->QuadPart <= 0) /* relative timeout */ |
| 363 | { |
Alexandre Julliard | 462172a | 2003-04-02 22:48:59 +0000 | [diff] [blame] | 364 | struct timeval tv; |
Alexandre Julliard | 25b23a0 | 2004-09-07 23:01:34 +0000 | [diff] [blame] | 365 | |
| 366 | if (-timeout->QuadPart > (LONGLONG)INT_MAX * TICKSPERSEC) |
| 367 | when->sec = when->usec = INT_MAX; |
| 368 | else |
Alexandre Julliard | fbef57c | 2003-03-31 01:37:04 +0000 | [diff] [blame] | 369 | { |
Alexandre Julliard | 25b23a0 | 2004-09-07 23:01:34 +0000 | [diff] [blame] | 370 | ULONG sec = RtlEnlargedUnsignedDivide( -timeout->QuadPart, TICKSPERSEC, &remainder ); |
| 371 | gettimeofday( &tv, 0 ); |
| 372 | when->sec = tv.tv_sec + sec; |
| 373 | if ((when->usec = tv.tv_usec + (remainder / 10)) >= 1000000) |
| 374 | { |
| 375 | when->usec -= 1000000; |
| 376 | when->sec++; |
| 377 | } |
| 378 | if (when->sec < tv.tv_sec) /* overflow */ |
| 379 | when->sec = when->usec = INT_MAX; |
Alexandre Julliard | fbef57c | 2003-03-31 01:37:04 +0000 | [diff] [blame] | 380 | } |
Alexandre Julliard | fbef57c | 2003-03-31 01:37:04 +0000 | [diff] [blame] | 381 | } |
| 382 | else /* absolute time */ |
| 383 | { |
Alexandre Julliard | 25b23a0 | 2004-09-07 23:01:34 +0000 | [diff] [blame] | 384 | if (timeout->QuadPart < TICKS_1601_TO_1970) |
| 385 | when->sec = when->usec = 0; |
| 386 | else if (timeout->QuadPart > TICKS_1601_TO_UNIX_MAX) |
| 387 | when->sec = when->usec = INT_MAX; |
| 388 | else |
| 389 | { |
| 390 | when->sec = RtlEnlargedUnsignedDivide( timeout->QuadPart - TICKS_1601_TO_1970, |
| 391 | TICKSPERSEC, &remainder ); |
| 392 | when->usec = remainder / 10; |
| 393 | } |
Alexandre Julliard | fbef57c | 2003-03-31 01:37:04 +0000 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
| 397 | |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 398 | /****************************************************************************** |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 399 | * RtlTimeToTimeFields [NTDLL.@] |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 400 | * |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 401 | * Convert a time into a TIME_FIELDS structure. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 402 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 403 | * PARAMS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 404 | * liTime [I] Time to convert. |
| 405 | * TimeFields [O] Destination for the converted time. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 406 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 407 | * RETURNS |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 408 | * Nothing. |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 409 | */ |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 410 | VOID WINAPI RtlTimeToTimeFields( |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 411 | const LARGE_INTEGER *liTime, |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 412 | PTIME_FIELDS TimeFields) |
| 413 | { |
Huw Davies | 166faa4 | 2004-02-24 01:01:27 +0000 | [diff] [blame] | 414 | int SecondsInDay, DeltaYear; |
György 'Nog' Jeney | 39433b9 | 2002-11-06 21:57:23 +0000 | [diff] [blame] | 415 | int LeapYear, CurMonth; |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 416 | long int Days; |
Alexandre Julliard | dcc3afd | 2002-12-13 20:53:04 +0000 | [diff] [blame] | 417 | LONGLONG Time = liTime->QuadPart; |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 418 | |
| 419 | /* Extract millisecond from time and convert time into seconds */ |
| 420 | TimeFields->Milliseconds = (CSHORT) ((Time % TICKSPERSEC) / TICKSPERMSEC); |
| 421 | Time = Time / TICKSPERSEC; |
| 422 | |
György 'Nog' Jeney | 39433b9 | 2002-11-06 21:57:23 +0000 | [diff] [blame] | 423 | /* The native version of RtlTimeToTimeFields does not take leap seconds |
| 424 | * into account */ |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 425 | |
| 426 | /* Split the time into days and seconds within the day */ |
| 427 | Days = Time / SECSPERDAY; |
| 428 | SecondsInDay = Time % SECSPERDAY; |
| 429 | |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 430 | /* compute time of day */ |
| 431 | TimeFields->Hour = (CSHORT) (SecondsInDay / SECSPERHOUR); |
| 432 | SecondsInDay = SecondsInDay % SECSPERHOUR; |
| 433 | TimeFields->Minute = (CSHORT) (SecondsInDay / SECSPERMIN); |
| 434 | TimeFields->Second = (CSHORT) (SecondsInDay % SECSPERMIN); |
| 435 | |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 436 | /* compute day of week */ |
| 437 | TimeFields->Weekday = (CSHORT) ((EPOCHWEEKDAY + Days) % DAYSPERWEEK); |
| 438 | |
| 439 | /* compute year */ |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 440 | /* FIXME: handle calendar modifications */ |
Huw Davies | 166faa4 | 2004-02-24 01:01:27 +0000 | [diff] [blame] | 441 | TimeFields->Year = EPOCHYEAR; |
| 442 | DeltaYear = Days / DAYSPERQUADRICENTENNIUM; |
| 443 | TimeFields->Year += DeltaYear * 400; |
| 444 | Days -= DeltaYear * DAYSPERQUADRICENTENNIUM; |
| 445 | DeltaYear = Days / DAYSPERNORMALCENTURY; |
| 446 | TimeFields->Year += DeltaYear * 100; |
| 447 | Days -= DeltaYear * DAYSPERNORMALCENTURY; |
| 448 | DeltaYear = Days / DAYSPERNORMALQUADRENNIUM; |
| 449 | TimeFields->Year += DeltaYear * 4; |
| 450 | Days -= DeltaYear * DAYSPERNORMALQUADRENNIUM; |
| 451 | DeltaYear = Days / DAYSPERNORMALYEAR; |
| 452 | TimeFields->Year += DeltaYear; |
| 453 | Days -= DeltaYear * DAYSPERNORMALYEAR; |
| 454 | |
| 455 | LeapYear = IsLeapYear(TimeFields->Year); |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 456 | |
| 457 | /* Compute month of year */ |
Alexandre Julliard | 9aef077 | 2004-04-02 20:28:07 +0000 | [diff] [blame] | 458 | CurMonth = 1; |
| 459 | while (Days >= YearDays[LeapYear][CurMonth]) CurMonth++; |
| 460 | TimeFields->Day = Days - YearDays[LeapYear][CurMonth-1] + 1; |
| 461 | TimeFields->Month = CurMonth; |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 462 | } |
György 'Nog' Jeney | 39433b9 | 2002-11-06 21:57:23 +0000 | [diff] [blame] | 463 | |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 464 | /****************************************************************************** |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 465 | * RtlTimeFieldsToTime [NTDLL.@] |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 466 | * |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 467 | * Convert a TIME_FIELDS structure into a time. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 468 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 469 | * PARAMS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 470 | * ftTimeFields [I] TIME_FIELDS structure to convert. |
| 471 | * Time [O] Destination for the converted time. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 472 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 473 | * RETURNS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 474 | * Success: TRUE. |
| 475 | * Failure: FALSE. |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 476 | */ |
| 477 | BOOLEAN WINAPI RtlTimeFieldsToTime( |
| 478 | PTIME_FIELDS tfTimeFields, |
| 479 | PLARGE_INTEGER Time) |
| 480 | { |
Alexandre Julliard | 9aef077 | 2004-04-02 20:28:07 +0000 | [diff] [blame] | 481 | int CurYear, DeltaYear; |
Patrik Stridvall | ef0e2af | 2002-08-27 18:17:49 +0000 | [diff] [blame] | 482 | LONGLONG rcTime; |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 483 | TIME_FIELDS TimeFields = *tfTimeFields; |
| 484 | |
| 485 | rcTime = 0; |
| 486 | |
| 487 | /* FIXME: normalize the TIME_FIELDS structure here */ |
| 488 | while (TimeFields.Second >= SECSPERMIN) |
| 489 | { NormalizeTimeFields(&TimeFields.Second, &TimeFields.Minute, SECSPERMIN); |
| 490 | } |
| 491 | while (TimeFields.Minute >= MINSPERHOUR) |
| 492 | { NormalizeTimeFields(&TimeFields.Minute, &TimeFields.Hour, MINSPERHOUR); |
| 493 | } |
| 494 | while (TimeFields.Hour >= HOURSPERDAY) |
| 495 | { NormalizeTimeFields(&TimeFields.Hour, &TimeFields.Day, HOURSPERDAY); |
| 496 | } |
| 497 | while (TimeFields.Day > MonthLengths[IsLeapYear(TimeFields.Year)][TimeFields.Month - 1]) |
Alexandre Julliard | 9aef077 | 2004-04-02 20:28:07 +0000 | [diff] [blame] | 498 | { NormalizeTimeFields(&TimeFields.Day, &TimeFields.Month, |
| 499 | MonthLengths[IsLeapYear(TimeFields.Year)][TimeFields.Month - 1]); |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 500 | } |
| 501 | while (TimeFields.Month > MONSPERYEAR) |
| 502 | { NormalizeTimeFields(&TimeFields.Month, &TimeFields.Year, MONSPERYEAR); |
| 503 | } |
| 504 | |
| 505 | /* FIXME: handle calendar corrections here */ |
Huw Davies | f66af59 | 2004-02-25 01:25:00 +0000 | [diff] [blame] | 506 | CurYear = TimeFields.Year - EPOCHYEAR; |
| 507 | DeltaYear = CurYear / 400; |
| 508 | CurYear -= DeltaYear * 400; |
| 509 | rcTime += DeltaYear * DAYSPERQUADRICENTENNIUM; |
| 510 | DeltaYear = CurYear / 100; |
| 511 | CurYear -= DeltaYear * 100; |
| 512 | rcTime += DeltaYear * DAYSPERNORMALCENTURY; |
| 513 | DeltaYear = CurYear / 4; |
| 514 | CurYear -= DeltaYear * 4; |
| 515 | rcTime += DeltaYear * DAYSPERNORMALQUADRENNIUM; |
| 516 | rcTime += CurYear * DAYSPERNORMALYEAR; |
Alexandre Julliard | 9aef077 | 2004-04-02 20:28:07 +0000 | [diff] [blame] | 517 | rcTime += YearDays[IsLeapYear(TimeFields.Year)][TimeFields.Month - 1]; |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 518 | rcTime += TimeFields.Day - 1; |
| 519 | rcTime *= SECSPERDAY; |
| 520 | rcTime += TimeFields.Hour * SECSPERHOUR + TimeFields.Minute * SECSPERMIN + TimeFields.Second; |
| 521 | rcTime *= TICKSPERSEC; |
| 522 | rcTime += TimeFields.Milliseconds * TICKSPERMSEC; |
Alexandre Julliard | dcc3afd | 2002-12-13 20:53:04 +0000 | [diff] [blame] | 523 | Time->QuadPart = rcTime; |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 524 | |
| 525 | return TRUE; |
| 526 | } |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 527 | |
Huw Davies | 64ed848 | 2004-02-26 05:26:34 +0000 | [diff] [blame] | 528 | /*********************************************************************** |
| 529 | * TIME_GetBias [internal] |
| 530 | * |
| 531 | * Helper function calculates delta local time from UTC. |
| 532 | * |
| 533 | * PARAMS |
| 534 | * utc [I] The current utc time. |
| 535 | * pdaylight [I] Local daylight. |
| 536 | * |
| 537 | * RETURNS |
| 538 | * The bias for the current timezone. |
| 539 | */ |
| 540 | static int TIME_GetBias(time_t utc, int *pdaylight) |
| 541 | { |
Huw Davies | 67e2d6c | 2004-02-27 00:43:20 +0000 | [diff] [blame] | 542 | struct tm *ptm; |
| 543 | static time_t last_utc; |
| 544 | static int last_bias; |
Rein Klazes | 5040309 | 2004-03-01 21:23:18 +0000 | [diff] [blame] | 545 | static int last_daylight; |
Huw Davies | 67e2d6c | 2004-02-27 00:43:20 +0000 | [diff] [blame] | 546 | int ret; |
| 547 | |
| 548 | RtlEnterCriticalSection( &TIME_GetBias_section ); |
| 549 | if(utc == last_utc) |
Rein Klazes | 5040309 | 2004-03-01 21:23:18 +0000 | [diff] [blame] | 550 | { |
| 551 | *pdaylight = last_daylight; |
Huw Davies | 67e2d6c | 2004-02-27 00:43:20 +0000 | [diff] [blame] | 552 | ret = last_bias; |
Rein Klazes | 5040309 | 2004-03-01 21:23:18 +0000 | [diff] [blame] | 553 | } else |
Huw Davies | 67e2d6c | 2004-02-27 00:43:20 +0000 | [diff] [blame] | 554 | { |
| 555 | ptm = localtime(&utc); |
Rein Klazes | 5040309 | 2004-03-01 21:23:18 +0000 | [diff] [blame] | 556 | *pdaylight = last_daylight = |
| 557 | ptm->tm_isdst; /* daylight for local timezone */ |
Huw Davies | 67e2d6c | 2004-02-27 00:43:20 +0000 | [diff] [blame] | 558 | ptm = gmtime(&utc); |
| 559 | ptm->tm_isdst = *pdaylight; /* use local daylight, not that of Greenwich */ |
| 560 | last_utc = utc; |
| 561 | ret = last_bias = (int)(utc-mktime(ptm)); |
| 562 | } |
| 563 | RtlLeaveCriticalSection( &TIME_GetBias_section ); |
| 564 | return ret; |
Huw Davies | 64ed848 | 2004-02-26 05:26:34 +0000 | [diff] [blame] | 565 | } |
| 566 | |
György 'Nog' Jeney | 4d6ba25 | 2002-12-11 00:19:56 +0000 | [diff] [blame] | 567 | /****************************************************************************** |
| 568 | * RtlLocalTimeToSystemTime [NTDLL.@] |
| 569 | * |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 570 | * Convert a local time into system time. |
György 'Nog' Jeney | 4d6ba25 | 2002-12-11 00:19:56 +0000 | [diff] [blame] | 571 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 572 | * PARAMS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 573 | * LocalTime [I] Local time to convert. |
| 574 | * SystemTime [O] Destination for the converted time. |
György 'Nog' Jeney | 4d6ba25 | 2002-12-11 00:19:56 +0000 | [diff] [blame] | 575 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 576 | * RETURNS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 577 | * Success: STATUS_SUCCESS. |
| 578 | * Failure: An NTSTATUS error code indicating the problem. |
György 'Nog' Jeney | 4d6ba25 | 2002-12-11 00:19:56 +0000 | [diff] [blame] | 579 | */ |
| 580 | NTSTATUS WINAPI RtlLocalTimeToSystemTime( const LARGE_INTEGER *LocalTime, |
| 581 | PLARGE_INTEGER SystemTime) |
| 582 | { |
Huw Davies | 64ed848 | 2004-02-26 05:26:34 +0000 | [diff] [blame] | 583 | time_t gmt; |
| 584 | int bias, daylight; |
György 'Nog' Jeney | 4d6ba25 | 2002-12-11 00:19:56 +0000 | [diff] [blame] | 585 | |
| 586 | TRACE("(%p, %p)\n", LocalTime, SystemTime); |
| 587 | |
Huw Davies | 64ed848 | 2004-02-26 05:26:34 +0000 | [diff] [blame] | 588 | gmt = time(NULL); |
| 589 | bias = TIME_GetBias(gmt, &daylight); |
| 590 | |
| 591 | SystemTime->QuadPart = LocalTime->QuadPart - bias * (LONGLONG)10000000; |
György 'Nog' Jeney | 4d6ba25 | 2002-12-11 00:19:56 +0000 | [diff] [blame] | 592 | return STATUS_SUCCESS; |
| 593 | } |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 594 | |
| 595 | /****************************************************************************** |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 596 | * RtlSystemTimeToLocalTime [NTDLL.@] |
| 597 | * |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 598 | * Convert a system time into a local time. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 599 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 600 | * PARAMS |
| 601 | * SystemTime [I] System time to convert. |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 602 | * LocalTime [O] Destination for the converted time. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 603 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 604 | * RETURNS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 605 | * Success: STATUS_SUCCESS. |
| 606 | * Failure: An NTSTATUS error code indicating the problem. |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 607 | */ |
György 'Nog' Jeney | 4d6ba25 | 2002-12-11 00:19:56 +0000 | [diff] [blame] | 608 | NTSTATUS WINAPI RtlSystemTimeToLocalTime( const LARGE_INTEGER *SystemTime, |
| 609 | PLARGE_INTEGER LocalTime ) |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 610 | { |
Huw Davies | 64ed848 | 2004-02-26 05:26:34 +0000 | [diff] [blame] | 611 | time_t gmt; |
| 612 | int bias, daylight; |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 613 | |
György 'Nog' Jeney | 4d6ba25 | 2002-12-11 00:19:56 +0000 | [diff] [blame] | 614 | TRACE("(%p, %p)\n", SystemTime, LocalTime); |
| 615 | |
Huw Davies | 64ed848 | 2004-02-26 05:26:34 +0000 | [diff] [blame] | 616 | gmt = time(NULL); |
| 617 | bias = TIME_GetBias(gmt, &daylight); |
| 618 | |
| 619 | LocalTime->QuadPart = SystemTime->QuadPart + bias * (LONGLONG)10000000; |
György 'Nog' Jeney | 4d6ba25 | 2002-12-11 00:19:56 +0000 | [diff] [blame] | 620 | return STATUS_SUCCESS; |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 621 | } |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 622 | |
| 623 | /****************************************************************************** |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 624 | * RtlTimeToSecondsSince1970 [NTDLL.@] |
| 625 | * |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 626 | * Convert a time into a count of seconds since 1970. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 627 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 628 | * PARAMS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 629 | * Time [I] Time to convert. |
| 630 | * Seconds [O] Destination for the converted time. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 631 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 632 | * RETURNS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 633 | * Success: TRUE. |
| 634 | * Failure: FALSE, if the resulting value will not fit in a DWORD. |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 635 | */ |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 636 | BOOLEAN WINAPI RtlTimeToSecondsSince1970( const LARGE_INTEGER *Time, LPDWORD Seconds ) |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 637 | { |
Ge van Geldorp | 399901e | 2004-01-23 01:51:33 +0000 | [diff] [blame] | 638 | ULONGLONG tmp = ((ULONGLONG)Time->u.HighPart << 32) | Time->u.LowPart; |
Patrik Stridvall | ef0e2af | 2002-08-27 18:17:49 +0000 | [diff] [blame] | 639 | tmp = RtlLargeIntegerDivide( tmp, 10000000, NULL ); |
Alexandre Julliard | d76f9f9 | 2000-10-01 01:40:42 +0000 | [diff] [blame] | 640 | tmp -= SECS_1601_TO_1970; |
| 641 | if (tmp > 0xffffffff) return FALSE; |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 642 | *Seconds = (DWORD)tmp; |
Alexandre Julliard | 0aa6cc2 | 2000-07-29 21:56:59 +0000 | [diff] [blame] | 643 | return TRUE; |
| 644 | } |
| 645 | |
| 646 | /****************************************************************************** |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 647 | * RtlTimeToSecondsSince1980 [NTDLL.@] |
| 648 | * |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 649 | * Convert a time into a count of seconds since 1980. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 650 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 651 | * PARAMS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 652 | * Time [I] Time to convert. |
| 653 | * Seconds [O] Destination for the converted time. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 654 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 655 | * RETURNS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 656 | * Success: TRUE. |
| 657 | * Failure: FALSE, if the resulting value will not fit in a DWORD. |
Alexandre Julliard | 0aa6cc2 | 2000-07-29 21:56:59 +0000 | [diff] [blame] | 658 | */ |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 659 | BOOLEAN WINAPI RtlTimeToSecondsSince1980( const LARGE_INTEGER *Time, LPDWORD Seconds ) |
Alexandre Julliard | 0aa6cc2 | 2000-07-29 21:56:59 +0000 | [diff] [blame] | 660 | { |
Ge van Geldorp | 399901e | 2004-01-23 01:51:33 +0000 | [diff] [blame] | 661 | ULONGLONG tmp = ((ULONGLONG)Time->u.HighPart << 32) | Time->u.LowPart; |
Patrik Stridvall | ef0e2af | 2002-08-27 18:17:49 +0000 | [diff] [blame] | 662 | tmp = RtlLargeIntegerDivide( tmp, 10000000, NULL ); |
Alexandre Julliard | fbef57c | 2003-03-31 01:37:04 +0000 | [diff] [blame] | 663 | tmp -= SECS_1601_TO_1980; |
Alexandre Julliard | d76f9f9 | 2000-10-01 01:40:42 +0000 | [diff] [blame] | 664 | if (tmp > 0xffffffff) return FALSE; |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 665 | *Seconds = (DWORD)tmp; |
Alexandre Julliard | 0aa6cc2 | 2000-07-29 21:56:59 +0000 | [diff] [blame] | 666 | return TRUE; |
| 667 | } |
| 668 | |
| 669 | /****************************************************************************** |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 670 | * RtlSecondsSince1970ToTime [NTDLL.@] |
| 671 | * |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 672 | * Convert a count of seconds since 1970 to a time. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 673 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 674 | * PARAMS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 675 | * Seconds [I] Time to convert. |
| 676 | * Time [O] Destination for the converted time. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 677 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 678 | * RETURNS |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 679 | * Nothing. |
Alexandre Julliard | 0aa6cc2 | 2000-07-29 21:56:59 +0000 | [diff] [blame] | 680 | */ |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 681 | void WINAPI RtlSecondsSince1970ToTime( DWORD Seconds, LARGE_INTEGER *Time ) |
Alexandre Julliard | 0aa6cc2 | 2000-07-29 21:56:59 +0000 | [diff] [blame] | 682 | { |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 683 | ULONGLONG secs = Seconds * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970; |
Ge van Geldorp | 399901e | 2004-01-23 01:51:33 +0000 | [diff] [blame] | 684 | Time->u.LowPart = (DWORD)secs; |
| 685 | Time->u.HighPart = (DWORD)(secs >> 32); |
Alexandre Julliard | 0aa6cc2 | 2000-07-29 21:56:59 +0000 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | /****************************************************************************** |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 689 | * RtlSecondsSince1980ToTime [NTDLL.@] |
| 690 | * |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 691 | * Convert a count of seconds since 1980 to a time. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 692 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 693 | * PARAMS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 694 | * Seconds [I] Time to convert. |
| 695 | * Time [O] Destination for the converted time. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 696 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 697 | * RETURNS |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 698 | * Nothing. |
Alexandre Julliard | 0aa6cc2 | 2000-07-29 21:56:59 +0000 | [diff] [blame] | 699 | */ |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 700 | void WINAPI RtlSecondsSince1980ToTime( DWORD Seconds, LARGE_INTEGER *Time ) |
Alexandre Julliard | 0aa6cc2 | 2000-07-29 21:56:59 +0000 | [diff] [blame] | 701 | { |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 702 | ULONGLONG secs = Seconds * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1980; |
Ge van Geldorp | 399901e | 2004-01-23 01:51:33 +0000 | [diff] [blame] | 703 | Time->u.LowPart = (DWORD)secs; |
| 704 | Time->u.HighPart = (DWORD)(secs >> 32); |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | /****************************************************************************** |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 708 | * RtlTimeToElapsedTimeFields [NTDLL.@] |
| 709 | * |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 710 | * Convert a time to a count of elapsed seconds. |
| 711 | * |
| 712 | * PARAMS |
| 713 | * Time [I] Time to convert. |
| 714 | * TimeFields [O] Destination for the converted time. |
| 715 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 716 | * RETURNS |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 717 | * Nothing. |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 718 | */ |
Alexandre Julliard | a16ed90 | 2002-12-18 02:31:33 +0000 | [diff] [blame] | 719 | void WINAPI RtlTimeToElapsedTimeFields( const LARGE_INTEGER *Time, PTIME_FIELDS TimeFields ) |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 720 | { |
Alexandre Julliard | a16ed90 | 2002-12-18 02:31:33 +0000 | [diff] [blame] | 721 | LONGLONG time; |
| 722 | UINT rem; |
| 723 | |
| 724 | time = RtlExtendedLargeIntegerDivide( Time->QuadPart, TICKSPERSEC, &rem ); |
| 725 | TimeFields->Milliseconds = rem / TICKSPERMSEC; |
| 726 | |
| 727 | /* time is now in seconds */ |
| 728 | TimeFields->Year = 0; |
| 729 | TimeFields->Month = 0; |
| 730 | TimeFields->Day = RtlExtendedLargeIntegerDivide( time, SECSPERDAY, &rem ); |
| 731 | |
| 732 | /* rem is now the remaining seconds in the last day */ |
| 733 | TimeFields->Second = rem % 60; |
| 734 | rem /= 60; |
| 735 | TimeFields->Minute = rem % 60; |
| 736 | TimeFields->Hour = rem / 60; |
Juergen Schmied | 026d9db | 1999-03-09 17:47:51 +0000 | [diff] [blame] | 737 | } |
Alexandre Julliard | d76f9f9 | 2000-10-01 01:40:42 +0000 | [diff] [blame] | 738 | |
| 739 | /*********************************************************************** |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 740 | * NtQuerySystemTime [NTDLL.@] |
| 741 | * ZwQuerySystemTime [NTDLL.@] |
| 742 | * |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 743 | * Get the current system time. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 744 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 745 | * PARAMS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 746 | * Time [O] Destination for the current system time. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 747 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 748 | * RETURNS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 749 | * Success: STATUS_SUCCESS. |
| 750 | * Failure: An NTSTATUS error code indicating the problem. |
Alexandre Julliard | d76f9f9 | 2000-10-01 01:40:42 +0000 | [diff] [blame] | 751 | */ |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 752 | NTSTATUS WINAPI NtQuerySystemTime( PLARGE_INTEGER Time ) |
Alexandre Julliard | d76f9f9 | 2000-10-01 01:40:42 +0000 | [diff] [blame] | 753 | { |
Alexandre Julliard | d76f9f9 | 2000-10-01 01:40:42 +0000 | [diff] [blame] | 754 | struct timeval now; |
| 755 | |
| 756 | gettimeofday( &now, 0 ); |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 757 | Time->QuadPart = now.tv_sec * (ULONGLONG)TICKSPERSEC + TICKS_1601_TO_1970; |
| 758 | Time->QuadPart += now.tv_usec * 10; |
Patrik Stridvall | 9c1de6d | 2002-09-12 22:07:02 +0000 | [diff] [blame] | 759 | return STATUS_SUCCESS; |
Alexandre Julliard | d76f9f9 | 2000-10-01 01:40:42 +0000 | [diff] [blame] | 760 | } |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 761 | |
| 762 | /*********************************************************************** |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 763 | * TIME_GetTZAsStr [internal] |
| 764 | * |
| 765 | * Helper function that returns the given timezone as a string. |
| 766 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 767 | * PARAMS |
| 768 | * utc [I] The current utc time. |
| 769 | * bias [I] The bias of the current timezone. |
| 770 | * dst [I] ?? |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 771 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 772 | * RETURNS |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 773 | * Timezone name. |
| 774 | * |
| 775 | * NOTES: |
| 776 | * This could be done with a hash table instead of merely iterating through a |
| 777 | * table, however with the small amount of entries (60 or so) I didn't think |
| 778 | * it was worth it. |
| 779 | */ |
| 780 | static const WCHAR* TIME_GetTZAsStr (time_t utc, int bias, int dst) |
| 781 | { |
| 782 | char psTZName[7]; |
| 783 | struct tm *ptm = localtime(&utc); |
Hans Leidekker | a9b4a47 | 2004-08-13 23:53:44 +0000 | [diff] [blame] | 784 | unsigned int i; |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 785 | |
| 786 | if (!strftime (psTZName, 7, "%Z", ptm)) |
| 787 | return (NULL); |
| 788 | |
| 789 | for (i=0; i<(sizeof(TZ_INFO) / sizeof(struct tagTZ_INFO)); i++) |
| 790 | { |
| 791 | if ( strcmp(TZ_INFO[i].psTZFromUnix, psTZName) == 0 && |
| 792 | TZ_INFO[i].bias == bias && |
| 793 | TZ_INFO[i].dst == dst |
| 794 | ) |
| 795 | return TZ_INFO[i].psTZWindows; |
| 796 | } |
Uwe Bonnes | d349908 | 2004-09-06 21:26:37 +0000 | [diff] [blame] | 797 | FIXME("Can't match system time zone name \"%s\" to an entry in TZ_INFO\n",psTZName); |
| 798 | FIXME(" Please add appropriate entry to TZ_INFO and submit as patch to wine-patches\n"); |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 799 | return NULL; |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Rein Klazes | c5c93d1 | 2004-10-18 21:19:28 +0000 | [diff] [blame^] | 802 | /*** TIME_GetTimeZoneInfoFromReg: helper for GetTimeZoneInformation ***/ |
| 803 | |
| 804 | |
| 805 | static int TIME_GetTimeZoneInfoFromReg(LPTIME_ZONE_INFORMATION tzinfo) |
| 806 | { |
| 807 | BYTE buf[90]; |
| 808 | KEY_VALUE_PARTIAL_INFORMATION * KpInfo = |
| 809 | (KEY_VALUE_PARTIAL_INFORMATION *) buf; |
| 810 | HKEY hkey; |
| 811 | DWORD size; |
| 812 | OBJECT_ATTRIBUTES attr; |
| 813 | UNICODE_STRING nameW; |
| 814 | |
| 815 | attr.Length = sizeof(attr); |
| 816 | attr.RootDirectory = 0; |
| 817 | attr.ObjectName = &nameW; |
| 818 | attr.Attributes = 0; |
| 819 | attr.SecurityDescriptor = NULL; |
| 820 | attr.SecurityQualityOfService = NULL; |
| 821 | RtlInitUnicodeString( &nameW, TZInformationKeyW); |
| 822 | if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) { |
| 823 | |
| 824 | #define GTZIFR_N( valkey, tofield) \ |
| 825 | RtlInitUnicodeString( &nameW, valkey );\ |
| 826 | if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, KpInfo,\ |
| 827 | sizeof(buf), &size )) { \ |
| 828 | if( size >= (sizeof((tofield)) + \ |
| 829 | offsetof(KEY_VALUE_PARTIAL_INFORMATION,Data))); { \ |
| 830 | memcpy(&(tofield), \ |
| 831 | KpInfo->Data, sizeof(tofield)); \ |
| 832 | } \ |
| 833 | } |
| 834 | #define GTZIFR_S( valkey, tofield) \ |
| 835 | RtlInitUnicodeString( &nameW, valkey );\ |
| 836 | if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, KpInfo,\ |
| 837 | sizeof(buf), &size )) { \ |
| 838 | strncpyW( tofield, (WCHAR*) KpInfo->Data, \ |
| 839 | sizeof( tofield) / sizeof(WCHAR) ); \ |
| 840 | } |
| 841 | |
| 842 | GTZIFR_N( TZStandardStartW, tzinfo->StandardDate) |
| 843 | GTZIFR_N( TZDaylightStartW, tzinfo->DaylightDate) |
| 844 | GTZIFR_N( TZBiasW, tzinfo->Bias) |
| 845 | GTZIFR_N( TZStandardBiasW, tzinfo->StandardBias) |
| 846 | GTZIFR_N( TZDaylightBiasW, tzinfo->DaylightBias) |
| 847 | GTZIFR_S( TZStandardNameW, tzinfo->StandardName) |
| 848 | GTZIFR_S( TZDaylightNameW, tzinfo->DaylightName) |
| 849 | |
| 850 | #undef GTZIFR_N |
| 851 | #undef GTZIFR_S |
| 852 | NtClose( hkey ); |
| 853 | return 1; |
| 854 | } |
| 855 | return 0; |
| 856 | } |
| 857 | |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 858 | /*********************************************************************** |
| 859 | * RtlQueryTimeZoneInformation [NTDLL.@] |
| 860 | * |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 861 | * Get information about the current timezone. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 862 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 863 | * PARAMS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 864 | * tzinfo [O] Destination for the retrieved timezone info. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 865 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 866 | * RETURNS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 867 | * Success: STATUS_SUCCESS. |
| 868 | * Failure: An NTSTATUS error code indicating the problem. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 869 | */ |
| 870 | NTSTATUS WINAPI RtlQueryTimeZoneInformation(LPTIME_ZONE_INFORMATION tzinfo) |
| 871 | { |
| 872 | time_t gmt; |
| 873 | int bias, daylight; |
| 874 | const WCHAR *psTZ; |
| 875 | |
| 876 | memset(tzinfo, 0, sizeof(TIME_ZONE_INFORMATION)); |
| 877 | |
Rein Klazes | c5c93d1 | 2004-10-18 21:19:28 +0000 | [diff] [blame^] | 878 | if( !TIME_GetTimeZoneInfoFromReg(tzinfo)) { |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 879 | |
Rein Klazes | c5c93d1 | 2004-10-18 21:19:28 +0000 | [diff] [blame^] | 880 | gmt = time(NULL); |
| 881 | bias = TIME_GetBias(gmt, &daylight); |
| 882 | |
| 883 | tzinfo->Bias = -bias / 60; |
| 884 | tzinfo->StandardBias = 0; |
| 885 | tzinfo->DaylightBias = -60; |
| 886 | tzinfo->StandardName[0]='\0'; |
| 887 | tzinfo->DaylightName[0]='\0'; |
| 888 | psTZ = TIME_GetTZAsStr (gmt, (-bias/60), daylight); |
| 889 | if (psTZ) strcpyW( tzinfo->StandardName, psTZ ); |
| 890 | } |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 891 | return STATUS_SUCCESS; |
| 892 | } |
| 893 | |
| 894 | /*********************************************************************** |
| 895 | * RtlSetTimeZoneInformation [NTDLL.@] |
| 896 | * |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 897 | * Set the current time zone information. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 898 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 899 | * PARAMS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 900 | * tzinfo [I] Timezone information to set. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 901 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 902 | * RETURNS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 903 | * Success: STATUS_SUCCESS. |
| 904 | * Failure: An NTSTATUS error code indicating the problem. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 905 | * |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 906 | * BUGS |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 907 | * Uses the obsolete unix timezone structure and tz_dsttime member. |
| 908 | */ |
| 909 | NTSTATUS WINAPI RtlSetTimeZoneInformation( const TIME_ZONE_INFORMATION *tzinfo ) |
| 910 | { |
Alexandre Julliard | 8548fc2 | 2004-03-11 00:46:09 +0000 | [diff] [blame] | 911 | #ifdef HAVE_SETTIMEOFDAY |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 912 | struct timezone tz; |
| 913 | |
| 914 | tz.tz_minuteswest = tzinfo->Bias; |
| 915 | #ifdef DST_NONE |
| 916 | tz.tz_dsttime = DST_NONE; |
| 917 | #else |
| 918 | tz.tz_dsttime = 0; |
| 919 | #endif |
| 920 | if(!settimeofday(NULL, &tz)) |
| 921 | return STATUS_SUCCESS; |
Alexandre Julliard | 8548fc2 | 2004-03-11 00:46:09 +0000 | [diff] [blame] | 922 | #endif |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 923 | return STATUS_PRIVILEGE_NOT_HELD; |
| 924 | } |
| 925 | |
| 926 | /*********************************************************************** |
| 927 | * NtSetSystemTime [NTDLL.@] |
| 928 | * ZwSetSystemTime [NTDLL.@] |
| 929 | * |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 930 | * Set the system time. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 931 | * |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 932 | * PARAMS |
| 933 | * NewTime [I] The time to set. |
| 934 | * OldTime [O] Optional destination for the previous system time. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 935 | * |
Jon Griffiths | cd4234a | 2003-03-18 18:35:48 +0000 | [diff] [blame] | 936 | * RETURNS |
Jon Griffiths | 0892285 | 2003-08-19 00:56:34 +0000 | [diff] [blame] | 937 | * Success: STATUS_SUCCESS. |
| 938 | * Failure: An NTSTATUS error code indicating the problem. |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 939 | */ |
| 940 | NTSTATUS WINAPI NtSetSystemTime(const LARGE_INTEGER *NewTime, LARGE_INTEGER *OldTime) |
| 941 | { |
| 942 | TIME_FIELDS tf; |
| 943 | struct timeval tv; |
| 944 | struct timezone tz; |
| 945 | struct tm t; |
| 946 | time_t sec, oldsec; |
| 947 | int dst, bias; |
| 948 | int err; |
| 949 | |
| 950 | /* Return the old time if necessary */ |
| 951 | if(OldTime) |
| 952 | NtQuerySystemTime(OldTime); |
| 953 | |
| 954 | RtlTimeToTimeFields(NewTime, &tf); |
| 955 | |
| 956 | /* call gettimeofday to get the current timezone */ |
| 957 | gettimeofday(&tv, &tz); |
| 958 | oldsec = tv.tv_sec; |
| 959 | /* get delta local time from utc */ |
| 960 | bias = TIME_GetBias(oldsec, &dst); |
| 961 | |
| 962 | /* get the number of seconds */ |
| 963 | t.tm_sec = tf.Second; |
| 964 | t.tm_min = tf.Minute; |
| 965 | t.tm_hour = tf.Hour; |
| 966 | t.tm_mday = tf.Day; |
| 967 | t.tm_mon = tf.Month - 1; |
| 968 | t.tm_year = tf.Year - 1900; |
| 969 | t.tm_isdst = dst; |
| 970 | sec = mktime (&t); |
| 971 | /* correct for timezone and daylight */ |
| 972 | sec += bias; |
| 973 | |
| 974 | /* set the new time */ |
| 975 | tv.tv_sec = sec; |
| 976 | tv.tv_usec = tf.Milliseconds * 1000; |
| 977 | |
| 978 | /* error and sanity check*/ |
| 979 | if(sec == (time_t)-1 || abs((int)(sec-oldsec)) > SETTIME_MAX_ADJUST) { |
| 980 | err = 2; |
| 981 | } else { |
| 982 | #ifdef HAVE_SETTIMEOFDAY |
| 983 | err = settimeofday(&tv, NULL); /* 0 is OK, -1 is error */ |
| 984 | if(err == 0) |
| 985 | return STATUS_SUCCESS; |
| 986 | #else |
| 987 | err = 1; |
| 988 | #endif |
| 989 | } |
| 990 | |
| 991 | ERR("Cannot set time to %d/%d/%d %d:%d:%d Time adjustment %ld %s\n", |
| 992 | tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, |
Gerald Pfeifer | aa0f379 | 2003-10-02 04:29:30 +0000 | [diff] [blame] | 993 | (long)(sec-oldsec), |
| 994 | err == -1 ? "No Permission" |
| 995 | : sec == (time_t)-1 ? "" : "is too large." ); |
György 'Nog' Jeney | 6f3015b | 2002-11-25 01:12:39 +0000 | [diff] [blame] | 996 | |
| 997 | if(err == 2) |
| 998 | return STATUS_INVALID_PARAMETER; |
| 999 | else if(err == -1) |
| 1000 | return STATUS_PRIVILEGE_NOT_HELD; |
| 1001 | else |
| 1002 | return STATUS_NOT_IMPLEMENTED; |
| 1003 | } |