/** @file\r
Main file for time, timezone, and date shell level 2 and shell level 3 functions.\r
\r
+ (C) Copyright 2012-2014, Hewlett-Packard Development Company, L.P.\r
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
// ShellPrintEx the date in SFO or regular format\r
//\r
if (ShellCommandLineGetFlag(Package, L"-sfo")) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DATE_SFO_FORMAT), gShellLevel2HiiHandle, TheTime.Month, TheTime.Day, TheTime.Year);\r
+ //\r
+ // Match UEFI Shell spec:\r
+ // ShellCommand,"date"\r
+ // Date,"DD","MM","YYYY"\r
+ //\r
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellLevel2HiiHandle, L"date");\r
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DATE_SFO_FORMAT), gShellLevel2HiiHandle, TheTime.Day, TheTime.Month, TheTime.Year);\r
} else {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DATE_FORMAT), gShellLevel2HiiHandle, TheTime.Month, TheTime.Day, TheTime.Year);\r
}\r
Walker2 = Walker1!=NULL?StrStr(Walker1, L":"):NULL;\r
if (Walker2 != NULL && *Walker2 == L':') {\r
*Walker2 = CHAR_NULL;\r
+ TheTime.Second = (UINT8)0;\r
+ }\r
+ else if (Walker2 == NULL) {\r
+ TheTime.Second = (UINT8)0;\r
}\r
if (Walker1 != NULL && Walker1[0] != CHAR_NULL) {\r
TheTime.Minute = (UINT8)ShellStrToUintn (Walker1);\r
if (Walker2 != NULL) {\r
Walker1 = Walker2 + 1;\r
- }\r
- if (Walker1 != NULL && Walker1[0] != CHAR_NULL) {\r
- TheTime.Second = (UINT8)ShellStrToUintn (Walker1);\r
+ if (Walker1 != NULL && Walker1[0] != CHAR_NULL) {\r
+ TheTime.Second = (UINT8)ShellStrToUintn (Walker1);\r
+ }\r
}\r
}\r
SHELL_FREE_NON_NULL(TimeStringCopy);\r
}\r
\r
\r
- if ((Tz >= -1440 && Tz <= 1440)||(Tz == 0x7FF)) {\r
+ if (Tz >= -1440 && Tz <= 1440) {\r
+ //\r
+ // EFI_TIME TimeZone is stored to meet the following calculation (see UEFI Spec):\r
+ // Localtime = UTC - TimeZone\r
+ // This means the sign must be changed for the user provided Tz.\r
+ // EX: User wants to set TimeZone to Pacific Standard Time, so runs\r
+ // time -tz -480 # set to UTC-08:00\r
+ // To meet the calculation, the sign must be changed.\r
+ //\r
+ TheTime.TimeZone = -Tz;\r
+ } else if (Tz == EFI_UNSPECIFIED_TIMEZONE) {\r
TheTime.TimeZone = Tz;\r
}\r
\r
TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
}\r
\r
- ShellPrintHiiEx (\r
- -1,\r
- -1,\r
- NULL,\r
- STRING_TOKEN (STR_TIME_FORMAT),\r
- gShellLevel2HiiHandle,\r
- TheTime.Hour,\r
- TheTime.Minute,\r
- TheTime.Second,\r
- TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?L" ":(TheTime.TimeZone > 0?L"-":L"+"),\r
- TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,\r
- TzMinutes\r
- );\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel2HiiHandle);\r
+ if (TheTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) {\r
+ ShellPrintHiiEx (\r
+ -1,\r
+ -1,\r
+ NULL,\r
+ STRING_TOKEN (STR_TIME_FORMAT),\r
+ gShellLevel2HiiHandle,\r
+ TheTime.Hour,\r
+ TheTime.Minute,\r
+ TheTime.Second,\r
+ (TheTime.TimeZone > 0?L"-":L"+"),\r
+ ((ABS(TheTime.TimeZone)) / 60),\r
+ TzMinutes\r
+ );\r
+ } else {\r
+ ShellPrintHiiEx (\r
+ -1,\r
+ -1,\r
+ NULL,\r
+ STRING_TOKEN (STR_TIME_FORMAT_LOCAL),\r
+ gShellLevel2HiiHandle,\r
+ TheTime.Hour,\r
+ TheTime.Minute,\r
+ TheTime.Second\r
+ );\r
+ }\r
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel2HiiHandle);\r
} else if (ShellCommandLineGetFlag(Package, L"-d") && ShellCommandLineGetValue(Package, L"-d") == NULL) {\r
if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {\r
- TzMinutes = 0;\r
+ ShellPrintHiiEx (\r
+ -1,\r
+ -1,\r
+ NULL,\r
+ STRING_TOKEN (STR_TIME_FORMAT_LOCAL),\r
+ gShellLevel2HiiHandle,\r
+ TheTime.Hour,\r
+ TheTime.Minute,\r
+ TheTime.Second\r
+ );\r
} else {\r
TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
+ ShellPrintHiiEx (\r
+ -1,\r
+ -1,\r
+ NULL,\r
+ STRING_TOKEN (STR_TIME_FORMAT),\r
+ gShellLevel2HiiHandle,\r
+ TheTime.Hour,\r
+ TheTime.Minute,\r
+ TheTime.Second,\r
+ (TheTime.TimeZone > 0?L"-":L"+"),\r
+ ((ABS(TheTime.TimeZone)) / 60),\r
+ TzMinutes\r
+ );\r
}\r
-\r
- ShellPrintHiiEx (\r
- -1,\r
- -1,\r
- NULL,\r
- STRING_TOKEN (STR_TIME_FORMAT),\r
- gShellLevel2HiiHandle,\r
- TheTime.Hour,\r
- TheTime.Minute,\r
- TheTime.Second,\r
- TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?L" ":(TheTime.TimeZone > 0?L"-":L"+"),\r
- TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,\r
- TzMinutes\r
- );\r
switch (TheTime.Daylight) {\r
case 0:\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST0), gShellLevel2HiiHandle);\r
// perform level 3 operation here.\r
//\r
if ((TempLocation = ShellCommandLineGetValue(Package, L"-tz")) != NULL) {\r
- if (TempLocation[0] == L'-') {\r
- Tz = (INT16)(0 - ShellStrToUintn(++TempLocation));\r
+ if (StrniCmp (TempLocation, L"_local", StrLen (TempLocation)) == NULL) {\r
+ Tz = EFI_UNSPECIFIED_TIMEZONE;\r
+ } else if (TempLocation[0] == L'-') {\r
+\r
+ Tz = (INT16) ShellStrToUintn (++TempLocation);\r
+ //\r
+ // When the argument of "time [-tz tz]" is not numeric, ShellStrToUintn() returns "-1".\r
+ // Here we can detect the argument error by checking the return of ShellStrToUintn().\r
+ //\r
+ if (Tz == -1) {\r
+ Tz = 1441; //make it to be out of bounds value\r
+ } else {\r
+ Tz *= (-1); //sign convert\r
+ }\r
} else {\r
- Tz = (INT16)ShellStrToUintn(TempLocation);\r
+ if (TempLocation[0] == L'+') {\r
+ Tz = (INT16)ShellStrToUintn (++TempLocation);\r
+ } else {\r
+ Tz = (INT16)ShellStrToUintn (TempLocation);\r
+ }\r
+ //\r
+ // Detect the return of ShellStrToUintn() to make sure the argument is valid.\r
+ //\r
+ if (Tz == -1) {\r
+ Tz = 1441; //make it to be out of bounds value\r
+ }\r
}\r
if (!(Tz >= -1440 && Tz <= 1440) && Tz != EFI_UNSPECIFIED_TIMEZONE) {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"-tz");\r
TempLocation = ShellCommandLineGetValue(Package, L"-d");\r
if (TempLocation != NULL) {\r
Daylight = (UINT8)ShellStrToUintn(TempLocation);\r
+ //\r
+ // The argument of "time [-d dl]" is unsigned, if the first character is '-',\r
+ // the argument is incorrect. That's because ShellStrToUintn() will skip past\r
+ // any '-' sign and convert what's next, forgetting the sign is here.\r
+ //\r
+ if (TempLocation[0] == '-') {\r
+ Daylight = 0xff; //make it invalid = will not use\r
+ }\r
if (Daylight != 0 && Daylight != 1 && Daylight != 3) {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"-d");\r
ShellStatus = SHELL_INVALID_PARAMETER;\r
{-660 , STRING_TOKEN (STR_TIMEZONE_P11)},\r
{-720 , STRING_TOKEN (STR_TIMEZONE_P12)},\r
{-780 , STRING_TOKEN (STR_TIMEZONE_P13)},\r
- {-840 , STRING_TOKEN (STR_TIMEZONE_P14)}\r
+ {-840 , STRING_TOKEN (STR_TIMEZONE_P14)},\r
+ {EFI_UNSPECIFIED_TIMEZONE, STRING_TOKEN (STR_TIMEZONE_LOCAL)}\r
};\r
\r
/**\r
return (SHELL_INVALID_PARAMETER);\r
}\r
\r
+ if (StrniCmp (TimeZoneString, L"_local", StrLen (TimeZoneString)) == NULL) {\r
+ Status = gRT->GetTime (&TheTime, NULL);\r
+ if (EFI_ERROR (Status)) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);\r
+ return (SHELL_DEVICE_ERROR);\r
+ }\r
+\r
+ TheTime.TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
+ Status = gRT->SetTime (&TheTime);\r
+ if (!EFI_ERROR(Status)){\r
+ return (SHELL_SUCCESS);\r
+ }\r
+ return (SHELL_INVALID_PARAMETER);\r
+ }\r
if (TimeZoneString != NULL && !InternalIsTimeLikeString(TimeZoneString, L':', 1, 1, TRUE)) {\r
return (SHELL_INVALID_PARAMETER);\r
}\r
//\r
// Print basic info only\r
//\r
- if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {\r
- TzMinutes = 0;\r
- } else {\r
- TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
- }\r
+ TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
\r
ShellPrintHiiEx (\r
-1,\r
NULL,\r
STRING_TOKEN(STR_TIMEZONE_SIMPLE),\r
gShellLevel2HiiHandle,\r
- TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(TheTime.TimeZone > 0?L"-":L"+"),\r
- TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,\r
+ (TheTime.TimeZone > 0?L"-":L"+"),\r
+ (ABS(TheTime.TimeZone)) / 60,\r
TzMinutes);\r
}\r
Found = TRUE;\r
//\r
// Print basic info only\r
//\r
- if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {\r
- TzMinutes = 0;\r
- } else {\r
- TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
- }\r
+ TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
+\r
ShellPrintHiiEx (\r
-1,\r
-1,\r
NULL,\r
STRING_TOKEN(STR_TIMEZONE_SIMPLE),\r
gShellLevel2HiiHandle,\r
- TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(TheTime.TimeZone > 0?L"-":L"+"),\r
- TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,\r
+ (TheTime.TimeZone > 0?L"-":L"+"),\r
+ (ABS(TheTime.TimeZone)) / 60,\r
TzMinutes);\r
+\r
if (ShellCommandLineGetFlag(Package, L"-f")) {\r
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN(STR_TIMEZONE_NI), gShellLevel2HiiHandle);\r
}\r
}\r
} else {\r
//\r
- // TimeZone was EFI_UNSPECIFIED_TIMEZONE (unknown) from GetTime()\r
+ // TimeZone was EFI_UNSPECIFIED_TIMEZONE (local) from GetTime()\r
//\r
+ if (ShellCommandLineGetFlag (Package, L"-f")) {\r
+ for ( LoopVar = 0\r
+ ; LoopVar < sizeof (TimeZoneList) / sizeof (TimeZoneList[0])\r
+ ; LoopVar++\r
+ ){\r
+ if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) {\r
+ //\r
+ // Print all info about current time zone\r
+ //\r
+ ShellPrintHiiEx (-1, -1, NULL, TimeZoneList[LoopVar].StringId, gShellLevel2HiiHandle);\r
+ break;\r
+ } \r
+ }\r
+ } else {\r
+ //\r
+ // Print basic info only\r
+ //\r
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_TIMEZONE_SIMPLE_LOCAL), gShellLevel2HiiHandle);\r
+ }\r
}\r
}\r
}\r