summaryrefslogtreecommitdiffstats
path: root/EmbeddedPkg/Library/TimeBaseLib
diff options
context:
space:
mode:
authorNhi Pham <nhi@os.amperecomputing.com>2021-01-06 23:09:02 +0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-01-07 16:43:48 +0000
commite31dc4717c75d8e771dfa5c9b1648fa20d88ab0d (patch)
treebdbf235236e0f97c791ad02de8b94d2e7a3b81a9 /EmbeddedPkg/Library/TimeBaseLib
parentad16388d69c653333275fcb266617d7fa0c24ff4 (diff)
downloadedk2-e31dc4717c75d8e771dfa5c9b1648fa20d88ab0d.tar.gz
edk2-e31dc4717c75d8e771dfa5c9b1648fa20d88ab0d.tar.bz2
edk2-e31dc4717c75d8e771dfa5c9b1648fa20d88ab0d.zip
EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight
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>
Diffstat (limited to 'EmbeddedPkg/Library/TimeBaseLib')
-rw-r--r--EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c49
1 files changed, 47 insertions, 2 deletions
diff --git a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
index 17466c1e6c..210d0b2bf1 100644
--- a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
+++ b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
@@ -211,6 +211,51 @@ IsDayValid (
}
/**
+ Check if the time zone is valid.
+ Valid values are between -1440 and 1440 or 2047 (EFI_UNSPECIFIED_TIMEZONE).
+
+ @param TimeZone The time zone to be checked.
+
+ @retval TRUE Valid.
+ @retval FALSE Invalid.
+
+**/
+BOOLEAN
+EFIAPI
+IsValidTimeZone (
+ IN INT16 TimeZone
+ )
+{
+ return TimeZone == EFI_UNSPECIFIED_TIMEZONE ||
+ (TimeZone >= -1440 && TimeZone <= 1440);
+}
+
+/**
+ Check if the daylight is valid.
+ Valid values are:
+ 0 : Time is not affected.
+ 1 : Time is affected, and has not been adjusted for daylight savings.
+ 3 : Time is affected, and has been adjusted for daylight savings.
+ All other values are invalid.
+
+ @param Daylight The daylight to be checked.
+
+ @retval TRUE Valid.
+ @retval FALSE Invalid.
+
+**/
+BOOLEAN
+EFIAPI
+IsValidDaylight (
+ IN INT8 Daylight
+ )
+{
+ return Daylight == 0 ||
+ Daylight == EFI_TIME_ADJUST_DAYLIGHT ||
+ Daylight == (EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT);
+}
+
+/**
Check if the UEFI time is valid.
@param Time The UEFI time to be checked.
@@ -235,8 +280,8 @@ IsTimeValid (
(Time->Minute > 59 ) ||
(Time->Second > 59 ) ||
(Time->Nanosecond > 999999999) ||
- (!((Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) || ((Time->TimeZone >= -1440) && (Time->TimeZone <= 1440)))) ||
- (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))) {
+ (!IsValidTimeZone(Time->TimeZone)) ||
+ (!IsValidDaylight(Time->Daylight))) {
return FALSE;
}