diff options
author | Li Huajing <huajing.li@intel.com> | 2017-07-24 15:46:03 +0800 |
---|---|---|
committer | Ruiyu Ni <ruiyu.ni@intel.com> | 2017-07-26 13:31:17 +0800 |
commit | 99849a906e15ea3a9a0330d69bbae0d21ff49808 (patch) | |
tree | 4fb2b84f5ff91ce4bef140737d20edbe59f4f15d /ShellPkg | |
parent | c46aeceaf69ce777606f4825d6412bba6c25f193 (diff) | |
download | edk2-99849a906e15ea3a9a0330d69bbae0d21ff49808.tar.gz edk2-99849a906e15ea3a9a0330d69bbae0d21ff49808.tar.bz2 edk2-99849a906e15ea3a9a0330d69bbae0d21ff49808.zip |
ShellPkg/ls: Display the file time in local time.
Signed-off-by: Li Huajing <huajing.li@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Diffstat (limited to 'ShellPkg')
-rw-r--r-- | ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c | 118 |
1 files changed, 117 insertions, 1 deletions
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c index 52ae18f19b..7d2e15f520 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c @@ -2,7 +2,7 @@ Main file for ls shell level 2 function.
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
- Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -16,6 +16,8 @@ #include "UefiShellLevel2CommandsLib.h"
#include <Guid/FileSystemInfo.h>
+UINTN mDayOfMonth[] = {31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30};
+
/**
print out the standard format output volume entry.
@@ -319,6 +321,96 @@ PrintNonSfoFooter( }
/**
+ Change the file time to local time based on the timezone.
+
+ @param[in] Time The file time.
+ @param[in] LocalTimeZone Local time zone.
+**/
+VOID
+FileTimeToLocalTime (
+ IN EFI_TIME *Time,
+ IN INT16 LocalTimeZone
+ )
+{
+ INTN MinuteDiff;
+ INTN TempMinute;
+ INTN HourNumberOfTempMinute;
+ INTN TempHour;
+ INTN DayNumberOfTempHour;
+ INTN TempDay;
+ INTN MonthNumberOfTempDay;
+ INTN TempMonth;
+ INTN YearNumberOfTempMonth;
+ INTN MonthRecord;
+
+ ASSERT ((Time->TimeZone >= -1440) && (Time->TimeZone <=1440));
+ ASSERT ((LocalTimeZone >= -1440) && (LocalTimeZone <=1440));
+ ASSERT ((Time->Month >= 1) && (Time->Month <= 12));
+
+ if(Time->TimeZone == LocalTimeZone) {
+ //
+ //if the file timezone is equal to the local timezone, there is no need to adjust the file time.
+ //
+ return;
+ }
+
+ if((Time->Year % 4 == 0 && Time->Year / 100 != 0)||(Time->Year % 400 == 0)) {
+ //
+ // Day in February of leap year is 29.
+ //
+ mDayOfMonth[1] = 29;
+ }
+
+ MinuteDiff = Time->TimeZone - LocalTimeZone;
+ TempMinute = Time->Minute + MinuteDiff;
+
+ //
+ // Calculate Time->Minute
+ // TempHour will be used to calculate Time->Hour
+ //
+ HourNumberOfTempMinute = TempMinute / 60;
+ if(TempMinute < 0) {
+ HourNumberOfTempMinute --;
+ }
+ TempHour = Time->Hour + HourNumberOfTempMinute;
+ Time->Minute = (UINT8)(TempMinute - 60 * HourNumberOfTempMinute);
+
+ //
+ // Calculate Time->Hour
+ // TempDay will be used to calculate Time->Day
+ //
+ DayNumberOfTempHour = TempHour / 24 ;
+ if(TempHour < 0){
+ DayNumberOfTempHour--;
+ }
+ TempDay = Time->Day + DayNumberOfTempHour;
+ Time->Hour = (UINT8)(TempHour - 24 * DayNumberOfTempHour);
+
+ //
+ // Calculate Time->Day
+ // TempMonth will be used to calculate Time->Month
+ //
+ MonthNumberOfTempDay = (TempDay - 1) / (INTN)mDayOfMonth[Time->Month - 1];
+ MonthRecord = (INTN)(Time->Month) ;
+ if(TempDay - 1 < 0){
+ MonthNumberOfTempDay -- ;
+ MonthRecord -- ;
+ }
+ TempMonth = Time->Month + MonthNumberOfTempDay;
+ Time->Day = (UINT8)(TempDay - (INTN)mDayOfMonth[(MonthRecord - 1 + 12) % 12] * MonthNumberOfTempDay);
+
+ //
+ // Calculate Time->Month, Time->Year
+ //
+ YearNumberOfTempMonth = (TempMonth - 1) / 12;
+ if(TempMonth - 1 < 0){
+ YearNumberOfTempMonth --;
+ }
+ Time->Month = (UINT8)(TempMonth - 12 * (YearNumberOfTempMonth));
+ Time->Year = (UINT16)(Time->Year + YearNumberOfTempMonth);
+}
+
+/**
print out the list of files and directories from the LS command
@param[in] Rec TRUE to automatically recurse into each found directory
@@ -357,6 +449,7 @@ PrintLsOutput( CHAR16 *CorrectedPath;
BOOLEAN FoundOne;
BOOLEAN HeaderPrinted;
+ EFI_TIME LocalTime;
HeaderPrinted = FALSE;
FileCount = 0;
@@ -408,6 +501,29 @@ PrintLsOutput( break;
}
ASSERT(Node != NULL);
+
+ //
+ // Change the file time to local time.
+ //
+ Status = gRT->GetTime(&LocalTime, NULL);
+ if (!EFI_ERROR (Status)) {
+ if ((Node->Info->CreateTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) &&
+ (Node->Info->CreateTime.Month >= 1 && Node->Info->CreateTime.Month <= 12)) {
+ //
+ // FileTimeToLocalTime () requires Month is in a valid range, other buffer out-of-band access happens.
+ //
+ FileTimeToLocalTime (&Node->Info->CreateTime, LocalTime.TimeZone);
+ }
+ if ((Node->Info->LastAccessTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) &&
+ (Node->Info->LastAccessTime.Month >= 1 && Node->Info->LastAccessTime.Month <= 12)) {
+ FileTimeToLocalTime (&Node->Info->LastAccessTime, LocalTime.TimeZone);
+ }
+ if ((Node->Info->ModificationTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) &&
+ (Node->Info->ModificationTime.Month >= 1 && Node->Info->ModificationTime.Month <= 12)) {
+ FileTimeToLocalTime (&Node->Info->ModificationTime, LocalTime.TimeZone);
+ }
+ }
+
if (LongestPath < StrSize(Node->FullName)) {
LongestPath = StrSize(Node->FullName);
}
|