6 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
36 #ifndef IPRT_INCLUDED_time_h
37 #define IPRT_INCLUDED_time_h
38 #ifndef RT_WITHOUT_PRAGMA_ONCE
42 #include <iprt/cdefs.h>
43 #include <iprt/types.h>
44 #include <iprt/assertcompile.h>
48 /** @defgroup grp_rt_time RTTime - Time
53 /** Time Specification.
55 * Use the inline RTTimeSpecGet/Set to operate on structure this so we
56 * can easily change the representation if required later.
58 * The current representation is in nanoseconds relative to the unix epoch
59 * (1970-01-01 00:00:00 UTC). This gives us an approximate span from
60 * 1678 to 2262 without sacrificing the resolution offered by the various
61 * host OSes (BSD & LINUX 1ns, NT 100ns).
63 typedef struct RTTIMESPEC
65 /** Nanoseconds since epoch.
66 * The name is intentially too long to be comfortable to use because you should be
67 * using inline helpers! */
68 int64_t i64NanosecondsRelativeToUnixEpoch
;
72 /** @name RTTIMESPEC methods
76 * Gets the time as nanoseconds relative to the unix epoch.
78 * @returns Nanoseconds relative to unix epoch.
79 * @param pTime The time spec to interpret.
81 DECLINLINE(int64_t) RTTimeSpecGetNano(PCRTTIMESPEC pTime
)
83 return pTime
->i64NanosecondsRelativeToUnixEpoch
;
88 * Sets the time give by nanoseconds relative to the unix epoch.
91 * @param pTime The time spec to modify.
92 * @param i64Nano The new time in nanoseconds.
94 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSetNano(PRTTIMESPEC pTime
, int64_t i64Nano
)
96 pTime
->i64NanosecondsRelativeToUnixEpoch
= i64Nano
;
102 * Gets the time as microseconds relative to the unix epoch.
104 * @returns microseconds relative to unix epoch.
105 * @param pTime The time spec to interpret.
107 DECLINLINE(int64_t) RTTimeSpecGetMicro(PCRTTIMESPEC pTime
)
109 return pTime
->i64NanosecondsRelativeToUnixEpoch
/ RT_NS_1US
;
114 * Sets the time given by microseconds relative to the unix epoch.
117 * @param pTime The time spec to modify.
118 * @param i64Micro The new time in microsecond.
120 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSetMicro(PRTTIMESPEC pTime
, int64_t i64Micro
)
122 pTime
->i64NanosecondsRelativeToUnixEpoch
= i64Micro
* RT_NS_1US
;
128 * Gets the time as milliseconds relative to the unix epoch.
130 * @returns milliseconds relative to unix epoch.
131 * @param pTime The time spec to interpret.
133 DECLINLINE(int64_t) RTTimeSpecGetMilli(PCRTTIMESPEC pTime
)
135 return pTime
->i64NanosecondsRelativeToUnixEpoch
/ RT_NS_1MS
;
140 * Sets the time given by milliseconds relative to the unix epoch.
143 * @param pTime The time spec to modify.
144 * @param i64Milli The new time in milliseconds.
146 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSetMilli(PRTTIMESPEC pTime
, int64_t i64Milli
)
148 pTime
->i64NanosecondsRelativeToUnixEpoch
= i64Milli
* RT_NS_1MS
;
154 * Gets the time as seconds relative to the unix epoch.
156 * @returns seconds relative to unix epoch.
157 * @param pTime The time spec to interpret.
159 DECLINLINE(int64_t) RTTimeSpecGetSeconds(PCRTTIMESPEC pTime
)
161 return pTime
->i64NanosecondsRelativeToUnixEpoch
/ RT_NS_1SEC
;
166 * Sets the time given by seconds relative to the unix epoch.
169 * @param pTime The time spec to modify.
170 * @param i64Seconds The new time in seconds.
172 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSetSeconds(PRTTIMESPEC pTime
, int64_t i64Seconds
)
174 pTime
->i64NanosecondsRelativeToUnixEpoch
= i64Seconds
* RT_NS_1SEC
;
180 * Makes the time spec absolute like abs() does (i.e. a positive value).
183 * @param pTime The time spec to modify.
185 DECLINLINE(PRTTIMESPEC
) RTTimeSpecAbsolute(PRTTIMESPEC pTime
)
187 if (pTime
->i64NanosecondsRelativeToUnixEpoch
< 0)
188 pTime
->i64NanosecondsRelativeToUnixEpoch
= -pTime
->i64NanosecondsRelativeToUnixEpoch
;
197 * @param pTime The time spec to modify.
199 DECLINLINE(PRTTIMESPEC
) RTTimeSpecNegate(PRTTIMESPEC pTime
)
201 pTime
->i64NanosecondsRelativeToUnixEpoch
= -pTime
->i64NanosecondsRelativeToUnixEpoch
;
207 * Adds a time period to the time.
210 * @param pTime The time spec to modify.
211 * @param pTimeAdd The time spec to add to pTime.
213 DECLINLINE(PRTTIMESPEC
) RTTimeSpecAdd(PRTTIMESPEC pTime
, PCRTTIMESPEC pTimeAdd
)
215 pTime
->i64NanosecondsRelativeToUnixEpoch
+= pTimeAdd
->i64NanosecondsRelativeToUnixEpoch
;
221 * Adds a time period give as nanoseconds from the time.
224 * @param pTime The time spec to modify.
225 * @param i64Nano The time period in nanoseconds.
227 DECLINLINE(PRTTIMESPEC
) RTTimeSpecAddNano(PRTTIMESPEC pTime
, int64_t i64Nano
)
229 pTime
->i64NanosecondsRelativeToUnixEpoch
+= i64Nano
;
235 * Adds a time period give as microseconds from the time.
238 * @param pTime The time spec to modify.
239 * @param i64Micro The time period in microseconds.
241 DECLINLINE(PRTTIMESPEC
) RTTimeSpecAddMicro(PRTTIMESPEC pTime
, int64_t i64Micro
)
243 pTime
->i64NanosecondsRelativeToUnixEpoch
+= i64Micro
* RT_NS_1US
;
249 * Adds a time period give as milliseconds from the time.
252 * @param pTime The time spec to modify.
253 * @param i64Milli The time period in milliseconds.
255 DECLINLINE(PRTTIMESPEC
) RTTimeSpecAddMilli(PRTTIMESPEC pTime
, int64_t i64Milli
)
257 pTime
->i64NanosecondsRelativeToUnixEpoch
+= i64Milli
* RT_NS_1MS
;
263 * Adds a time period give as seconds from the time.
266 * @param pTime The time spec to modify.
267 * @param i64Seconds The time period in seconds.
269 DECLINLINE(PRTTIMESPEC
) RTTimeSpecAddSeconds(PRTTIMESPEC pTime
, int64_t i64Seconds
)
271 pTime
->i64NanosecondsRelativeToUnixEpoch
+= i64Seconds
* RT_NS_1SEC
;
277 * Subtracts a time period from the time.
280 * @param pTime The time spec to modify.
281 * @param pTimeSub The time spec to subtract from pTime.
283 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSub(PRTTIMESPEC pTime
, PCRTTIMESPEC pTimeSub
)
285 pTime
->i64NanosecondsRelativeToUnixEpoch
-= pTimeSub
->i64NanosecondsRelativeToUnixEpoch
;
291 * Subtracts a time period give as nanoseconds from the time.
294 * @param pTime The time spec to modify.
295 * @param i64Nano The time period in nanoseconds.
297 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSubNano(PRTTIMESPEC pTime
, int64_t i64Nano
)
299 pTime
->i64NanosecondsRelativeToUnixEpoch
-= i64Nano
;
305 * Subtracts a time period give as microseconds from the time.
308 * @param pTime The time spec to modify.
309 * @param i64Micro The time period in microseconds.
311 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSubMicro(PRTTIMESPEC pTime
, int64_t i64Micro
)
313 pTime
->i64NanosecondsRelativeToUnixEpoch
-= i64Micro
* RT_NS_1US
;
319 * Subtracts a time period give as milliseconds from the time.
322 * @param pTime The time spec to modify.
323 * @param i64Milli The time period in milliseconds.
325 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSubMilli(PRTTIMESPEC pTime
, int64_t i64Milli
)
327 pTime
->i64NanosecondsRelativeToUnixEpoch
-= i64Milli
* RT_NS_1MS
;
333 * Subtracts a time period give as seconds from the time.
336 * @param pTime The time spec to modify.
337 * @param i64Seconds The time period in seconds.
339 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSubSeconds(PRTTIMESPEC pTime
, int64_t i64Seconds
)
341 pTime
->i64NanosecondsRelativeToUnixEpoch
-= i64Seconds
* RT_NS_1SEC
;
347 * Gives the time in seconds and nanoseconds.
349 * @param pTime The time spec to interpret.
350 * @param *pi32Seconds Where to store the time period in seconds.
351 * @param *pi32Nano Where to store the time period in nanoseconds.
353 DECLINLINE(void) RTTimeSpecGetSecondsAndNano(PRTTIMESPEC pTime
, int32_t *pi32Seconds
, int32_t *pi32Nano
)
355 int64_t i64
= RTTimeSpecGetNano(pTime
);
356 int32_t i32Nano
= (int32_t)(i64
% RT_NS_1SEC
);
360 i32Nano
+= RT_NS_1SEC
;
363 *pi32Seconds
= (int32_t)i64
;
367 /** @def RTTIME_LINUX_KERNEL_PREREQ
368 * Prerequisite minimum linux kernel version.
369 * @note Cannot really be moved to iprt/cdefs.h, see the-linux-kernel.h */
370 /** @def RTTIME_LINUX_KERNEL_PREREQ_LT
371 * Prerequisite maxium linux kernel version (LT=less-than).
372 * @note Cannot really be moved to iprt/cdefs.h, see the-linux-kernel.h */
373 #if defined(RT_OS_LINUX) && defined(LINUX_VERSION_CODE) && defined(KERNEL_VERSION)
374 # define RTTIME_LINUX_KERNEL_PREREQ(a, b, c) (LINUX_VERSION_CODE >= KERNEL_VERSION(a, b, c))
375 # define RTTIME_LINUX_KERNEL_PREREQ_LT(a, b, c) (!RTTIME_LINUX_KERNEL_PREREQ(a, b, c))
377 # define RTTIME_LINUX_KERNEL_PREREQ(a, b, c) 0
378 # define RTTIME_LINUX_KERNEL_PREREQ_LT(a, b, c) 0
381 /* PORTME: Add struct timeval guard macro here. */
382 #if defined(RTTIME_INCL_TIMEVAL) \
383 || defined(_SYS__TIMEVAL_H_) \
384 || defined(_SYS_TIME_H) \
385 || defined(_TIMEVAL) \
386 || defined(_STRUCT_TIMEVAL) \
387 || ( defined(RT_OS_LINUX) \
388 && defined(_LINUX_TIME_H) \
389 && ( !defined(__KERNEL__) \
390 || RTTIME_LINUX_KERNEL_PREREQ_LT(5,6,0) /* @bugref{9757} */ ) ) \
391 || (defined(RT_OS_NETBSD) && defined(_SYS_TIME_H_))
394 * Gets the time as POSIX timeval.
397 * @param pTime The time spec to interpret.
398 * @param pTimeval Where to store the time as POSIX timeval.
400 DECLINLINE(struct timeval
*) RTTimeSpecGetTimeval(PCRTTIMESPEC pTime
, struct timeval
*pTimeval
)
402 int64_t i64
= RTTimeSpecGetMicro(pTime
);
403 int32_t i32Micro
= (int32_t)(i64
% RT_US_1SEC
);
407 i32Micro
+= RT_US_1SEC
;
410 pTimeval
->tv_sec
= (time_t)i64
;
411 pTimeval
->tv_usec
= i32Micro
;
416 * Sets the time as POSIX timeval.
419 * @param pTime The time spec to modify.
420 * @param pTimeval Pointer to the POSIX timeval struct with the new time.
422 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSetTimeval(PRTTIMESPEC pTime
, const struct timeval
*pTimeval
)
424 return RTTimeSpecAddMicro(RTTimeSpecSetSeconds(pTime
, pTimeval
->tv_sec
), pTimeval
->tv_usec
);
427 #endif /* various ways of detecting struct timeval */
430 /* PORTME: Add struct timespec guard macro here. */
431 #if defined(RTTIME_INCL_TIMESPEC) \
432 || defined(_SYS__TIMESPEC_H_) \
433 || defined(TIMEVAL_TO_TIMESPEC) \
434 || defined(_TIMESPEC) \
435 || ( defined(_STRUCT_TIMESPEC) \
436 && ( !defined(RT_OS_LINUX) \
437 || !defined(__KERNEL__) \
438 || RTTIME_LINUX_KERNEL_PREREQ_LT(5,6,0) /* @bugref{9757} */ ) ) \
439 || (defined(RT_OS_NETBSD) && defined(_SYS_TIME_H_))
442 * Gets the time as POSIX timespec.
444 * @returns pTimespec.
445 * @param pTime The time spec to interpret.
446 * @param pTimespec Where to store the time as POSIX timespec.
448 DECLINLINE(struct timespec
*) RTTimeSpecGetTimespec(PCRTTIMESPEC pTime
, struct timespec
*pTimespec
)
450 int64_t i64
= RTTimeSpecGetNano(pTime
);
451 int32_t i32Nano
= (int32_t)(i64
% RT_NS_1SEC
);
455 i32Nano
+= RT_NS_1SEC
;
458 pTimespec
->tv_sec
= (time_t)i64
;
459 pTimespec
->tv_nsec
= i32Nano
;
464 * Sets the time as POSIX timespec.
467 * @param pTime The time spec to modify.
468 * @param pTimespec Pointer to the POSIX timespec struct with the new time.
470 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSetTimespec(PRTTIMESPEC pTime
, const struct timespec
*pTimespec
)
472 return RTTimeSpecAddNano(RTTimeSpecSetSeconds(pTime
, pTimespec
->tv_sec
), pTimespec
->tv_nsec
);
475 #endif /* various ways of detecting struct timespec */
478 #if defined(RT_OS_LINUX) && defined(_LINUX_TIME64_H) /* since linux 3.17 */
481 * Gets the time a linux 64-bit timespec structure.
482 * @returns pTimespec.
483 * @param pTime The time spec to modify.
484 * @param pTimespec Where to store the time as linux 64-bit timespec.
486 DECLINLINE(struct timespec64
*) RTTimeSpecGetTimespec64(PCRTTIMESPEC pTime
, struct timespec64
*pTimespec
)
488 int64_t i64
= RTTimeSpecGetNano(pTime
);
489 int32_t i32Nano
= (int32_t)(i64
% RT_NS_1SEC
);
493 i32Nano
+= RT_NS_1SEC
;
496 pTimespec
->tv_sec
= i64
;
497 pTimespec
->tv_nsec
= i32Nano
;
502 * Sets the time from a linux 64-bit timespec structure.
504 * @param pTime The time spec to modify.
505 * @param pTimespec Pointer to the linux 64-bit timespec struct with the new time.
507 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSetTimespec64(PRTTIMESPEC pTime
, const struct timespec64
*pTimespec
)
509 return RTTimeSpecAddNano(RTTimeSpecSetSeconds(pTime
, pTimespec
->tv_sec
), pTimespec
->tv_nsec
);
512 #endif /* RT_OS_LINUX && _LINUX_TIME64_H */
515 /** The offset of the unix epoch and the base for NT time (in 100ns units).
516 * Nt time starts at 1601-01-01 00:00:00. */
517 #define RTTIME_NT_TIME_OFFSET_UNIX (116444736000000000LL)
521 * Gets the time as NT time.
524 * @param pTime The time spec to interpret.
526 DECLINLINE(int64_t) RTTimeSpecGetNtTime(PCRTTIMESPEC pTime
)
528 return pTime
->i64NanosecondsRelativeToUnixEpoch
/ 100
529 + RTTIME_NT_TIME_OFFSET_UNIX
;
534 * Sets the time given by Nt time.
537 * @param pTime The time spec to modify.
538 * @param u64NtTime The new time in Nt time.
540 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSetNtTime(PRTTIMESPEC pTime
, uint64_t u64NtTime
)
542 pTime
->i64NanosecondsRelativeToUnixEpoch
=
543 ((int64_t)u64NtTime
- RTTIME_NT_TIME_OFFSET_UNIX
) * 100;
551 * Gets the time as NT file time.
553 * @returns pFileTime.
554 * @param pTime The time spec to interpret.
555 * @param pFileTime Pointer to NT filetime structure.
557 DECLINLINE(PFILETIME
) RTTimeSpecGetNtFileTime(PCRTTIMESPEC pTime
, PFILETIME pFileTime
)
559 *((uint64_t *)pFileTime
) = RTTimeSpecGetNtTime(pTime
);
564 * Sets the time as NT file time.
567 * @param pTime The time spec to modify.
568 * @param pFileTime Where to store the time as Nt file time.
570 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSetNtFileTime(PRTTIMESPEC pTime
, const FILETIME
*pFileTime
)
572 return RTTimeSpecSetNtTime(pTime
, *(const uint64_t *)pFileTime
);
575 #endif /* _FILETIME_ */
578 /** The offset to the start of DOS time.
579 * DOS time starts 1980-01-01 00:00:00. */
580 #define RTTIME_OFFSET_DOS_TIME (315532800000000000LL)
584 * Gets the time as seconds relative to the start of dos time.
586 * @returns seconds relative to the start of dos time.
587 * @param pTime The time spec to interpret.
589 DECLINLINE(int64_t) RTTimeSpecGetDosSeconds(PCRTTIMESPEC pTime
)
591 return (pTime
->i64NanosecondsRelativeToUnixEpoch
- RTTIME_OFFSET_DOS_TIME
)
597 * Sets the time given by seconds relative to the start of dos time.
600 * @param pTime The time spec to modify.
601 * @param i64Seconds The new time in seconds relative to the start of dos time.
603 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSetDosSeconds(PRTTIMESPEC pTime
, int64_t i64Seconds
)
605 pTime
->i64NanosecondsRelativeToUnixEpoch
= i64Seconds
* RT_NS_1SEC
606 + RTTIME_OFFSET_DOS_TIME
;
612 * Compare two time specs.
614 * @returns true they are equal.
615 * @returns false they are not equal.
616 * @param pTime1 The 1st time spec.
617 * @param pTime2 The 2nd time spec.
619 DECLINLINE(bool) RTTimeSpecIsEqual(PCRTTIMESPEC pTime1
, PCRTTIMESPEC pTime2
)
621 return pTime1
->i64NanosecondsRelativeToUnixEpoch
== pTime2
->i64NanosecondsRelativeToUnixEpoch
;
626 * Compare two time specs.
628 * @returns 0 if equal, -1 if @a pLeft is smaller, 1 if @a pLeft is larger.
629 * @returns false they are not equal.
630 * @param pLeft The 1st time spec.
631 * @param pRight The 2nd time spec.
633 DECLINLINE(int) RTTimeSpecCompare(PCRTTIMESPEC pLeft
, PCRTTIMESPEC pRight
)
635 if (pLeft
->i64NanosecondsRelativeToUnixEpoch
== pRight
->i64NanosecondsRelativeToUnixEpoch
)
637 return pLeft
->i64NanosecondsRelativeToUnixEpoch
< pRight
->i64NanosecondsRelativeToUnixEpoch
? -1 : 1;
642 * Converts a time spec to a ISO date string.
644 * @returns psz on success.
645 * @returns NULL on buffer underflow.
646 * @param pTime The time spec.
647 * @param psz Where to store the string.
648 * @param cb The size of the buffer.
650 RTDECL(char *) RTTimeSpecToString(PCRTTIMESPEC pTime
, char *psz
, size_t cb
);
653 * Attempts to convert an ISO date string to a time structure.
655 * We're a little forgiving with zero padding, unspecified parts, and leading
656 * and trailing spaces.
658 * @retval pTime on success,
659 * @retval NULL on failure.
660 * @param pTime The time spec.
661 * @param pszString The ISO date string to convert.
663 RTDECL(PRTTIMESPEC
) RTTimeSpecFromString(PRTTIMESPEC pTime
, const char *pszString
);
666 * Formats duration as best we can according to ISO-8601, with no fraction.
668 * See RTTimeFormatDurationEx for details.
670 * @returns Number of characters in the output on success. VERR_BUFFER_OVEFLOW
672 * @param pszDst Pointer to the output buffer. In case of overflow,
673 * the max number of characters will be written and
674 * zero terminated, provided @a cbDst isn't zero.
675 * @param cbDst The size of the output buffer.
676 * @param pDuration The duration to format.
678 RTDECL(int) RTTimeFormatDuration(char *pszDst
, size_t cbDst
, PCRTTIMESPEC pDuration
);
681 * Formats duration as best we can according to ISO-8601.
683 * The returned value is on the form "[-]PnnnnnWnDTnnHnnMnn.fffffffffS", where a
684 * sequence of 'n' can be between 1 and the given lenght, and all but the
685 * "nn.fffffffffS" part is optional and will only be outputted when the duration
686 * is sufficiently large. The code currently does not omit any inbetween
687 * elements other than the day count (D), so an exactly 7 day duration is
688 * formatted as "P1WT0H0M0.000000000S" when @a cFractionDigits is 9.
690 * @returns Number of characters in the output on success. VERR_BUFFER_OVEFLOW
692 * @retval VERR_OUT_OF_RANGE if @a cFractionDigits is too large.
693 * @param pszDst Pointer to the output buffer. In case of overflow,
694 * the max number of characters will be written and
695 * zero terminated, provided @a cbDst isn't zero.
696 * @param cbDst The size of the output buffer.
697 * @param pDuration The duration to format.
698 * @param cFractionDigits Number of digits in the second fraction part. Zero
699 * for whole no fraction. Max is 9 (nano seconds).
701 RTDECL(ssize_t
) RTTimeFormatDurationEx(char *pszDst
, size_t cbDst
, PCRTTIMESPEC pDuration
, uint32_t cFractionDigits
);
703 /** Max length of a RTTimeFormatDurationEx output string. */
704 #define RTTIME_DURATION_STR_LEN (sizeof("-P99999W7D23H59M59.123456789S") + 2)
712 typedef struct RTTIME
714 /** The year number. */
716 /** The month of the year (1-12). January is 1. */
718 /** The day of the week (0-6). Monday is 0. */
720 /** The day of the year (1-366). January the 1st is 1. */
722 /** The day of the month (1-31). */
724 /** Hour of the day (0-23). */
726 /** The minute of the hour (0-59). */
728 /** The second of the minute (0-60).
729 * (u32Nanosecond / 1000000) */
731 /** The nanoseconds of the second (0-999999999). */
732 uint32_t u32Nanosecond
;
733 /** Flags, of the RTTIME_FLAGS_* \#defines. */
735 /** UTC time offset in minutes (-840-840). Positive for timezones east of
736 * UTC, negative for zones to the west. Same as what RTTimeLocalDeltaNano
737 * & RTTimeLocalDeltaNanoFor returns, just different unit. */
740 AssertCompileSize(RTTIME
, 24);
741 /** Pointer to a exploded time structure. */
742 typedef RTTIME
*PRTTIME
;
743 /** Pointer to a const exploded time structure. */
744 typedef const RTTIME
*PCRTTIME
;
746 /** @name RTTIME::fFlags values.
748 /** Set if the time is UTC. If clear the time local time. */
749 #define RTTIME_FLAGS_TYPE_MASK 3
750 /** the time is UTC time. */
751 #define RTTIME_FLAGS_TYPE_UTC 2
752 /** The time is local time. */
753 #define RTTIME_FLAGS_TYPE_LOCAL 3
755 /** Set if the time is local and daylight saving time is in effect.
756 * Not bit is not valid if RTTIME_FLAGS_NO_DST_DATA is set. */
757 #define RTTIME_FLAGS_DST RT_BIT(4)
758 /** Set if the time is local and there is no data available on daylight saving time. */
759 #define RTTIME_FLAGS_NO_DST_DATA RT_BIT(5)
760 /** Set if the year is a leap year.
761 * This is mutual exclusiv with RTTIME_FLAGS_COMMON_YEAR. */
762 #define RTTIME_FLAGS_LEAP_YEAR RT_BIT(6)
763 /** Set if the year is a common year.
764 * This is mutual exclusiv with RTTIME_FLAGS_LEAP_YEAR. */
765 #define RTTIME_FLAGS_COMMON_YEAR RT_BIT(7)
766 /** The mask of valid flags. */
767 #define RTTIME_FLAGS_MASK UINT32_C(0xff)
772 * Gets the current system time (UTC).
775 * @param pTime Where to store the time.
777 RTDECL(PRTTIMESPEC
) RTTimeNow(PRTTIMESPEC pTime
);
780 * Sets the system time.
782 * @returns IPRT status code
783 * @param pTime The new system time (UTC).
785 * @remarks This will usually fail because changing the wall time is usually
786 * requires extra privileges.
788 RTDECL(int) RTTimeSet(PCRTTIMESPEC pTime
);
791 * Explodes a time spec (UTC).
794 * @param pTime Where to store the exploded time.
795 * @param pTimeSpec The time spec to exploded.
797 RTDECL(PRTTIME
) RTTimeExplode(PRTTIME pTime
, PCRTTIMESPEC pTimeSpec
);
800 * Implodes exploded time to a time spec (UTC).
802 * @returns pTime on success.
803 * @returns NULL if the pTime data is invalid.
804 * @param pTimeSpec Where to store the imploded UTC time.
805 * If pTime specifies a time which outside the range, maximum or
806 * minimum values will be returned.
807 * @param pTime Pointer to the exploded time to implode.
808 * The fields u8Month, u8WeekDay and u8MonthDay are not used,
809 * and all the other fields are expected to be within their
810 * bounds. Use RTTimeNormalize() to calculate u16YearDay and
811 * normalize the ranges of the fields.
813 RTDECL(PRTTIMESPEC
) RTTimeImplode(PRTTIMESPEC pTimeSpec
, PCRTTIME pTime
);
816 * Normalizes the fields of a time structure.
818 * It is possible to calculate year-day from month/day and vice
819 * versa. If you adjust any of of these, make sure to zero the
820 * other so you make it clear which of the fields to use. If
821 * it's ambiguous, the year-day field is used (and you get
822 * assertions in debug builds).
824 * All the time fields and the year-day or month/day fields will
825 * be adjusted for overflows. (Since all fields are unsigned, there
826 * is no underflows.) It is possible to exploit this for simple
827 * date math, though the recommended way of doing that to implode
828 * the time into a timespec and do the math on that.
830 * @returns pTime on success.
831 * @returns NULL if the data is invalid.
833 * @param pTime The time structure to normalize.
835 * @remarks This function doesn't work with local time, only with UTC time.
837 RTDECL(PRTTIME
) RTTimeNormalize(PRTTIME pTime
);
840 * Gets the current local system time.
843 * @param pTime Where to store the local time.
845 RTDECL(PRTTIMESPEC
) RTTimeLocalNow(PRTTIMESPEC pTime
);
848 * Gets the current delta between UTC and local time.
851 * RTTIMESPEC LocalTime;
852 * RTTimeSpecAddNano(RTTimeNow(&LocalTime), RTTimeLocalDeltaNano());
855 * @returns Returns the nanosecond delta between UTC and local time.
857 RTDECL(int64_t) RTTimeLocalDeltaNano(void);
860 * Gets the delta between UTC and local time at the given time.
863 * RTTIMESPEC LocalTime;
864 * RTTimeNow(&LocalTime);
865 * RTTimeSpecAddNano(&LocalTime, RTTimeLocalDeltaNanoFor(&LocalTime));
868 * @param pTimeSpec The time spec giving the time to get the delta for.
869 * @returns Returns the nanosecond delta between UTC and local time.
871 RTDECL(int64_t) RTTimeLocalDeltaNanoFor(PCRTTIMESPEC pTimeSpec
);
874 * Explodes a time spec to the localized timezone.
877 * @param pTime Where to store the exploded time.
878 * @param pTimeSpec The time spec to exploded (UTC).
880 RTDECL(PRTTIME
) RTTimeLocalExplode(PRTTIME pTime
, PCRTTIMESPEC pTimeSpec
);
883 * Normalizes the fields of a time structure containing local time.
885 * See RTTimeNormalize for details.
887 * @returns pTime on success.
888 * @returns NULL if the data is invalid.
889 * @param pTime The time structure to normalize.
891 RTDECL(PRTTIME
) RTTimeLocalNormalize(PRTTIME pTime
);
894 * Converts a time structure to UTC, relying on UTC offset information
895 * if it contains local time.
897 * @returns pTime on success.
898 * @returns NULL if the data is invalid.
899 * @param pTime The time structure to convert.
901 RTDECL(PRTTIME
) RTTimeConvertToZulu(PRTTIME pTime
);
904 * Converts a time spec to a ISO date string.
906 * @returns psz on success.
907 * @returns NULL on buffer underflow.
908 * @param pTime The time. Caller should've normalized this.
909 * @param psz Where to store the string.
910 * @param cb The size of the buffer.
912 RTDECL(char *) RTTimeToString(PCRTTIME pTime
, char *psz
, size_t cb
);
915 * Converts a time spec to a ISO date string, extended version.
917 * @returns Output string length on success (positive), VERR_BUFFER_OVERFLOW
918 * (negative) or VERR_OUT_OF_RANGE (negative) on failure.
919 * @param pTime The time. Caller should've normalized this.
920 * @param psz Where to store the string.
921 * @param cb The size of the buffer.
922 * @param cFractionDigits Number of digits in the fraction. Max is 9.
924 RTDECL(ssize_t
) RTTimeToStringEx(PCRTTIME pTime
, char *psz
, size_t cb
, unsigned cFractionDigits
);
926 /** Suggested buffer length for RTTimeToString and RTTimeToStringEx output, including terminator. */
927 #define RTTIME_STR_LEN 40
930 * Attempts to convert an ISO date string to a time structure.
932 * We're a little forgiving with zero padding, unspecified parts, and leading
933 * and trailing spaces.
935 * @retval pTime on success,
936 * @retval NULL on failure.
937 * @param pTime Where to store the time on success.
938 * @param pszString The ISO date string to convert.
940 RTDECL(PRTTIME
) RTTimeFromString(PRTTIME pTime
, const char *pszString
);
943 * Formats the given time on a RTC-2822 compliant format.
945 * @returns Output string length on success (positive), VERR_BUFFER_OVERFLOW
946 * (negative) on failure.
947 * @param pTime The time. Caller should've normalized this.
948 * @param psz Where to store the string.
949 * @param cb The size of the buffer.
950 * @param fFlags RTTIME_RFC2822_F_XXX
951 * @sa RTTIME_RFC2822_LEN
953 RTDECL(ssize_t
) RTTimeToRfc2822(PRTTIME pTime
, char *psz
, size_t cb
, uint32_t fFlags
);
955 /** Suggested buffer length for RTTimeToRfc2822 output, including terminator. */
956 #define RTTIME_RFC2822_LEN 40
957 /** @name RTTIME_RFC2822_F_XXX
959 /** Use the deprecated GMT timezone instead of +/-0000.
960 * This is required by the HTTP RFC-7231 7.1.1.1. */
961 #define RTTIME_RFC2822_F_GMT RT_BIT_32(0)
965 * Attempts to convert an RFC-2822 date string to a time structure.
967 * We're a little forgiving with zero padding, unspecified parts, and leading
968 * and trailing spaces.
970 * @retval pTime on success,
971 * @retval NULL on failure.
972 * @param pTime Where to store the time on success.
973 * @param pszString The ISO date string to convert.
975 RTDECL(PRTTIME
) RTTimeFromRfc2822(PRTTIME pTime
, const char *pszString
);
978 * Checks if a year is a leap year or not.
980 * @returns true if it's a leap year.
981 * @returns false if it's a common year.
982 * @param i32Year The year in question.
984 RTDECL(bool) RTTimeIsLeapYear(int32_t i32Year
);
987 * Compares two normalized time structures.
989 * @retval 0 if equal.
990 * @retval -1 if @a pLeft is earlier than @a pRight.
991 * @retval 1 if @a pRight is earlier than @a pLeft.
993 * @param pLeft The left side time. NULL is accepted.
994 * @param pRight The right side time. NULL is accepted.
996 * @note A NULL time is considered smaller than anything else. If both are
997 * NULL, they are considered equal.
999 RTDECL(int) RTTimeCompare(PCRTTIME pLeft
, PCRTTIME pRight
);
1002 * Gets the current nanosecond timestamp.
1004 * @returns nanosecond timestamp.
1006 RTDECL(uint64_t) RTTimeNanoTS(void);
1009 * Gets the current millisecond timestamp.
1011 * @returns millisecond timestamp.
1013 RTDECL(uint64_t) RTTimeMilliTS(void);
1016 * Debugging the time api.
1018 * @returns the number of 1ns steps which has been applied by RTTimeNanoTS().
1020 RTDECL(uint32_t) RTTimeDbgSteps(void);
1023 * Debugging the time api.
1025 * @returns the number of times the TSC interval expired RTTimeNanoTS().
1027 RTDECL(uint32_t) RTTimeDbgExpired(void);
1030 * Debugging the time api.
1032 * @returns the number of bad previous values encountered by RTTimeNanoTS().
1034 RTDECL(uint32_t) RTTimeDbgBad(void);
1037 * Debugging the time api.
1039 * @returns the number of update races in RTTimeNanoTS().
1041 RTDECL(uint32_t) RTTimeDbgRaces(void);
1044 RTDECL(const char *) RTTimeNanoTSWorkerName(void);
1047 /** @name RTTimeNanoTS GIP worker functions, for TM.
1050 /** Extra info optionally returned by the RTTimeNanoTS GIP workers. */
1051 typedef struct RTITMENANOTSEXTRA
1053 /** The TSC value used (delta adjusted). */
1055 } RTITMENANOTSEXTRA
;
1056 /** Pointer to extra info optionally returned by the RTTimeNanoTS GIP workers. */
1057 typedef RTITMENANOTSEXTRA
*PRTITMENANOTSEXTRA
;
1059 /** Pointer to a RTTIMENANOTSDATA structure. */
1060 typedef struct RTTIMENANOTSDATA
*PRTTIMENANOTSDATA
;
1063 * Nanosecond timestamp data.
1065 * This is used to keep track of statistics and callback so IPRT
1066 * and TM (VirtualBox) can share code.
1068 * @remark Keep this in sync with the assembly version in timesupA.asm.
1070 typedef struct RTTIMENANOTSDATA
1072 /** Where the previous timestamp is stored.
1073 * This is maintained to ensure that time doesn't go backwards or anything. */
1074 uint64_t volatile *pu64Prev
;
1077 * Helper function that's used by the assembly routines when something goes bust.
1079 * @param pData Pointer to this structure.
1080 * @param u64NanoTS The calculated nano ts.
1081 * @param u64DeltaPrev The delta relative to the previously returned timestamp.
1082 * @param u64PrevNanoTS The previously returned timestamp (as it was read it).
1084 DECLCALLBACKMEMBER(void, pfnBad
,(PRTTIMENANOTSDATA pData
, uint64_t u64NanoTS
, uint64_t u64DeltaPrev
, uint64_t u64PrevNanoTS
));
1087 * Callback for when rediscovery is required.
1089 * @returns Nanosecond timestamp.
1090 * @param pData Pointer to this structure.
1091 * @param pExtra Where to return extra time info. Optional.
1093 DECLCALLBACKMEMBER(uint64_t, pfnRediscover
,(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
));
1096 * Callback for when some CPU index related stuff goes wrong.
1098 * @returns Nanosecond timestamp.
1099 * @param pData Pointer to this structure.
1100 * @param pExtra Where to return extra time info. Optional.
1101 * @param idApic The APIC ID if available, otherwise (UINT16_MAX-1).
1102 * @param iCpuSet The CPU set index if available, otherwise
1104 * @param iGipCpu The GIP CPU array index if available, otherwise
1107 DECLCALLBACKMEMBER(uint64_t, pfnBadCpuIndex
,(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
,
1108 uint16_t idApic
, uint16_t iCpuSet
, uint16_t iGipCpu
));
1110 /** Number of 1ns steps because of overshooting the period. */
1112 /** The number of times the interval expired (overflow). */
1114 /** Number of "bad" previous values. */
1116 /** The number of update races. */
1117 uint32_t cUpdateRaces
;
1122 * The Ring-3 layout of the RTTIMENANOTSDATA structure.
1124 typedef struct RTTIMENANOTSDATAR3
1126 R3PTRTYPE(uint64_t volatile *) pu64Prev
;
1127 DECLR3CALLBACKMEMBER(void, pfnBad
,(PRTTIMENANOTSDATA pData
, uint64_t u64NanoTS
, uint64_t u64DeltaPrev
, uint64_t u64PrevNanoTS
));
1128 DECLR3CALLBACKMEMBER(uint64_t, pfnRediscover
,(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
));
1129 DECLR3CALLBACKMEMBER(uint64_t, pfnBadCpuIndex
,(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
,
1130 uint16_t idApic
, uint16_t iCpuSet
, uint16_t iGipCpu
));
1134 uint32_t cUpdateRaces
;
1135 } RTTIMENANOTSDATAR3
;
1137 typedef RTTIMENANOTSDATA RTTIMENANOTSDATAR3
;
1142 * The Ring-3 layout of the RTTIMENANOTSDATA structure.
1144 typedef struct RTTIMENANOTSDATAR0
1146 R0PTRTYPE(uint64_t volatile *) pu64Prev
;
1147 DECLR0CALLBACKMEMBER(void, pfnBad
,(PRTTIMENANOTSDATA pData
, uint64_t u64NanoTS
, uint64_t u64DeltaPrev
, uint64_t u64PrevNanoTS
));
1148 DECLR0CALLBACKMEMBER(uint64_t, pfnRediscover
,(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
));
1149 DECLR0CALLBACKMEMBER(uint64_t, pfnBadCpuIndex
,(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
,
1150 uint16_t idApic
, uint16_t iCpuSet
, uint16_t iGipCpu
));
1154 uint32_t cUpdateRaces
;
1155 } RTTIMENANOTSDATAR0
;
1157 typedef RTTIMENANOTSDATA RTTIMENANOTSDATAR0
;
1162 * The RC layout of the RTTIMENANOTSDATA structure.
1164 typedef struct RTTIMENANOTSDATARC
1166 RCPTRTYPE(uint64_t volatile *) pu64Prev
;
1167 DECLRCCALLBACKMEMBER(void, pfnBad
,(PRTTIMENANOTSDATA pData
, uint64_t u64NanoTS
, uint64_t u64DeltaPrev
, uint64_t u64PrevNanoTS
));
1168 DECLRCCALLBACKMEMBER(uint64_t, pfnRediscover
,(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
));
1169 DECLRCCALLBACKMEMBER(uint64_t, pfnBadCpuIndex
,(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
,
1170 uint16_t idApic
, uint16_t iCpuSet
, uint16_t iGipCpu
));
1174 uint32_t cUpdateRaces
;
1175 } RTTIMENANOTSDATARC
;
1177 typedef RTTIMENANOTSDATA RTTIMENANOTSDATARC
;
1180 /** Internal RTTimeNanoTS worker (assembly). */
1181 typedef DECLCALLBACKTYPE(uint64_t, FNTIMENANOTSINTERNAL
,(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
));
1182 /** Pointer to an internal RTTimeNanoTS worker (assembly). */
1183 typedef FNTIMENANOTSINTERNAL
*PFNTIMENANOTSINTERNAL
;
1184 #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
1185 RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarNoDelta(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1186 RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarNoDelta(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1188 RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseApicId(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1189 RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseApicIdExt0B(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1190 RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseApicIdExt8000001E(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1191 RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseRdtscp(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1192 RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseRdtscpGroupChNumCl(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1193 RTDECL(uint64_t) RTTimeNanoTSLegacyAsyncUseIdtrLim(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1194 RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDeltaUseApicId(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1195 RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDeltaUseApicIdExt0B(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1196 RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDeltaUseApicIdExt8000001E(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1197 RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDeltaUseRdtscp(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1198 RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDeltaUseIdtrLim(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1199 RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseApicId(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1200 RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseApicIdExt0B(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1201 RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseApicIdExt8000001E(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1202 RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseRdtscp(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1203 RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseRdtscpGroupChNumCl(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1204 RTDECL(uint64_t) RTTimeNanoTSLFenceAsyncUseIdtrLim(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1205 RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicId(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1206 RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicIdExt0B(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1207 RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDeltaUseApicIdExt8000001E(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1208 RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDeltaUseRdtscp(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1209 RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDeltaUseIdtrLim(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1211 RTDECL(uint64_t) RTTimeNanoTSLegacyAsync(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1212 RTDECL(uint64_t) RTTimeNanoTSLegacySyncInvarWithDelta(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1213 RTDECL(uint64_t) RTTimeNanoTSLFenceAsync(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1214 RTDECL(uint64_t) RTTimeNanoTSLFenceSyncInvarWithDelta(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1217 RTDECL(uint64_t) RTTimeNanoTSSyncInvarNoDelta(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1219 # ifdef RT_ARCH_ARM64
1220 RTDECL(uint64_t) RTTimeNanoTSSyncInvarWithDeltaUseTpIdRRo(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1221 RTDECL(uint64_t) RTTimeNanoTSAsyncUseTpIdRRo(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1224 RTDECL(uint64_t) RTTimeNanoTSSyncInvarWithDelta(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1225 RTDECL(uint64_t) RTTimeNanoTSAsync(PRTTIMENANOTSDATA pData
, PRTITMENANOTSEXTRA pExtra
);
1233 * Gets the current nanosecond timestamp.
1235 * This differs from RTTimeNanoTS in that it will use system APIs and not do any
1236 * resolution or performance optimizations.
1238 * @returns nanosecond timestamp.
1240 RTDECL(uint64_t) RTTimeSystemNanoTS(void);
1243 * Gets the current millisecond timestamp.
1245 * This differs from RTTimeNanoTS in that it will use system APIs and not do any
1246 * resolution or performance optimizations.
1248 * @returns millisecond timestamp.
1250 RTDECL(uint64_t) RTTimeSystemMilliTS(void);
1253 * Get the nanosecond timestamp relative to program startup.
1255 * @returns Timestamp relative to program startup.
1257 RTDECL(uint64_t) RTTimeProgramNanoTS(void);
1260 * Get the microsecond timestamp relative to program startup.
1262 * @returns Timestamp relative to program startup.
1264 RTDECL(uint64_t) RTTimeProgramMicroTS(void);
1267 * Get the millisecond timestamp relative to program startup.
1269 * @returns Timestamp relative to program startup.
1271 RTDECL(uint64_t) RTTimeProgramMilliTS(void);
1274 * Get the second timestamp relative to program startup.
1276 * @returns Timestamp relative to program startup.
1278 RTDECL(uint32_t) RTTimeProgramSecTS(void);
1281 * Get the RTTimeNanoTS() of when the program started.
1283 * @returns Program startup timestamp.
1285 RTDECL(uint64_t) RTTimeProgramStartNanoTS(void);
1289 * Time zone information.
1291 typedef struct RTTIMEZONEINFO
1293 /** Unix time zone name (continent/country[/city]|). */
1294 const char *pszUnixName
;
1295 /** Windows time zone name. */
1296 const char *pszWindowsName
;
1297 /** The length of the unix time zone name. */
1298 uint8_t cchUnixName
;
1299 /** The length of the windows time zone name. */
1300 uint8_t cchWindowsName
;
1301 /** Two letter country/territory code if applicable, otherwise 'ZZ'. */
1303 /** Two letter windows country/territory code if applicable.
1304 * Empty string if no windows mapping. */
1305 char szWindowsCountry
[3];
1306 #if 0 /* Add when needed and it's been extracted. */
1307 /** The standard delta in minutes (add to UTC). */
1308 int16_t cMinStdDelta
;
1309 /** The daylight saving time delta in minutes (add to UTC). */
1310 int16_t cMinDstDelta
;
1312 /** closest matching windows time zone index. */
1313 uint32_t idxWindows
;
1314 /** Flags, RTTIMEZONEINFO_F_XXX. */
1317 /** Pointer to time zone info. */
1318 typedef RTTIMEZONEINFO
const *PCRTTIMEZONEINFO
;
1320 /** @name RTTIMEZONEINFO_F_XXX - time zone info flags.
1322 /** Indicates golden mapping entry for a windows time zone name. */
1323 #define RTTIMEZONEINFO_F_GOLDEN RT_BIT_32(0)
1327 * Looks up static time zone information by unix name.
1329 * @returns Pointer to info entry if found, NULL if not.
1330 * @param pszName The unix zone name (TZ).
1332 RTDECL(PCRTTIMEZONEINFO
) RTTimeZoneGetInfoByUnixName(const char *pszName
);
1335 * Looks up static time zone information by window name.
1337 * @returns Pointer to info entry if found, NULL if not.
1338 * @param pszName The windows zone name (reg key).
1340 RTDECL(PCRTTIMEZONEINFO
) RTTimeZoneGetInfoByWindowsName(const char *pszName
);
1343 * Looks up static time zone information by windows index.
1345 * @returns Pointer to info entry if found, NULL if not.
1346 * @param idxZone The windows timezone index.
1348 RTDECL(PCRTTIMEZONEINFO
) RTTimeZoneGetInfoByWindowsIndex(uint32_t idxZone
);
1351 * Get the current time zone (TZ).
1353 * @returns IPRT status code.
1354 * @param pszName Where to return the time zone name.
1355 * @param cbName The size of the name buffer.
1357 RTDECL(int) RTTimeZoneGetCurrent(char *pszName
, size_t cbName
);
1363 #endif /* !IPRT_INCLUDED_time_h */