]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight
authorNhi Pham <nhi@os.amperecomputing.com>
Wed, 6 Jan 2021 16:09:02 +0000 (23:09 +0700)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 7 Jan 2021 16:43:48 +0000 (16:43 +0000)
This adds two functions IsValidTimeZone() and IsValidDaylight() to check
the time zone and daylight value from EFI time. These functions are
retrieved from the RealTimeClockRuntimeDxe module as they reduce
duplicated code in RTC modules.

Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
EmbeddedPkg/Include/Library/TimeBaseLib.h
EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c

index a9f3c6588b75fbd576fe08a86914a52a1bc59678..10700d1a649a6f19eaeda4e8f37557cda8c3a870 100644 (file)
@@ -83,6 +83,42 @@ IsDayValid (
   IN  EFI_TIME  *Time\r
   );\r
 \r
+/**\r
+  Check if the time zone is valid.\r
+  Valid values are between -1440 and 1440 or 2047 (EFI_UNSPECIFIED_TIMEZONE).\r
+\r
+  @param    TimeZone    The time zone to be checked.\r
+\r
+  @retval   TRUE    Valid.\r
+  @retval   FALSE   Invalid.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsValidTimeZone (\r
+  IN  INT16  TimeZone\r
+  );\r
+\r
+/**\r
+  Check if the daylight is valid.\r
+  Valid values are:\r
+    0 : Time is not affected.\r
+    1 : Time is affected, and has not been adjusted for daylight savings.\r
+    3 : Time is affected, and has been adjusted for daylight savings.\r
+  All other values are invalid.\r
+\r
+  @param    Daylight    The daylight to be checked.\r
+\r
+  @retval   TRUE    Valid.\r
+  @retval   FALSE   Invalid.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsValidDaylight (\r
+  IN  INT8  Daylight\r
+  );\r
+\r
 /**\r
   Check if the UEFI time is valid.\r
 \r
index 17466c1e6c67d3c559623d4a7a39255b33c29f49..210d0b2bf17ddc217c58f78eb8a11e8997c664d3 100644 (file)
@@ -210,6 +210,51 @@ IsDayValid (
   return TRUE;\r
 }\r
 \r
+/**\r
+  Check if the time zone is valid.\r
+  Valid values are between -1440 and 1440 or 2047 (EFI_UNSPECIFIED_TIMEZONE).\r
+\r
+  @param    TimeZone    The time zone to be checked.\r
+\r
+  @retval   TRUE    Valid.\r
+  @retval   FALSE   Invalid.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsValidTimeZone (\r
+  IN  INT16  TimeZone\r
+  )\r
+{\r
+  return TimeZone == EFI_UNSPECIFIED_TIMEZONE ||\r
+         (TimeZone >= -1440 && TimeZone <= 1440);\r
+}\r
+\r
+/**\r
+  Check if the daylight is valid.\r
+  Valid values are:\r
+    0 : Time is not affected.\r
+    1 : Time is affected, and has not been adjusted for daylight savings.\r
+    3 : Time is affected, and has been adjusted for daylight savings.\r
+  All other values are invalid.\r
+\r
+  @param    Daylight    The daylight to be checked.\r
+\r
+  @retval   TRUE    Valid.\r
+  @retval   FALSE   Invalid.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsValidDaylight (\r
+  IN  INT8  Daylight\r
+  )\r
+{\r
+  return Daylight == 0 ||\r
+         Daylight == EFI_TIME_ADJUST_DAYLIGHT ||\r
+         Daylight == (EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT);\r
+}\r
+\r
 /**\r
   Check if the UEFI time is valid.\r
 \r
@@ -235,8 +280,8 @@ IsTimeValid (
      (Time->Minute > 59  )              ||\r
      (Time->Second > 59  )              ||\r
      (Time->Nanosecond > 999999999)     ||\r
-     (!((Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) || ((Time->TimeZone >= -1440) && (Time->TimeZone <= 1440)))) ||\r
-     (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))) {\r
+     (!IsValidTimeZone(Time->TimeZone)) ||\r
+     (!IsValidDaylight(Time->Daylight))) {\r
     return FALSE;\r
   }\r
 \r