]> git.proxmox.com Git - mirror_edk2.git/blob - EmbeddedPkg/Include/Library/TimeBaseLib.h
a9f3c6588b75fbd576fe08a86914a52a1bc59678
[mirror_edk2.git] / EmbeddedPkg / Include / Library / TimeBaseLib.h
1 /** @file
2 *
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.
6 *
7 * SPDX-License-Identifier: BSD-2-Clause-Patent
8 *
9 **/
10
11 #ifndef _TIME_BASE_LIB_H_
12 #define _TIME_BASE_LIB_H_
13
14 #include <Uefi/UefiBaseType.h>
15
16 //
17 // Convenience macros to obtain a build date
18 //
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.
22 //
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 \
41 : 12)
42 #define TIME_BUILD_DAY ( __DATE__[4] == '?' ? 1 \
43 : ((__DATE__[4] == ' ' ? 0 : \
44 ((__DATE__[4] - '0') * 10)) \
45 + __DATE__[5] - '0'))
46 #endif
47
48 // Define EPOCH (1970-JANUARY-01) in the Julian Date representation
49 #define EPOCH_JULIAN_DATE 2440588
50
51 // Seconds per unit
52 #define SEC_PER_MIN ((UINTN) 60)
53 #define SEC_PER_HOUR ((UINTN) 3600)
54 #define SEC_PER_DAY ((UINTN) 86400)
55
56 /**
57 Check if it is a leap year.
58
59 @param Time The UEFI time to be checked.
60
61 @retval TRUE It is a leap year.
62 @retval FALSE It is NOT a leap year.
63
64 **/
65 BOOLEAN
66 EFIAPI
67 IsLeapYear (
68 IN EFI_TIME *Time
69 );
70
71 /**
72 Check if the day in the UEFI time is valid.
73
74 @param Time The UEFI time to be checked.
75
76 @retval TRUE Valid.
77 @retval FALSE Invalid.
78
79 **/
80 BOOLEAN
81 EFIAPI
82 IsDayValid (
83 IN EFI_TIME *Time
84 );
85
86 /**
87 Check if the UEFI time is valid.
88
89 @param Time The UEFI time to be checked.
90
91 @retval TRUE Valid.
92 @retval FALSE Invalid.
93
94 **/
95 BOOLEAN
96 EFIAPI
97 IsTimeValid (
98 IN EFI_TIME *Time
99 );
100
101 /**
102 Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME.
103
104 @param EpochSeconds Epoch seconds.
105 @param Time The time converted to UEFI format.
106
107 **/
108 VOID
109 EFIAPI
110 EpochToEfiTime (
111 IN UINTN EpochSeconds,
112 OUT EFI_TIME *Time
113 );
114
115 /**
116 Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC).
117
118 @param Time The UEFI time to be converted.
119
120 @return Number of seconds.
121
122 **/
123 UINTN
124 EFIAPI
125 EfiTimeToEpoch (
126 IN EFI_TIME *Time
127 );
128
129 /**
130 Get the day of the week from the UEFI time.
131
132 @param Time The UEFI time to be calculated.
133
134 @return The day of the week: Sunday=0, Monday=1, ... Saturday=6
135
136 **/
137 UINTN
138 EfiTimeToWday (
139 IN EFI_TIME *Time
140 );
141
142 #endif