From: "Nhi Pham" <nhi@os.amperecomputing.com>
To: devel@edk2.groups.io
Cc: Nhi Pham <nhi@os.amperecomputing.com>,
Leif Lindholm <leif@nuviainc.com>,
Ard Biesheuvel <ard.biesheuvel@arm.com>
Subject: [PATCH v2 3/4] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight
Date: Wed, 6 Jan 2021 23:09:02 +0700 [thread overview]
Message-ID: <20210106160903.27679-4-nhi@os.amperecomputing.com> (raw)
In-Reply-To: <20210106160903.27679-1-nhi@os.amperecomputing.com>
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>
---
EmbeddedPkg/Include/Library/TimeBaseLib.h | 36 ++++++++++++++
EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 49 +++++++++++++++++++-
2 files changed, 83 insertions(+), 2 deletions(-)
diff --git a/EmbeddedPkg/Include/Library/TimeBaseLib.h b/EmbeddedPkg/Include/Library/TimeBaseLib.h
index a9f3c6588b75..10700d1a649a 100644
--- a/EmbeddedPkg/Include/Library/TimeBaseLib.h
+++ b/EmbeddedPkg/Include/Library/TimeBaseLib.h
@@ -83,6 +83,42 @@ IsDayValid (
IN EFI_TIME *Time
);
+/**
+ 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
+ );
+
+/**
+ 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
+ );
+
/**
Check if the UEFI time is valid.
diff --git a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
index 17466c1e6c67..210d0b2bf17d 100644
--- a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
+++ b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
@@ -210,6 +210,51 @@ IsDayValid (
return TRUE;
}
+/**
+ 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.
@@ -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;
}
--
2.17.1
next prev parent reply other threads:[~2021-01-06 16:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-06 16:08 [PATCH v2 0/4] EmbeddedPkg/TimeBaseLib: Reduce duplicate code in RTC modules Nhi Pham
2021-01-06 16:09 ` [PATCH v2 1/4] EmbeddedPkg/TimeBaseLib: Update comment blocks for API functions Nhi Pham
2021-01-06 16:09 ` [PATCH v2 2/4] EmbeddedPkg/TimeBaseLib: Fix for minor code formatting Nhi Pham
2021-01-06 16:09 ` Nhi Pham [this message]
2021-01-06 16:09 ` [PATCH v2 4/4] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib Nhi Pham
2021-01-07 17:42 ` [PATCH v2 0/4] EmbeddedPkg/TimeBaseLib: Reduce duplicate code in RTC modules Leif Lindholm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210106160903.27679-4-nhi@os.amperecomputing.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox