]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/LibC/Time/TimeEfi.c
2 Transformations between the EFI_TIME structure and struct tm or time_t.
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <LibConfig.h>
22 /** Convert an EFI_TIME structure into a C Standard tm structure.
24 @param[in] ET Pointer to the EFI_TIME structure to convert.
25 @param[out] BT Pointer to the tm structure to receive the converted time.
33 // Convert EFI time to broken-down time.
34 BT
->tm_year
= ET
->Year
- TM_YEAR_BASE
;
35 BT
->tm_mon
= ET
->Month
- 1; // BD time is zero based, EFI is 1 based
36 BT
->tm_mday
= ET
->Day
;
37 BT
->tm_hour
= ET
->Hour
;
38 BT
->tm_min
= ET
->Minute
;
39 BT
->tm_sec
= ET
->Second
;
41 BT
->tm_zoneoff
= ET
->TimeZone
;
42 BT
->tm_daylight
= ET
->Daylight
;
43 BT
->tm_Nano
= ET
->Nanosecond
;
46 /** Convert an EFI_TIME structure into a time_t value.
48 @param[in] EfiBDtime Pointer to the EFI_TIME structure to convert.
50 @return The EFI_TIME converted into a time_t value.
54 IN EFI_TIME
*EfiBDtime
57 Efi2Tm( EfiBDtime
, &gMD
->BDTime
);
59 return mktime( &gMD
->BDTime
);
62 /** Convert a C Standard tm structure into an EFI_TIME structure.
64 @param[in] BT Pointer to the tm structure to convert.
65 @param[out] ET Pointer to an EFI_TIME structure to receive the converted time.
73 ET
->Year
= (UINT16
)BT
->tm_year
+ TM_YEAR_BASE
;
74 ET
->Month
= (UINT8
)BT
->tm_mon
+ 1;
75 ET
->Day
= (UINT8
)BT
->tm_mday
;
76 ET
->Hour
= (UINT8
)BT
->tm_hour
;
77 ET
->Minute
= (UINT8
)BT
->tm_min
;
78 ET
->Second
= (UINT8
)BT
->tm_sec
;
79 ET
->Nanosecond
= (UINT32
)BT
->tm_Nano
;
80 ET
->TimeZone
= (INT16
)BT
->tm_zoneoff
;
81 ET
->Daylight
= (UINT8
)BT
->tm_daylight
;
84 /** Convert a time_t value into an EFI_TIME structure.
86 @param[in] CalTime Calendar time as a time_t value.
88 @return Returns a newly malloced EFI_TIME structure containing
89 the converted calendar time.
91 @post It is the responsibility of the caller to free the
92 returned structure before the application exits.
102 IT
= gmtime(&CalTime
);
104 ET
= malloc(sizeof(EFI_TIME
));