+++ /dev/null
-/** @file\r
- Transformations between the EFI_TIME structure and struct tm or time_t.\r
-\r
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials are licensed and made available under\r
- the terms and conditions of the BSD License that accompanies this distribution.\r
- The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php.\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-#include <Uefi.h>\r
-\r
-#include <LibConfig.h>\r
-\r
-#include <time.h>\r
-#include "tzfile.h"\r
-#include <MainData.h>\r
-\r
-/** Convert an EFI_TIME structure into a C Standard tm structure.\r
-\r
- @param[in] ET Pointer to the EFI_TIME structure to convert.\r
- @param[out] BT Pointer to the tm structure to receive the converted time.\r
-*/\r
-void\r
-Efi2Tm(\r
- IN EFI_TIME *ET,\r
- OUT struct tm *BT\r
- )\r
-{\r
- // Convert EFI time to broken-down time.\r
- BT->tm_year = ET->Year - TM_YEAR_BASE;\r
- BT->tm_mon = ET->Month - 1; // BD time is zero based, EFI is 1 based\r
- BT->tm_mday = ET->Day;\r
- BT->tm_hour = ET->Hour;\r
- BT->tm_min = ET->Minute;\r
- BT->tm_sec = ET->Second;\r
- BT->tm_isdst = -1;\r
- BT->tm_zoneoff = ET->TimeZone;\r
- BT->tm_daylight = ET->Daylight;\r
- BT->tm_Nano = ET->Nanosecond;\r
-}\r
-\r
-/** Convert an EFI_TIME structure into a time_t value.\r
-\r
- @param[in] EfiBDtime Pointer to the EFI_TIME structure to convert.\r
-\r
- @return The EFI_TIME converted into a time_t value.\r
-*/\r
-time_t\r
-Efi2Time(\r
- IN EFI_TIME *EfiBDtime\r
- )\r
-{\r
- Efi2Tm( EfiBDtime, &gMD->BDTime);\r
-\r
- return mktime( &gMD->BDTime);\r
-}\r
-\r
-/** Convert a C Standard tm structure into an EFI_TIME structure.\r
-\r
- @param[in] BT Pointer to the tm structure to convert.\r
- @param[out] ET Pointer to an EFI_TIME structure to receive the converted time.\r
-*/\r
-void\r
-Tm2Efi(\r
- IN struct tm *BT,\r
- OUT EFI_TIME *ET\r
- )\r
-{\r
- ET->Year = (UINT16)BT->tm_year + TM_YEAR_BASE;\r
- ET->Month = (UINT8)BT->tm_mon + 1;\r
- ET->Day = (UINT8)BT->tm_mday;\r
- ET->Hour = (UINT8)BT->tm_hour;\r
- ET->Minute = (UINT8)BT->tm_min;\r
- ET->Second = (UINT8)BT->tm_sec;\r
- ET->Nanosecond = (UINT32)BT->tm_Nano;\r
- ET->TimeZone = (INT16)BT->tm_zoneoff;\r
- ET->Daylight = (UINT8)BT->tm_daylight;\r
-}\r
-\r
-/** Convert a time_t value into an EFI_TIME structure.\r
-\r
- @param[in] CalTime Calendar time as a time_t value.\r
-\r
- @return Returns a newly malloced EFI_TIME structure containing\r
- the converted calendar time.\r
-\r
- @post It is the responsibility of the caller to free the\r
- returned structure before the application exits.\r
-*/\r
-EFI_TIME*\r
-Time2Efi(\r
- IN time_t CalTime\r
- )\r
-{\r
- struct tm *IT;\r
- EFI_TIME *ET = NULL;\r
-\r
- IT = gmtime(&CalTime);\r
- if(IT != NULL) {\r
- ET = malloc(sizeof(EFI_TIME));\r
- if(ET != NULL) {\r
- Tm2Efi(IT, ET);\r
- }\r
- }\r
- return ET;\r
-}\r