3 * Copyright (c) 2016, Hisilicon Limited. All rights reserved.
4 * Copyright (c) 2016, Linaro Limited. All rights reserved.
6 * This program and the accompanying materials
7 * are licensed and made available under the terms and conditions of the BSD License
8 * which accompanies this distribution. The full text of the license may be found at
9 * http://opensource.org/licenses/bsd-license.php
11 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Uefi/UefiBaseType.h>
17 #include <Uefi/UefiSpec.h>
18 #include <Library/DebugLib.h>
19 #include <Library/TimeBaseLib.h>
22 Converts Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC) to EFI_TIME
27 IN UINTN EpochSeconds
,
48 J
= (EpochSeconds
/ 86400) + 2440588;
52 c
= (((dg
/ 36524) + 1) * 3) / 4;
53 dc
= dg
- (c
* 36524);
56 a
= (((db
/ 365) + 1) * 3) / 4;
58 y
= (g
* 400) + (c
* 100) + (b
* 4) + a
;
59 m
= (((da
* 5) + 308) / 153) - 2;
60 d
= da
- (((m
+ 4) * 153) / 5) + 122;
62 Time
->Year
= y
- 4800 + ((m
+ 2) / 12);
63 Time
->Month
= ((m
+ 2) % 12) + 1;
66 ss
= EpochSeconds
% 60;
67 a
= (EpochSeconds
- ss
) / 60;
91 UINTN JulianDate
; // Absolute Julian Date representation of the supplied Time
92 UINTN EpochDays
; // Number of days elapsed since EPOCH_JULIAN_DAY
94 a
= (14 - Time
->Month
) / 12 ;
95 y
= Time
->Year
+ 4800 - a
;
96 m
= Time
->Month
+ (12*a
) - 3;
98 JulianDate
= Time
->Day
+ ((153*m
+ 2)/5) + (365*y
) + (y
/4) - (y
/100) + (y
/400) - 32045;
100 ASSERT (JulianDate
>= EPOCH_JULIAN_DATE
);
101 EpochDays
= JulianDate
- EPOCH_JULIAN_DATE
;
106 Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)
114 UINTN EpochDays
; // Number of days elapsed since EPOCH_JULIAN_DAY
117 EpochDays
= EfiGetEpochDays (Time
);
119 EpochSeconds
= (EpochDays
* SEC_PER_DAY
) + ((UINTN
)Time
->Hour
* SEC_PER_HOUR
) + (Time
->Minute
* SEC_PER_MIN
) + Time
->Second
;
125 returns Day of the week [0-6] 0=Sunday
132 UINTN EpochDays
; // Number of days elapsed since EPOCH_JULIAN_DAY
134 EpochDays
= EfiGetEpochDays (Time
);
136 // 4=1/1/1970 was a Thursday
138 return (EpochDays
+ 4) % 7;
147 if (Time
->Year
% 4 == 0) {
148 if (Time
->Year
% 100 == 0) {
149 if (Time
->Year
% 400 == 0) {
168 STATIC CONST INTN DayOfMonth
[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
171 Time
->Day
> DayOfMonth
[Time
->Month
- 1] ||
172 (Time
->Month
== 2 && (!IsLeapYear (Time
) && Time
->Day
> 28))
186 // Check the input parameters are within the range specified by UEFI
187 if ((Time
->Year
< 2000) ||
188 (Time
->Year
> 2099) ||
189 (Time
->Month
< 1 ) ||
190 (Time
->Month
> 12 ) ||
191 (!IsDayValid (Time
) ) ||
192 (Time
->Hour
> 23 ) ||
193 (Time
->Minute
> 59 ) ||
194 (Time
->Second
> 59 ) ||
195 (Time
->Nanosecond
> 999999999) ||
196 (!((Time
->TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) || ((Time
->TimeZone
>= -1440) && (Time
->TimeZone
<= 1440)))) ||
197 (Time
->Daylight
& (~(EFI_TIME_ADJUST_DAYLIGHT
| EFI_TIME_IN_DAYLIGHT
)))