public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
To: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org,
	edk2-devel@lists.01.org
Subject: [PATCH v3] EmbeddedPkg/TimeBaseLib: Add function to get Week day.
Date: Mon,  4 Jun 2018 22:01:44 +0530	[thread overview]
Message-ID: <1528129904-28171-1-git-send-email-meenakshi.aggarwal@nxp.com> (raw)
In-Reply-To: <1527796029-10160-1-git-send-email-meenakshi.aggarwal@nxp.com>

This patch add function EfiTimeToWday() which returns
day of the week.
It is needed by our upcoming patches in edk2-platforms.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Vabhav Sharma <vabhav.sharma@nxp.com>
Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
---
 EmbeddedPkg/Include/Library/TimeBaseLib.h     |  8 ++++++
 EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 38 ++++++++++++++++++++++++---
 2 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/EmbeddedPkg/Include/Library/TimeBaseLib.h b/EmbeddedPkg/Include/Library/TimeBaseLib.h
index fe3618e..dd0b99f 100644
--- a/EmbeddedPkg/Include/Library/TimeBaseLib.h
+++ b/EmbeddedPkg/Include/Library/TimeBaseLib.h
@@ -65,4 +65,12 @@ EfiTimeToEpoch (
   IN  EFI_TIME  *Time
   );
 
+/**
+  returns Day of the week [0-6] 0=Sunday
+ **/
+UINTN
+EfiTimeToWday (
+  IN  EFI_TIME  *Time
+  );
+
 #endif
diff --git a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
index 0c0d940..5f2bf65 100644
--- a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
+++ b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
@@ -77,11 +77,11 @@ EpochToEfiTime (
 }
 
 /**
-  Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)
+  Calculate Epoch days
  **/
 UINTN
 EFIAPI
-EfiTimeToEpoch (
+EfiGetEpochDays (
   IN  EFI_TIME  *Time
   )
 {
@@ -90,7 +90,6 @@ EfiTimeToEpoch (
   UINTN m;
   UINTN JulianDate;  // Absolute Julian Date representation of the supplied Time
   UINTN EpochDays;   // Number of days elapsed since EPOCH_JULIAN_DAY
-  UINTN EpochSeconds;
 
   a = (14 - Time->Month) / 12 ;
   y = Time->Year + 4800 - a;
@@ -101,11 +100,44 @@ EfiTimeToEpoch (
   ASSERT (JulianDate >= EPOCH_JULIAN_DATE);
   EpochDays = JulianDate - EPOCH_JULIAN_DATE;
 
+  return EpochDays;
+}
+/**
+  Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)
+ **/
+UINTN
+EFIAPI
+EfiTimeToEpoch (
+  IN  EFI_TIME  *Time
+  )
+{
+  UINTN EpochDays;   // Number of days elapsed since EPOCH_JULIAN_DAY
+  UINTN EpochSeconds;
+
+  EpochDays = EfiGetEpochDays (Time);
+
   EpochSeconds = (EpochDays * SEC_PER_DAY) + ((UINTN)Time->Hour * SEC_PER_HOUR) + (Time->Minute * SEC_PER_MIN) + Time->Second;
 
   return EpochSeconds;
 }
 
+/**
+  returns Day of the week [0-6] 0=Sunday
+ **/
+UINTN
+EfiTimeToWday (
+  IN  EFI_TIME  *Time
+  )
+{
+  UINTN EpochDays;   // Number of days elapsed since EPOCH_JULIAN_DAY
+
+  EpochDays = EfiGetEpochDays (Time);
+
+  // 4=1/1/1970 was a Thursday
+
+  return (EpochDays + 4) % 7;
+}
+
 BOOLEAN
 EFIAPI
 IsLeapYear (
-- 
1.9.1



  parent reply	other threads:[~2018-06-04 10:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-31 17:02 [PATCH] EmbeddedPkg/TimeBaseLib: Add function to get Week day Meenakshi Aggarwal
2018-05-31 13:07 ` Ard Biesheuvel
2018-05-31 13:47   ` Meenakshi Aggarwal
2018-05-31 19:47 ` [PATCH v2] " Meenakshi Aggarwal
2018-05-31 14:28   ` Ard Biesheuvel
2018-06-04 16:31   ` Meenakshi Aggarwal [this message]
2018-06-05 15:40     ` [PATCH v3] " 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=1528129904-28171-1-git-send-email-meenakshi.aggarwal@nxp.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