EmbeddedPkg/TimeBaseLib: Add function to get Week day.

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>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
This commit is contained in:
Meenakshi Aggarwal 2018-06-04 22:01:44 +05:30 committed by Leif Lindholm
parent 1b6e7633ca
commit 91c31ff04a
2 changed files with 43 additions and 3 deletions

View File

@ -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

View File

@ -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 (