VirtualBox

source: vbox/trunk/include/iprt/time.h@ 83473

Last change on this file since 83473 was 83473, checked in by vboxsync, 5 years ago

Linux: ticketref:19312 Linux: kernel 5.6 - we need changes: fix non-linux builds

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 38.2 KB
Line 
1/** @file
2 * IPRT - Time.
3 */
4
5/*
6 * Copyright (C) 2006-2020 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef IPRT_INCLUDED_time_h
27#define IPRT_INCLUDED_time_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <iprt/cdefs.h>
33#include <iprt/types.h>
34#include <iprt/assertcompile.h>
35
36RT_C_DECLS_BEGIN
37
38/** @defgroup grp_rt_time RTTime - Time
39 * @ingroup grp_rt
40 * @{
41 */
42
43/** Time Specification.
44 *
45 * Use the inline RTTimeSpecGet/Set to operate on structure this so we
46 * can easily change the representation if required later.
47 *
48 * The current representation is in nanoseconds relative to the unix epoch
49 * (1970-01-01 00:00:00 UTC). This gives us an approximate span from
50 * 1678 to 2262 without sacrificing the resolution offered by the various
51 * host OSes (BSD & LINUX 1ns, NT 100ns).
52 */
53typedef struct RTTIMESPEC
54{
55 /** Nanoseconds since epoch.
56 * The name is intentially too long to be comfortable to use because you should be
57 * using inline helpers! */
58 int64_t i64NanosecondsRelativeToUnixEpoch;
59} RTTIMESPEC;
60
61
62/** @name RTTIMESPEC methods
63 * @{ */
64
65/**
66 * Gets the time as nanoseconds relative to the unix epoch.
67 *
68 * @returns Nanoseconds relative to unix epoch.
69 * @param pTime The time spec to interpret.
70 */
71DECLINLINE(int64_t) RTTimeSpecGetNano(PCRTTIMESPEC pTime)
72{
73 return pTime->i64NanosecondsRelativeToUnixEpoch;
74}
75
76
77/**
78 * Sets the time give by nanoseconds relative to the unix epoch.
79 *
80 * @returns pTime.
81 * @param pTime The time spec to modify.
82 * @param i64Nano The new time in nanoseconds.
83 */
84DECLINLINE(PRTTIMESPEC) RTTimeSpecSetNano(PRTTIMESPEC pTime, int64_t i64Nano)
85{
86 pTime->i64NanosecondsRelativeToUnixEpoch = i64Nano;
87 return pTime;
88}
89
90
91/**
92 * Gets the time as microseconds relative to the unix epoch.
93 *
94 * @returns microseconds relative to unix epoch.
95 * @param pTime The time spec to interpret.
96 */
97DECLINLINE(int64_t) RTTimeSpecGetMicro(PCRTTIMESPEC pTime)
98{
99 return pTime->i64NanosecondsRelativeToUnixEpoch / RT_NS_1US;
100}
101
102
103/**
104 * Sets the time given by microseconds relative to the unix epoch.
105 *
106 * @returns pTime.
107 * @param pTime The time spec to modify.
108 * @param i64Micro The new time in microsecond.
109 */
110DECLINLINE(PRTTIMESPEC) RTTimeSpecSetMicro(PRTTIMESPEC pTime, int64_t i64Micro)
111{
112 pTime->i64NanosecondsRelativeToUnixEpoch = i64Micro * RT_NS_1US;
113 return pTime;
114}
115
116
117/**
118 * Gets the time as milliseconds relative to the unix epoch.
119 *
120 * @returns milliseconds relative to unix epoch.
121 * @param pTime The time spec to interpret.
122 */
123DECLINLINE(int64_t) RTTimeSpecGetMilli(PCRTTIMESPEC pTime)
124{
125 return pTime->i64NanosecondsRelativeToUnixEpoch / RT_NS_1MS;
126}
127
128
129/**
130 * Sets the time given by milliseconds relative to the unix epoch.
131 *
132 * @returns pTime.
133 * @param pTime The time spec to modify.
134 * @param i64Milli The new time in milliseconds.
135 */
136DECLINLINE(PRTTIMESPEC) RTTimeSpecSetMilli(PRTTIMESPEC pTime, int64_t i64Milli)
137{
138 pTime->i64NanosecondsRelativeToUnixEpoch = i64Milli * RT_NS_1MS;
139 return pTime;
140}
141
142
143/**
144 * Gets the time as seconds relative to the unix epoch.
145 *
146 * @returns seconds relative to unix epoch.
147 * @param pTime The time spec to interpret.
148 */
149DECLINLINE(int64_t) RTTimeSpecGetSeconds(PCRTTIMESPEC pTime)
150{
151 return pTime->i64NanosecondsRelativeToUnixEpoch / RT_NS_1SEC;
152}
153
154
155/**
156 * Sets the time given by seconds relative to the unix epoch.
157 *
158 * @returns pTime.
159 * @param pTime The time spec to modify.
160 * @param i64Seconds The new time in seconds.
161 */
162DECLINLINE(PRTTIMESPEC) RTTimeSpecSetSeconds(PRTTIMESPEC pTime, int64_t i64Seconds)
163{
164 pTime->i64NanosecondsRelativeToUnixEpoch = i64Seconds * RT_NS_1SEC;
165 return pTime;
166}
167
168
169/**
170 * Makes the time spec absolute like abs() does (i.e. a positive value).
171 *
172 * @returns pTime.
173 * @param pTime The time spec to modify.
174 */
175DECLINLINE(PRTTIMESPEC) RTTimeSpecAbsolute(PRTTIMESPEC pTime)
176{
177 if (pTime->i64NanosecondsRelativeToUnixEpoch < 0)
178 pTime->i64NanosecondsRelativeToUnixEpoch = -pTime->i64NanosecondsRelativeToUnixEpoch;
179 return pTime;
180}
181
182
183/**
184 * Negates the time.
185 *
186 * @returns pTime.
187 * @param pTime The time spec to modify.
188 */
189DECLINLINE(PRTTIMESPEC) RTTimeSpecNegate(PRTTIMESPEC pTime)
190{
191 pTime->i64NanosecondsRelativeToUnixEpoch = -pTime->i64NanosecondsRelativeToUnixEpoch;
192 return pTime;
193}
194
195
196/**
197 * Adds a time period to the time.
198 *
199 * @returns pTime.
200 * @param pTime The time spec to modify.
201 * @param pTimeAdd The time spec to add to pTime.
202 */
203DECLINLINE(PRTTIMESPEC) RTTimeSpecAdd(PRTTIMESPEC pTime, PCRTTIMESPEC pTimeAdd)
204{
205 pTime->i64NanosecondsRelativeToUnixEpoch += pTimeAdd->i64NanosecondsRelativeToUnixEpoch;
206 return pTime;
207}
208
209
210/**
211 * Adds a time period give as nanoseconds from the time.
212 *
213 * @returns pTime.
214 * @param pTime The time spec to modify.
215 * @param i64Nano The time period in nanoseconds.
216 */
217DECLINLINE(PRTTIMESPEC) RTTimeSpecAddNano(PRTTIMESPEC pTime, int64_t i64Nano)
218{
219 pTime->i64NanosecondsRelativeToUnixEpoch += i64Nano;
220 return pTime;
221}
222
223
224/**
225 * Adds a time period give as microseconds from the time.
226 *
227 * @returns pTime.
228 * @param pTime The time spec to modify.
229 * @param i64Micro The time period in microseconds.
230 */
231DECLINLINE(PRTTIMESPEC) RTTimeSpecAddMicro(PRTTIMESPEC pTime, int64_t i64Micro)
232{
233 pTime->i64NanosecondsRelativeToUnixEpoch += i64Micro * RT_NS_1US;
234 return pTime;
235}
236
237
238/**
239 * Adds a time period give as milliseconds from the time.
240 *
241 * @returns pTime.
242 * @param pTime The time spec to modify.
243 * @param i64Milli The time period in milliseconds.
244 */
245DECLINLINE(PRTTIMESPEC) RTTimeSpecAddMilli(PRTTIMESPEC pTime, int64_t i64Milli)
246{
247 pTime->i64NanosecondsRelativeToUnixEpoch += i64Milli * RT_NS_1MS;
248 return pTime;
249}
250
251
252/**
253 * Adds a time period give as seconds from the time.
254 *
255 * @returns pTime.
256 * @param pTime The time spec to modify.
257 * @param i64Seconds The time period in seconds.
258 */
259DECLINLINE(PRTTIMESPEC) RTTimeSpecAddSeconds(PRTTIMESPEC pTime, int64_t i64Seconds)
260{
261 pTime->i64NanosecondsRelativeToUnixEpoch += i64Seconds * RT_NS_1SEC;
262 return pTime;
263}
264
265
266/**
267 * Subtracts a time period from the time.
268 *
269 * @returns pTime.
270 * @param pTime The time spec to modify.
271 * @param pTimeSub The time spec to subtract from pTime.
272 */
273DECLINLINE(PRTTIMESPEC) RTTimeSpecSub(PRTTIMESPEC pTime, PCRTTIMESPEC pTimeSub)
274{
275 pTime->i64NanosecondsRelativeToUnixEpoch -= pTimeSub->i64NanosecondsRelativeToUnixEpoch;
276 return pTime;
277}
278
279
280/**
281 * Subtracts a time period give as nanoseconds from the time.
282 *
283 * @returns pTime.
284 * @param pTime The time spec to modify.
285 * @param i64Nano The time period in nanoseconds.
286 */
287DECLINLINE(PRTTIMESPEC) RTTimeSpecSubNano(PRTTIMESPEC pTime, int64_t i64Nano)
288{
289 pTime->i64NanosecondsRelativeToUnixEpoch -= i64Nano;
290 return pTime;
291}
292
293
294/**
295 * Subtracts a time period give as microseconds from the time.
296 *
297 * @returns pTime.
298 * @param pTime The time spec to modify.
299 * @param i64Micro The time period in microseconds.
300 */
301DECLINLINE(PRTTIMESPEC) RTTimeSpecSubMicro(PRTTIMESPEC pTime, int64_t i64Micro)
302{
303 pTime->i64NanosecondsRelativeToUnixEpoch -= i64Micro * RT_NS_1US;
304 return pTime;
305}
306
307
308/**
309 * Subtracts a time period give as milliseconds from the time.
310 *
311 * @returns pTime.
312 * @param pTime The time spec to modify.
313 * @param i64Milli The time period in milliseconds.
314 */
315DECLINLINE(PRTTIMESPEC) RTTimeSpecSubMilli(PRTTIMESPEC pTime, int64_t i64Milli)
316{
317 pTime->i64NanosecondsRelativeToUnixEpoch -= i64Milli * RT_NS_1MS;
318 return pTime;
319}
320
321
322/**
323 * Subtracts a time period give as seconds from the time.
324 *
325 * @returns pTime.
326 * @param pTime The time spec to modify.
327 * @param i64Seconds The time period in seconds.
328 */
329DECLINLINE(PRTTIMESPEC) RTTimeSpecSubSeconds(PRTTIMESPEC pTime, int64_t i64Seconds)
330{
331 pTime->i64NanosecondsRelativeToUnixEpoch -= i64Seconds * RT_NS_1SEC;
332 return pTime;
333}
334
335
336/**
337 * Gives the time in seconds and nanoseconds.
338 *
339 * @returns pTime.
340 * @param pTime The time spec to interpret.
341 * @param *pi32Seconds Where to store the time period in seconds.
342 * @param *pi32Nano Where to store the time period in nanoseconds.
343 */
344DECLINLINE(void) RTTimeSpecGetSecondsAndNano(PRTTIMESPEC pTime, int32_t *pi32Seconds, int32_t *pi32Nano)
345{
346 int64_t i64 = RTTimeSpecGetNano(pTime);
347 int32_t i32Nano = (int32_t)(i64 % RT_NS_1SEC);
348 i64 /= RT_NS_1SEC;
349 if (i32Nano < 0)
350 {
351 i32Nano += RT_NS_1SEC;
352 i64--;
353 }
354 *pi32Seconds = (int32_t)i64;
355 *pi32Nano = i32Nano;
356}
357
358
359/* PORTME: Add struct timeval guard macro here. */
360/*
361 * Starting with Linux kernel version 5.6-rc3, the struct timeval is no longer
362 * available to kernel code and must not be used in kernel code.
363 * Only 64-bit time-interfaces are allowed into the kernel.
364 */
365#if defined(RT_OS_LINUX) && (defined(__KERNEL__) || defined(_LINUX_TIME64_H))
366#define RTTIME_NO_TIMEVAL
367#endif
368#if !defined(RTTIME_NO_TIMEVAL) \
369 && (defined(RTTIME_INCL_TIMEVAL) || defined(_STRUCT_TIMEVAL) || defined(_SYS__TIMEVAL_H_) \
370 || defined(_SYS_TIME_H) || defined(_TIMEVAL) || defined(_LINUX_TIME_H) \
371 || (defined(RT_OS_NETBSD) && defined(_SYS_TIME_H_)))
372/**
373 * Gets the time as POSIX timeval.
374 *
375 * @returns pTime.
376 * @param pTime The time spec to interpret.
377 * @param pTimeval Where to store the time as POSIX timeval.
378 */
379DECLINLINE(struct timeval *) RTTimeSpecGetTimeval(PCRTTIMESPEC pTime, struct timeval *pTimeval)
380{
381 int64_t i64 = RTTimeSpecGetMicro(pTime);
382 int32_t i32Micro = (int32_t)(i64 % RT_US_1SEC);
383 i64 /= RT_US_1SEC;
384 if (i32Micro < 0)
385 {
386 i32Micro += RT_US_1SEC;
387 i64--;
388 }
389 pTimeval->tv_sec = (time_t)i64;
390 pTimeval->tv_usec = i32Micro;
391 return pTimeval;
392}
393
394/**
395 * Sets the time as POSIX timeval.
396 *
397 * @returns pTime.
398 * @param pTime The time spec to modify.
399 * @param pTimeval Pointer to the POSIX timeval struct with the new time.
400 */
401DECLINLINE(PRTTIMESPEC) RTTimeSpecSetTimeval(PRTTIMESPEC pTime, const struct timeval *pTimeval)
402{
403 return RTTimeSpecAddMicro(RTTimeSpecSetSeconds(pTime, pTimeval->tv_sec), pTimeval->tv_usec);
404}
405#endif /* various ways of detecting struct timeval */
406
407
408/* PORTME: Add struct timespec guard macro here. */
409#if defined(RTTIME_INCL_TIMESPEC) || defined(_STRUCT_TIMESPEC) || defined(_SYS__TIMESPEC_H_) || defined(TIMEVAL_TO_TIMESPEC) || defined(_TIMESPEC) \
410 || (defined(RT_OS_NETBSD) && defined(_SYS_TIME_H_))
411/**
412 * Gets the time as POSIX timespec.
413 *
414 * @returns pTime.
415 * @param pTime The time spec to interpret.
416 * @param pTimespec Where to store the time as POSIX timespec.
417 */
418DECLINLINE(struct timespec *) RTTimeSpecGetTimespec(PCRTTIMESPEC pTime, struct timespec *pTimespec)
419{
420 int64_t i64 = RTTimeSpecGetNano(pTime);
421 int32_t i32Nano = (int32_t)(i64 % RT_NS_1SEC);
422 i64 /= RT_NS_1SEC;
423 if (i32Nano < 0)
424 {
425 i32Nano += RT_NS_1SEC;
426 i64--;
427 }
428 pTimespec->tv_sec = (time_t)i64;
429 pTimespec->tv_nsec = i32Nano;
430 return pTimespec;
431}
432
433/**
434 * Sets the time as POSIX timespec.
435 *
436 * @returns pTime.
437 * @param pTime The time spec to modify.
438 * @param pTimespec Pointer to the POSIX timespec struct with the new time.
439 */
440DECLINLINE(PRTTIMESPEC) RTTimeSpecSetTimespec(PRTTIMESPEC pTime, const struct timespec *pTimespec)
441{
442 return RTTimeSpecAddNano(RTTimeSpecSetSeconds(pTime, pTimespec->tv_sec), pTimespec->tv_nsec);
443}
444#endif /* various ways of detecting struct timespec */
445
446#if defined(RT_OS_LINUX) && defined(_LINUX_TIME64_H)
447/*
448 * Starting with Linux kernel version 5.6-rc3, the _STRUCT_TIMESPEC is only defined
449 * under !__KERNEL__ guard and _LINUX_TIME64_H does not define a corresponding
450 * _STRUCT_TIMESPEC64. Only 64-bit time-interfaces are now allowed into the kernel.
451 */
452DECLINLINE(PRTTIMESPEC) RTTimeSpecSetTimespec64(PRTTIMESPEC pTime, const struct timespec64 *pTimeval)
453{
454 return RTTimeSpecAddNano(RTTimeSpecSetSeconds(pTime, pTimeval->tv_sec), pTimeval->tv_nsec);
455}
456#endif /* RT_OS_LINUX && _LINUX_TIME64_H */
457
458
459
460/** The offset of the unix epoch and the base for NT time (in 100ns units).
461 * Nt time starts at 1601-01-01 00:00:00. */
462#define RTTIME_NT_TIME_OFFSET_UNIX (116444736000000000LL)
463
464
465/**
466 * Gets the time as NT time.
467 *
468 * @returns Nt time.
469 * @param pTime The time spec to interpret.
470 */
471DECLINLINE(uint64_t) RTTimeSpecGetNtTime(PCRTTIMESPEC pTime)
472{
473 return pTime->i64NanosecondsRelativeToUnixEpoch / 100
474 + RTTIME_NT_TIME_OFFSET_UNIX;
475}
476
477
478/**
479 * Sets the time given by Nt time.
480 *
481 * @returns pTime.
482 * @param pTime The time spec to modify.
483 * @param u64NtTime The new time in Nt time.
484 */
485DECLINLINE(PRTTIMESPEC) RTTimeSpecSetNtTime(PRTTIMESPEC pTime, uint64_t u64NtTime)
486{
487 pTime->i64NanosecondsRelativeToUnixEpoch =
488 ((int64_t)u64NtTime - RTTIME_NT_TIME_OFFSET_UNIX) * 100;
489 return pTime;
490}
491
492
493#ifdef _FILETIME_
494/**
495 * Gets the time as NT file time.
496 *
497 * @returns pFileTime.
498 * @param pTime The time spec to interpret.
499 * @param pFileTime Pointer to NT filetime structure.
500 */
501DECLINLINE(PFILETIME) RTTimeSpecGetNtFileTime(PCRTTIMESPEC pTime, PFILETIME pFileTime)
502{
503 *((uint64_t *)pFileTime) = RTTimeSpecGetNtTime(pTime);
504 return pFileTime;
505}
506
507/**
508 * Sets the time as NT file time.
509 *
510 * @returns pTime.
511 * @param pTime The time spec to modify.
512 * @param pFileTime Where to store the time as Nt file time.
513 */
514DECLINLINE(PRTTIMESPEC) RTTimeSpecSetNtFileTime(PRTTIMESPEC pTime, const FILETIME *pFileTime)
515{
516 return RTTimeSpecSetNtTime(pTime, *(const uint64_t *)pFileTime);
517}
518#endif
519
520
521/** The offset to the start of DOS time.
522 * DOS time starts 1980-01-01 00:00:00. */
523#define RTTIME_OFFSET_DOS_TIME (315532800000000000LL)
524
525
526/**
527 * Gets the time as seconds relative to the start of dos time.
528 *
529 * @returns seconds relative to the start of dos time.
530 * @param pTime The time spec to interpret.
531 */
532DECLINLINE(int64_t) RTTimeSpecGetDosSeconds(PCRTTIMESPEC pTime)
533{
534 return (pTime->i64NanosecondsRelativeToUnixEpoch - RTTIME_OFFSET_DOS_TIME)
535 / RT_NS_1SEC;
536}
537
538
539/**
540 * Sets the time given by seconds relative to the start of dos time.
541 *
542 * @returns pTime.
543 * @param pTime The time spec to modify.
544 * @param i64Seconds The new time in seconds relative to the start of dos time.
545 */
546DECLINLINE(PRTTIMESPEC) RTTimeSpecSetDosSeconds(PRTTIMESPEC pTime, int64_t i64Seconds)
547{
548 pTime->i64NanosecondsRelativeToUnixEpoch = i64Seconds * RT_NS_1SEC
549 + RTTIME_OFFSET_DOS_TIME;
550 return pTime;
551}
552
553
554/**
555 * Compare two time specs.
556 *
557 * @returns true they are equal.
558 * @returns false they are not equal.
559 * @param pTime1 The 1st time spec.
560 * @param pTime2 The 2nd time spec.
561 */
562DECLINLINE(bool) RTTimeSpecIsEqual(PCRTTIMESPEC pTime1, PCRTTIMESPEC pTime2)
563{
564 return pTime1->i64NanosecondsRelativeToUnixEpoch == pTime2->i64NanosecondsRelativeToUnixEpoch;
565}
566
567
568/**
569 * Compare two time specs.
570 *
571 * @returns 0 if equal, -1 if @a pLeft is smaller, 1 if @a pLeft is larger.
572 * @returns false they are not equal.
573 * @param pLeft The 1st time spec.
574 * @param pRight The 2nd time spec.
575 */
576DECLINLINE(int) RTTimeSpecCompare(PCRTTIMESPEC pLeft, PCRTTIMESPEC pRight)
577{
578 if (pLeft->i64NanosecondsRelativeToUnixEpoch == pRight->i64NanosecondsRelativeToUnixEpoch)
579 return 0;
580 return pLeft->i64NanosecondsRelativeToUnixEpoch < pRight->i64NanosecondsRelativeToUnixEpoch ? -1 : 1;
581}
582
583
584/**
585 * Converts a time spec to a ISO date string.
586 *
587 * @returns psz on success.
588 * @returns NULL on buffer underflow.
589 * @param pTime The time spec.
590 * @param psz Where to store the string.
591 * @param cb The size of the buffer.
592 */
593RTDECL(char *) RTTimeSpecToString(PCRTTIMESPEC pTime, char *psz, size_t cb);
594
595/**
596 * Attempts to convert an ISO date string to a time structure.
597 *
598 * We're a little forgiving with zero padding, unspecified parts, and leading
599 * and trailing spaces.
600 *
601 * @retval pTime on success,
602 * @retval NULL on failure.
603 * @param pTime The time spec.
604 * @param pszString The ISO date string to convert.
605 */
606RTDECL(PRTTIMESPEC) RTTimeSpecFromString(PRTTIMESPEC pTime, const char *pszString);
607
608/** @} */
609
610
611/**
612 * Exploded time.
613 */
614typedef struct RTTIME
615{
616 /** The year number. */
617 int32_t i32Year;
618 /** The month of the year (1-12). January is 1. */
619 uint8_t u8Month;
620 /** The day of the week (0-6). Monday is 0. */
621 uint8_t u8WeekDay;
622 /** The day of the year (1-366). January the 1st is 1. */
623 uint16_t u16YearDay;
624 /** The day of the month (1-31). */
625 uint8_t u8MonthDay;
626 /** Hour of the day (0-23). */
627 uint8_t u8Hour;
628 /** The minute of the hour (0-59). */
629 uint8_t u8Minute;
630 /** The second of the minute (0-60).
631 * (u32Nanosecond / 1000000) */
632 uint8_t u8Second;
633 /** The nanoseconds of the second (0-999999999). */
634 uint32_t u32Nanosecond;
635 /** Flags, of the RTTIME_FLAGS_* \#defines. */
636 uint32_t fFlags;
637 /** UCT time offset in minutes (-840-840). Positive for timezones east of
638 * UTC, negative for zones to the west. Same as what RTTimeLocalDeltaNano
639 * & RTTimeLocalDeltaNanoFor returns, just different unit. */
640 int32_t offUTC;
641} RTTIME;
642AssertCompileSize(RTTIME, 24);
643/** Pointer to a exploded time structure. */
644typedef RTTIME *PRTTIME;
645/** Pointer to a const exploded time structure. */
646typedef const RTTIME *PCRTTIME;
647
648/** @name RTTIME::fFlags values.
649 * @{ */
650/** Set if the time is UTC. If clear the time local time. */
651#define RTTIME_FLAGS_TYPE_MASK 3
652/** the time is UTC time. */
653#define RTTIME_FLAGS_TYPE_UTC 2
654/** The time is local time. */
655#define RTTIME_FLAGS_TYPE_LOCAL 3
656
657/** Set if the time is local and daylight saving time is in effect.
658 * Not bit is not valid if RTTIME_FLAGS_NO_DST_DATA is set. */
659#define RTTIME_FLAGS_DST RT_BIT(4)
660/** Set if the time is local and there is no data available on daylight saving time. */
661#define RTTIME_FLAGS_NO_DST_DATA RT_BIT(5)
662/** Set if the year is a leap year.
663 * This is mutual exclusiv with RTTIME_FLAGS_COMMON_YEAR. */
664#define RTTIME_FLAGS_LEAP_YEAR RT_BIT(6)
665/** Set if the year is a common year.
666 * This is mutual exclusiv with RTTIME_FLAGS_LEAP_YEAR. */
667#define RTTIME_FLAGS_COMMON_YEAR RT_BIT(7)
668/** The mask of valid flags. */
669#define RTTIME_FLAGS_MASK UINT32_C(0xff)
670/** @} */
671
672
673/**
674 * Gets the current system time (UTC).
675 *
676 * @returns pTime.
677 * @param pTime Where to store the time.
678 */
679RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime);
680
681/**
682 * Sets the system time.
683 *
684 * @returns IPRT status code
685 * @param pTime The new system time (UTC).
686 *
687 * @remarks This will usually fail because changing the wall time is usually
688 * requires extra privileges.
689 */
690RTDECL(int) RTTimeSet(PCRTTIMESPEC pTime);
691
692/**
693 * Explodes a time spec (UTC).
694 *
695 * @returns pTime.
696 * @param pTime Where to store the exploded time.
697 * @param pTimeSpec The time spec to exploded.
698 */
699RTDECL(PRTTIME) RTTimeExplode(PRTTIME pTime, PCRTTIMESPEC pTimeSpec);
700
701/**
702 * Implodes exploded time to a time spec (UTC).
703 *
704 * @returns pTime on success.
705 * @returns NULL if the pTime data is invalid.
706 * @param pTimeSpec Where to store the imploded UTC time.
707 * If pTime specifies a time which outside the range, maximum or
708 * minimum values will be returned.
709 * @param pTime Pointer to the exploded time to implode.
710 * The fields u8Month, u8WeekDay and u8MonthDay are not used,
711 * and all the other fields are expected to be within their
712 * bounds. Use RTTimeNormalize() to calculate u16YearDay and
713 * normalize the ranges of the fields.
714 */
715RTDECL(PRTTIMESPEC) RTTimeImplode(PRTTIMESPEC pTimeSpec, PCRTTIME pTime);
716
717/**
718 * Normalizes the fields of a time structure.
719 *
720 * It is possible to calculate year-day from month/day and vice
721 * versa. If you adjust any of of these, make sure to zero the
722 * other so you make it clear which of the fields to use. If
723 * it's ambiguous, the year-day field is used (and you get
724 * assertions in debug builds).
725 *
726 * All the time fields and the year-day or month/day fields will
727 * be adjusted for overflows. (Since all fields are unsigned, there
728 * is no underflows.) It is possible to exploit this for simple
729 * date math, though the recommended way of doing that to implode
730 * the time into a timespec and do the math on that.
731 *
732 * @returns pTime on success.
733 * @returns NULL if the data is invalid.
734 *
735 * @param pTime The time structure to normalize.
736 *
737 * @remarks This function doesn't work with local time, only with UTC time.
738 */
739RTDECL(PRTTIME) RTTimeNormalize(PRTTIME pTime);
740
741/**
742 * Gets the current local system time.
743 *
744 * @returns pTime.
745 * @param pTime Where to store the local time.
746 */
747RTDECL(PRTTIMESPEC) RTTimeLocalNow(PRTTIMESPEC pTime);
748
749/**
750 * Gets the current delta between UTC and local time.
751 *
752 * @code
753 * RTTIMESPEC LocalTime;
754 * RTTimeSpecAddNano(RTTimeNow(&LocalTime), RTTimeLocalDeltaNano());
755 * @endcode
756 *
757 * @returns Returns the nanosecond delta between UTC and local time.
758 */
759RTDECL(int64_t) RTTimeLocalDeltaNano(void);
760
761/**
762 * Gets the delta between UTC and local time at the given time.
763 *
764 * @code
765 * RTTIMESPEC LocalTime;
766 * RTTimeNow(&LocalTime);
767 * RTTimeSpecAddNano(&LocalTime, RTTimeLocalDeltaNanoFor(&LocalTime));
768 * @endcode
769 *
770 * @param pTimeSpec The time spec giving the time to get the delta for.
771 * @returns Returns the nanosecond delta between UTC and local time.
772 */
773RTDECL(int64_t) RTTimeLocalDeltaNanoFor(PCRTTIMESPEC pTimeSpec);
774
775/**
776 * Explodes a time spec to the localized timezone.
777 *
778 * @returns pTime.
779 * @param pTime Where to store the exploded time.
780 * @param pTimeSpec The time spec to exploded (UTC).
781 */
782RTDECL(PRTTIME) RTTimeLocalExplode(PRTTIME pTime, PCRTTIMESPEC pTimeSpec);
783
784/**
785 * Normalizes the fields of a time structure containing local time.
786 *
787 * See RTTimeNormalize for details.
788 *
789 * @returns pTime on success.
790 * @returns NULL if the data is invalid.
791 * @param pTime The time structure to normalize.
792 */
793RTDECL(PRTTIME) RTTimeLocalNormalize(PRTTIME pTime);
794
795/**
796 * Converts a time structure to UTC, relying on UTC offset information
797 * if it contains local time.
798 *
799 * @returns pTime on success.
800 * @returns NULL if the data is invalid.
801 * @param pTime The time structure to convert.
802 */
803RTDECL(PRTTIME) RTTimeConvertToZulu(PRTTIME pTime);
804
805/**
806 * Converts a time spec to a ISO date string.
807 *
808 * @returns psz on success.
809 * @returns NULL on buffer underflow.
810 * @param pTime The time. Caller should've normalized this.
811 * @param psz Where to store the string.
812 * @param cb The size of the buffer.
813 */
814RTDECL(char *) RTTimeToString(PCRTTIME pTime, char *psz, size_t cb);
815
816/**
817 * Converts a time spec to a ISO date string, extended version.
818 *
819 * @returns Output string length on success (positive), VERR_BUFFER_OVERFLOW
820 * (negative) or VERR_OUT_OF_RANGE (negative) on failure.
821 * @param pTime The time. Caller should've normalized this.
822 * @param psz Where to store the string.
823 * @param cb The size of the buffer.
824 * @param cFractionDigits Number of digits in the fraction. Max is 9.
825 */
826RTDECL(ssize_t) RTTimeToStringEx(PCRTTIME pTime, char *psz, size_t cb, unsigned cFractionDigits);
827
828/** Suggested buffer length for RTTimeToString and RTTimeToStringEx output, including terminator. */
829#define RTTIME_STR_LEN 40
830
831/**
832 * Attempts to convert an ISO date string to a time structure.
833 *
834 * We're a little forgiving with zero padding, unspecified parts, and leading
835 * and trailing spaces.
836 *
837 * @retval pTime on success,
838 * @retval NULL on failure.
839 * @param pTime Where to store the time on success.
840 * @param pszString The ISO date string to convert.
841 */
842RTDECL(PRTTIME) RTTimeFromString(PRTTIME pTime, const char *pszString);
843
844/**
845 * Formats the given time on a RTC-2822 compliant format.
846 *
847 * @returns Output string length on success (positive), VERR_BUFFER_OVERFLOW
848 * (negative) on failure.
849 * @param pTime The time. Caller should've normalized this.
850 * @param psz Where to store the string.
851 * @param cb The size of the buffer.
852 * @param fFlags RTTIME_RFC2822_F_XXX
853 * @sa RTTIME_RFC2822_LEN
854 */
855RTDECL(ssize_t) RTTimeToRfc2822(PRTTIME pTime, char *psz, size_t cb, uint32_t fFlags);
856
857/** Suggested buffer length for RTTimeToRfc2822 output, including terminator. */
858#define RTTIME_RFC2822_LEN 40
859/** @name RTTIME_RFC2822_F_XXX
860 * @{ */
861/** Use the deprecated GMT timezone instead of +/-0000.
862 * This is required by the HTTP RFC-7231 7.1.1.1. */
863#define RTTIME_RFC2822_F_GMT RT_BIT_32(0)
864/** @} */
865
866/**
867 * Attempts to convert an RFC-2822 date string to a time structure.
868 *
869 * We're a little forgiving with zero padding, unspecified parts, and leading
870 * and trailing spaces.
871 *
872 * @retval pTime on success,
873 * @retval NULL on failure.
874 * @param pTime Where to store the time on success.
875 * @param pszString The ISO date string to convert.
876 */
877RTDECL(PRTTIME) RTTimeFromRfc2822(PRTTIME pTime, const char *pszString);
878
879/**
880 * Checks if a year is a leap year or not.
881 *
882 * @returns true if it's a leap year.
883 * @returns false if it's a common year.
884 * @param i32Year The year in question.
885 */
886RTDECL(bool) RTTimeIsLeapYear(int32_t i32Year);
887
888/**
889 * Compares two normalized time structures.
890 *
891 * @retval 0 if equal.
892 * @retval -1 if @a pLeft is earlier than @a pRight.
893 * @retval 1 if @a pRight is earlier than @a pLeft.
894 *
895 * @param pLeft The left side time. NULL is accepted.
896 * @param pRight The right side time. NULL is accepted.
897 *
898 * @note A NULL time is considered smaller than anything else. If both are
899 * NULL, they are considered equal.
900 */
901RTDECL(int) RTTimeCompare(PCRTTIME pLeft, PCRTTIME pRight);
902
903/**
904 * Gets the current nanosecond timestamp.
905 *
906 * @returns nanosecond timestamp.
907 */
908RTDECL(uint64_t) RTTimeNanoTS(void);
909
910/**
911 * Gets the current millisecond timestamp.
912 *
913 * @returns millisecond timestamp.
914 */
915RTDECL(uint64_t) RTTimeMilliTS(void);
916
917/**
918 * Debugging the time api.
919 *
920 * @returns the number of 1ns steps which has been applied by RTTimeNanoTS().
921 */
922RTDECL(uint32_t) RTTimeDbgSteps(void);
923
924/**
925 * Debugging the time api.
926 *
927 * @returns the number of times the TSC interval expired RTTimeNanoTS().
928 */
929RTDECL(uint32_t) RTTimeDbgExpired(void);
930
931/**
932 * Debugging the time api.
933 *
934 * @returns the number of bad previous values encountered by RTTimeNanoTS().
935 */
936RTDECL(uint32_t) RTTimeDbgBad(void);
937
938/**
939 * Debugging the time api.
940 *
941 * @returns the number of update races in RTTimeNanoTS().
942 */
943RTDECL(uint32_t) RTTimeDbgRaces(void);
944
945/** @name RTTimeNanoTS GIP worker functions, for TM.
946 * @{ */
947/** Pointer to a RTTIMENANOTSDATA structure. */
948typedef struct RTTIMENANOTSDATA *PRTTIMENANOTSDATA;
949
950/**
951 * Nanosecond timestamp data.
952 *
953 * This is used to keep track of statistics and callback so IPRT
954 * and TM (VirtualBox) can share code.
955 *
956 * @remark Keep this in sync with the assembly version in timesupA.asm.
957 */
958typedef struct RTTIMENANOTSDATA
959{
960 /** Where the previous timestamp is stored.
961 * This is maintained to ensure that time doesn't go backwards or anything. */
962 uint64_t volatile *pu64Prev;
963
964 /**
965 * Helper function that's used by the assembly routines when something goes bust.
966 *
967 * @param pData Pointer to this structure.
968 * @param u64NanoTS The calculated nano ts.
969 * @param u64DeltaPrev The delta relative to the previously returned timestamp.
970 * @param u64PrevNanoTS The previously returned timestamp (as it was read it).
971 */
972 DECLCALLBACKMEMBER(void, pfnBad)(PRTTIMENANOTSDATA pData, uint64_t u64NanoTS, uint64_t u64DeltaPrev, uint64_t u64PrevNanoTS);
973
974 /**
975 * Callback for when rediscovery is required.
976 *
977 * @returns Nanosecond timestamp.
978 * @param pData Pointer to this structure.
979 */
980 DECLCALLBACKMEMBER(uint64_t, pfnRediscover)(PRTTIMENANOTSDATA pData);
981
982 /**
983 * Callback for when some CPU index related stuff goes wrong.
984 *
985 * @returns Nanosecond timestamp.
986 * @param pData Pointer to this structure.
987 * @param idApic The APIC ID if available, otherwise (UINT16_MAX-1).
988 * @param iCpuSet The CPU set index if available, otherwise
989 * (UINT16_MAX-1).
990 * @param iGipCpu The GIP CPU array index if available, otherwise
991 * (UINT16_MAX-1).
992 */
993 DECLCALLBACKMEMBER(uint64_t, pfnBadCpuIndex)(PRTTIMENANOTSDATA pData, uint16_t idApic, uint16_t iCpuSet, uint16_t iGipCpu);
994
995 /** Number of 1ns steps because of overshooting the period. */
996 uint32_t c1nsSteps;
997 /** The number of times the interval expired (overflow). */
998 uint32_t cExpired;
999 /** Number of "bad" previous values. */
1000 uint32_t cBadPrev;
1001 /** The number of update races. */
1002 uint32_t cUpdateRaces;
1003} RTTIMENANOTSDATA;
1004
1005#ifndef IN_RING3
1006/**
1007 * The Ring-3 layout of the RTTIMENANOTSDATA structure.
1008 */
1009typedef struct RTTIMENANOTSDATAR3
1010{
1011 R3PTRTYPE(uint64_t volatile *) pu64Prev;
1012 DECLR3CALLBACKMEMBER(void, pfnBad,(PRTTIMENANOTSDATA pData, uint64_t u64NanoTS, uint64_t u64DeltaPrev, uint64_t u64PrevNanoTS));
1013 DECLR3CALLBACKMEMBER(uint64_t, pfnRediscover,(PRTTIMENANOTSDATA pData));
1014 DECLR3CALLBACKMEMBER(uint64_t, pfnBadCpuIndex,(PRTTIMENANOTSDATA pData, uint16_t idApic, uint16_t iCpuSet, uint16_t iGipCpu));
1015 uint32_t c1nsSteps;
1016 uint32_t cExpired;
1017 uint32_t cBadPrev;
1018 uint32_t cUpdateRaces;
1019} RTTIMENANOTSDATAR3;
1020#else
1021typedef RTTIMENANOTSDATA RTTIMENANOTSDATAR3;
1022#endif
1023
1024#ifndef IN_RING0
1025/**
1026 * The Ring-3 layout of the RTTIMENANOTSDATA structure.
1027 */
1028typedef struct RTTIMENANOTSDATAR0
1029{
1030 R0PTRTYPE(uint64_t volatile *) pu64Prev;
1031 DECLR0CALLBACKMEMBER(void, pfnBad,(PRTTIMENANOTSDATA pData, uint64_t u64NanoTS, uint64_t u64DeltaPrev, uint64_t u64PrevNanoTS));
1032 DECLR0CALLBACKMEMBER(uint64_t, pfnRediscover,(PRTTIMENANOTSDATA pData));
1033 DECLR0CALLBACKMEMBER(uint64_t, pfnBadCpuIndex,(PRTTIMENANOTSDATA pData, uint16_t idApic, uint16_t iCpuSet, uint16_t iGipCpu));
1034 uint32_t c1nsSteps;
1035 uint32_t cExpired;
1036 uint32_t cBadPrev;
1037 uint32_t cUpdateRaces;
1038} RTTIMENANOTSDATAR0;
1039#else
1040typedef RTTIMENANOTSDATA RTTIMENANOTSDATAR0;
1041#endif
1042
1043#ifndef IN_RC
1044/**
1045 * The RC layout of the RTTIMENANOTSDATA structure.
1046 */
1047typedef struct RTTIMENANOTSDATARC
1048{
1049 RCPTRTYPE(uint64_t volatile *) pu64Prev;
1050 DECLRCCALLBACKMEMBER(void, pfnBad,(PRTTIMENANOTSDATA pData, uint64_t u64NanoTS, uint64_t u64DeltaPrev, uint64_t u64PrevNanoTS));
1051 DECLRCCALLBACKMEMBER(uint64_t, pfnRediscover,(PRTTIMENANOTSDATA pData));
1052 DECLRCCALLBACKMEMBER(uint64_t, pfnBadCpuIndex,(PRTTIMENANOTSDATA pData, uint16_t idApic, uint16_t iCpuSet, uint16_t iGipCpu));
1053 uint32_t c1nsSteps;
1054 uint32_t cExpired;
1055 uint32_t cBadPrev;
1056 uint32_t cUpdateRaces;
1057} RTTIMENANOTSDATARC;
1058#else
1059typedef RTTIMENANOTSDATA RTTIMENANOTSDATARC;
1060#endif
1061
1062/** Internal RTTimeNanoTS worker (assembly). */
1063typedef DECLCALLBACK(uint64_t) FNTIMENANOTSINTERNAL(PRTTIMENANOTSDATA pData);
1064/** Pointer to an internal RTTimeNanoTS worker (assembly). */
1065typedef FNTIMENANOTSINTERNAL *PFNTIMENANOTSINTERNAL;
1066RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarNoDelta(PRTTIMENANOTSDATA pData);
1067RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarNoDelta(PRTTIMENANOTSDATA pData);
1068#ifdef IN_RING3
1069RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseApicId(PRTTIMENANOTSDATA pData);
1070RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseApicIdExt0B(PRTTIMENANOTSDATA pData);
1071RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseApicIdExt8000001E(PRTTIMENANOTSDATA pData);
1072RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseRdtscp(PRTTIMENANOTSDATA pData);
1073RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseRdtscpGroupChNumCl(PRTTIMENANOTSDATA pData);
1074RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseIdtrLim(PRTTIMENANOTSDATA pData);
1075RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDeltaUseApicId(PRTTIMENANOTSDATA pData);
1076RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDeltaUseApicIdExt0B(PRTTIMENANOTSDATA pData);
1077RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDeltaUseApicIdExt8000001E(PRTTIMENANOTSDATA pData);
1078RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDeltaUseRdtscp(PRTTIMENANOTSDATA pData);
1079RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDeltaUseIdtrLim(PRTTIMENANOTSDATA pData);
1080RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseApicId(PRTTIMENANOTSDATA pData);
1081RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseApicIdExt0B(PRTTIMENANOTSDATA pData);
1082RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseApicIdExt8000001E(PRTTIMENANOTSDATA pData);
1083RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseRdtscp(PRTTIMENANOTSDATA pData);
1084RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseRdtscpGroupChNumCl(PRTTIMENANOTSDATA pData);
1085RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseIdtrLim(PRTTIMENANOTSDATA pData);
1086RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicId(PRTTIMENANOTSDATA pData);
1087RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicIdExt0B(PRTTIMENANOTSDATA pData);
1088RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicIdExt8000001E(PRTTIMENANOTSDATA pData);
1089RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDeltaUseRdtscp(PRTTIMENANOTSDATA pData);
1090RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDeltaUseIdtrLim(PRTTIMENANOTSDATA pData);
1091#else
1092RTDECL(uint64_t) RTTimeNanoTSLegacyAsync(PRTTIMENANOTSDATA pData);
1093RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDelta(PRTTIMENANOTSDATA pData);
1094RTDECL(uint64_t) RTTimeNanoTSLFenceAsync(PRTTIMENANOTSDATA pData);
1095RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDelta(PRTTIMENANOTSDATA pData);
1096#endif
1097
1098/** @} */
1099
1100
1101/**
1102 * Gets the current nanosecond timestamp.
1103 *
1104 * This differs from RTTimeNanoTS in that it will use system APIs and not do any
1105 * resolution or performance optimizations.
1106 *
1107 * @returns nanosecond timestamp.
1108 */
1109RTDECL(uint64_t) RTTimeSystemNanoTS(void);
1110
1111/**
1112 * Gets the current millisecond timestamp.
1113 *
1114 * This differs from RTTimeNanoTS in that it will use system APIs and not do any
1115 * resolution or performance optimizations.
1116 *
1117 * @returns millisecond timestamp.
1118 */
1119RTDECL(uint64_t) RTTimeSystemMilliTS(void);
1120
1121/**
1122 * Get the nanosecond timestamp relative to program startup.
1123 *
1124 * @returns Timestamp relative to program startup.
1125 */
1126RTDECL(uint64_t) RTTimeProgramNanoTS(void);
1127
1128/**
1129 * Get the microsecond timestamp relative to program startup.
1130 *
1131 * @returns Timestamp relative to program startup.
1132 */
1133RTDECL(uint64_t) RTTimeProgramMicroTS(void);
1134
1135/**
1136 * Get the millisecond timestamp relative to program startup.
1137 *
1138 * @returns Timestamp relative to program startup.
1139 */
1140RTDECL(uint64_t) RTTimeProgramMilliTS(void);
1141
1142/**
1143 * Get the second timestamp relative to program startup.
1144 *
1145 * @returns Timestamp relative to program startup.
1146 */
1147RTDECL(uint32_t) RTTimeProgramSecTS(void);
1148
1149/**
1150 * Get the RTTimeNanoTS() of when the program started.
1151 *
1152 * @returns Program startup timestamp.
1153 */
1154RTDECL(uint64_t) RTTimeProgramStartNanoTS(void);
1155
1156
1157/**
1158 * Time zone information.
1159 */
1160typedef struct RTTIMEZONEINFO
1161{
1162 /** Unix time zone name (continent/country[/city]|). */
1163 const char *pszUnixName;
1164 /** Windows time zone name. */
1165 const char *pszWindowsName;
1166 /** The length of the unix time zone name. */
1167 uint8_t cchUnixName;
1168 /** The length of the windows time zone name. */
1169 uint8_t cchWindowsName;
1170 /** Two letter country/territory code if applicable, otherwise 'ZZ'. */
1171 char szCountry[3];
1172 /** Two letter windows country/territory code if applicable.
1173 * Empty string if no windows mapping. */
1174 char szWindowsCountry[3];
1175#if 0 /* Add when needed and it's been extracted. */
1176 /** The standard delta in minutes (add to UTC). */
1177 int16_t cMinStdDelta;
1178 /** The daylight saving time delta in minutes (add to UTC). */
1179 int16_t cMinDstDelta;
1180#endif
1181 /** closest matching windows time zone index. */
1182 uint32_t idxWindows;
1183 /** Flags, RTTIMEZONEINFO_F_XXX. */
1184 uint32_t fFlags;
1185} RTTIMEZONEINFO;
1186/** Pointer to time zone info. */
1187typedef RTTIMEZONEINFO const *PCRTTIMEZONEINFO;
1188
1189/** @name RTTIMEZONEINFO_F_XXX - time zone info flags.
1190 * @{ */
1191/** Indicates golden mapping entry for a windows time zone name. */
1192#define RTTIMEZONEINFO_F_GOLDEN RT_BIT_32(0)
1193/** @} */
1194
1195/**
1196 * Looks up static time zone information by unix name.
1197 *
1198 * @returns Pointer to info entry if found, NULL if not.
1199 * @param pszName The unix zone name (TZ).
1200 */
1201RTDECL(PCRTTIMEZONEINFO) RTTimeZoneGetInfoByUnixName(const char *pszName);
1202
1203/**
1204 * Looks up static time zone information by window name.
1205 *
1206 * @returns Pointer to info entry if found, NULL if not.
1207 * @param pszName The windows zone name (reg key).
1208 */
1209RTDECL(PCRTTIMEZONEINFO) RTTimeZoneGetInfoByWindowsName(const char *pszName);
1210
1211/**
1212 * Looks up static time zone information by windows index.
1213 *
1214 * @returns Pointer to info entry if found, NULL if not.
1215 * @param idxZone The windows timezone index.
1216 */
1217RTDECL(PCRTTIMEZONEINFO) RTTimeZoneGetInfoByWindowsIndex(uint32_t idxZone);
1218
1219/**
1220 * Get the current time zone (TZ).
1221 *
1222 * @returns IPRT status code.
1223 * @param pszName Where to return the time zone name.
1224 * @param cbName The size of the name buffer.
1225 */
1226RTDECL(int) RTTimeZoneGetCurrent(char *pszName, size_t cbName);
1227
1228/** @} */
1229
1230RT_C_DECLS_END
1231
1232#endif /* !IPRT_INCLUDED_time_h */
1233
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette