]>
git.proxmox.com Git - mirror_edk2.git/blob - EmbeddedPkg/Include/Library/TimeBaseLib.h
3 * Copyright (c) 2016, Hisilicon Limited. All rights reserved.
4 * Copyright (c) 2016-2019, Linaro Limited. All rights reserved.
5 * Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
7 * SPDX-License-Identifier: BSD-2-Clause-Patent
11 #ifndef _TIME_BASE_LIB_H_
12 #define _TIME_BASE_LIB_H_
14 #include <Uefi/UefiBaseType.h>
17 // Convenience macros to obtain a build date
19 // These macros should work for any compiler that follows ISO/IEC 9899,
20 // in which case __DATE__ is defined as a "Mmm dd yyyy" 11 chars string,
21 // but add an explicit filter for compilers that have been validated.
23 #if (defined (__GNUC__) || defined (_MSC_VER) || defined (__clang__))
24 #define TIME_BUILD_YEAR (__DATE__[7] == '?' ? 1900\
25 : (((__DATE__[7] - '0') * 1000 ) \
26 + (__DATE__[8] - '0') * 100 \
27 + (__DATE__[9] - '0') * 10 \
28 + __DATE__[10] - '0'))
29 #define TIME_BUILD_MONTH ( __DATE__ [2] == '?' ? 1 \
30 : __DATE__ [2] == 'n' ? ( \
31 __DATE__ [1] == 'a' ? 1 : 6) \
32 : __DATE__ [2] == 'b' ? 2 \
33 : __DATE__ [2] == 'r' ? ( \
34 __DATE__ [0] == 'M' ? 3 : 4) \
35 : __DATE__ [2] == 'y' ? 5 \
36 : __DATE__ [2] == 'l' ? 7 \
37 : __DATE__ [2] == 'g' ? 8 \
38 : __DATE__ [2] == 'p' ? 9 \
39 : __DATE__ [2] == 't' ? 10 \
40 : __DATE__ [2] == 'v' ? 11 \
42 #define TIME_BUILD_DAY ( __DATE__[4] == '?' ? 1 \
43 : ((__DATE__[4] == ' ' ? 0 : \
44 ((__DATE__[4] - '0') * 10)) \
48 // Define EPOCH (1970-JANUARY-01) in the Julian Date representation
49 #define EPOCH_JULIAN_DATE 2440588
52 #define SEC_PER_MIN ((UINTN) 60)
53 #define SEC_PER_HOUR ((UINTN) 3600)
54 #define SEC_PER_DAY ((UINTN) 86400)
57 Check if it is a leap year.
59 @param Time The UEFI time to be checked.
61 @retval TRUE It is a leap year.
62 @retval FALSE It is NOT a leap year.
72 Check if the day in the UEFI time is valid.
74 @param Time The UEFI time to be checked.
77 @retval FALSE Invalid.
87 Check if the time zone is valid.
88 Valid values are between -1440 and 1440 or 2047 (EFI_UNSPECIFIED_TIMEZONE).
90 @param TimeZone The time zone to be checked.
93 @retval FALSE Invalid.
103 Check if the daylight is valid.
105 0 : Time is not affected.
106 1 : Time is affected, and has not been adjusted for daylight savings.
107 3 : Time is affected, and has been adjusted for daylight savings.
108 All other values are invalid.
110 @param Daylight The daylight to be checked.
113 @retval FALSE Invalid.
123 Check if the UEFI time is valid.
125 @param Time The UEFI time to be checked.
128 @retval FALSE Invalid.
138 Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME.
140 @param EpochSeconds Epoch seconds.
141 @param Time The time converted to UEFI format.
147 IN UINTN EpochSeconds
,
152 Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC).
154 @param Time The UEFI time to be converted.
156 @return Number of seconds.
166 Get the day of the week from the UEFI time.
168 @param Time The UEFI time to be calculated.
170 @return The day of the week: Sunday=0, Monday=1, ... Saturday=6