/** @file\r
Main file for time, timezone, and date shell level 2 and shell level 3 functions.\r
\r
- Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+ (C) Copyright 2012-2014, Hewlett-Packard Development Company, L.P.\r
+ Copyright (c) 2009 - 2014, 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
which accompanies this distribution. The full text of the license may be found at\r
\r
#include "UefiShellLevel2CommandsLib.h"\r
\r
-INT16\r
-EFIAPI\r
-AbsVal(\r
- INT16 v\r
- )\r
-{\r
- if (v>0) {\r
- return (v);\r
- }\r
- return ((INT16)(-v));\r
-}\r
+/**\r
+ Determine if String is a valid representation for a time or date.\r
\r
+ @param[in] String The pointer to the string to test.\r
+ @param[in] Char The delimeter character.\r
+ @param[in] Min The minimum value allowed.\r
+ @param[in] Max The maximum value allowed.\r
+ @param[in] MinusOk Whether negative numbers are permitted.\r
+\r
+ @retval TRUE String is a valid representation.\r
+ @retval FALSE String is invalid.\r
+**/\r
BOOLEAN\r
EFIAPI\r
InternalIsTimeLikeString (\r
return (TRUE);\r
}\r
\r
+/**\r
+ Verify that the DateString is valid and if so set that as the current \r
+ date.\r
+\r
+ @param[in] DateString The pointer to a string representation of the date.\r
+\r
+ @retval SHELL_INVALID_PARAMETER DateString was NULL.\r
+ @retval SHELL_INVALID_PARAMETER DateString was mis-formatted.\r
+ @retval SHELL_SUCCESS The operation was successful.\r
+**/\r
SHELL_STATUS\r
EFIAPI\r
CheckAndSetDate (\r
{\r
EFI_TIME TheTime;\r
EFI_STATUS Status;\r
- CONST CHAR16 *Walker;\r
+ CHAR16 *DateStringCopy;\r
+ CHAR16 *Walker;\r
+ CHAR16 *Walker1;\r
\r
if (!InternalIsTimeLikeString(DateString, L'/', 2, 2, FALSE)) {\r
return (SHELL_INVALID_PARAMETER);\r
}\r
\r
Status = gRT->GetTime(&TheTime, NULL);\r
- ASSERT_EFI_ERROR(Status);\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
- Walker = DateString;\r
+ DateStringCopy = NULL;\r
+ DateStringCopy = StrnCatGrow(&DateStringCopy, NULL, DateString, 0);\r
+ if (DateStringCopy == NULL) {\r
+ return (SHELL_OUT_OF_RESOURCES);\r
+ }\r
+ Walker = DateStringCopy;\r
\r
TheTime.Month = 0xFF;\r
TheTime.Day = 0xFF;\r
TheTime.Year = 0xFFFF;\r
\r
- TheTime.Month = (UINT8)StrDecimalToUintn (Walker);\r
- Walker = StrStr(Walker, L"/");\r
- if (Walker != NULL && *Walker == L'/') {\r
- Walker = Walker + 1;\r
+ Walker1 = StrStr(Walker, L"/");\r
+ if (Walker1 != NULL && *Walker1 == L'/') {\r
+ *Walker1 = CHAR_NULL;\r
+ }\r
+\r
+ TheTime.Month = (UINT8)ShellStrToUintn (Walker);\r
+ if (Walker1 != NULL) {\r
+ Walker = Walker1 + 1;\r
+ }\r
+ Walker1 = Walker!=NULL?StrStr(Walker, L"/"):NULL;\r
+ if (Walker1 != NULL && *Walker1 == L'/') {\r
+ *Walker1 = CHAR_NULL;\r
}\r
if (Walker != NULL && Walker[0] != CHAR_NULL) {\r
- TheTime.Day = (UINT8)StrDecimalToUintn (Walker);\r
- Walker = StrStr(Walker, L"/");\r
- if (Walker != NULL && *Walker == L'/') {\r
- Walker = Walker + 1;\r
+ TheTime.Day = (UINT8)ShellStrToUintn (Walker);\r
+ if (Walker1 != NULL) {\r
+ Walker = Walker1 + 1;\r
+ }\r
+ Walker1 = Walker!=NULL?StrStr(Walker, L"/"):NULL;\r
+ if (Walker1 != NULL && *Walker1 == L'/') {\r
+ *Walker1 = CHAR_NULL;\r
}\r
if (Walker != NULL && Walker[0] != CHAR_NULL) {\r
- TheTime.Year = (UINT16)StrDecimalToUintn (Walker);\r
+ TheTime.Year = (UINT16)ShellStrToUintn (Walker);\r
}\r
}\r
\r
EFI_TIME TheTime;\r
CHAR16 *ProblemParam;\r
SHELL_STATUS ShellStatus;\r
+ CONST CHAR16 *Param1;\r
\r
ShellStatus = SHELL_SUCCESS;\r
ProblemParam = NULL;\r
// get the current date\r
//\r
Status = gRT->GetTime(&TheTime, NULL);\r
- ASSERT_EFI_ERROR(Status);\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
//\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
//\r
// perform level 3 operation here.\r
//\r
- ShellStatus = CheckAndSetDate(ShellCommandLineGetRawValue(Package, 1));\r
+ Param1 = ShellCommandLineGetRawValue(Package, 1);\r
+ if (Param1 == NULL) {\r
+ ShellStatus = SHELL_INVALID_PARAMETER;\r
+ } else {\r
+ ShellStatus = CheckAndSetDate(Param1);\r
+ }\r
if (ShellStatus != SHELL_SUCCESS) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, Param1);\r
ShellStatus = SHELL_INVALID_PARAMETER;\r
}\r
}\r
{NULL, TypeMax}\r
};\r
\r
+/**\r
+ Verify that the TimeString is valid and if so set that as the current \r
+ time.\r
+\r
+ @param[in] TimeString The pointer to a string representation of the time.\r
+ @param[in] Tz The value to set for TimeZone.\r
+ @param[in] Daylight The value to set for Daylight.\r
+\r
+ @retval SHELL_INVALID_PARAMETER TimeString was NULL.\r
+ @retval SHELL_INVALID_PARAMETER TimeString was mis-formatted.\r
+ @retval SHELL_SUCCESS The operation was successful.\r
+**/\r
SHELL_STATUS\r
EFIAPI\r
CheckAndSetTime (\r
{\r
EFI_TIME TheTime;\r
EFI_STATUS Status;\r
- CONST CHAR16 *Walker;\r
+ CHAR16 *TimeStringCopy;\r
+ CHAR16 *Walker1;\r
+ CHAR16 *Walker2;\r
\r
if (TimeString != NULL && !InternalIsTimeLikeString(TimeString, L':', 1, 2, FALSE)) {\r
return (SHELL_INVALID_PARAMETER);\r
}\r
+ if (Daylight != 0xFF &&((Daylight & (EFI_TIME_IN_DAYLIGHT|EFI_TIME_ADJUST_DAYLIGHT)) != Daylight)) {\r
+ return (SHELL_INVALID_PARAMETER);\r
+ }\r
\r
Status = gRT->GetTime(&TheTime, NULL);\r
- ASSERT_EFI_ERROR(Status);\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
if (TimeString != NULL) {\r
- Walker = TimeString;\r
+ TimeStringCopy = NULL;\r
+ TimeStringCopy = StrnCatGrow(&TimeStringCopy, NULL, TimeString, 0);\r
+ Walker1 = TimeStringCopy;\r
TheTime.Hour = 0xFF;\r
TheTime.Minute = 0xFF;\r
\r
- TheTime.Hour = (UINT8)StrDecimalToUintn (Walker);\r
- Walker = StrStr(Walker, L":");\r
- if (Walker != NULL && *Walker == L':') {\r
- Walker = Walker + 1;\r
+ Walker2 = Walker1!=NULL?StrStr(Walker1, L":"):NULL;\r
+ if (Walker2 != NULL && *Walker2 == L':') {\r
+ *Walker2 = CHAR_NULL;\r
}\r
- if (Walker != NULL && Walker[0] != CHAR_NULL) {\r
- TheTime.Minute = (UINT8)StrDecimalToUintn (Walker);\r
- Walker = StrStr(Walker, L":");\r
- if (Walker != NULL && *Walker == L':') {\r
- Walker = Walker + 1;\r
- }\r
- if (Walker != NULL && Walker[0] != CHAR_NULL) {\r
- TheTime.Second = (UINT8)StrDecimalToUintn (Walker);\r
+ TheTime.Hour = (UINT8)ShellStrToUintn (Walker1);\r
+ if (Walker2 != NULL) {\r
+ Walker1 = Walker2 + 1;\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
+ 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
- if ((Tz >= -1440 && Tz <= 1440)||(Tz == 2047)) {\r
+\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
- if (Daylight <= 3 && Daylight != 2) {\r
+\r
+ if (Daylight != 0xFF) {\r
TheTime.Daylight = Daylight;\r
}\r
+\r
Status = gRT->SetTime(&TheTime);\r
\r
if (!EFI_ERROR(Status)){\r
{\r
EFI_STATUS Status;\r
LIST_ENTRY *Package;\r
- CHAR16 *Message;\r
EFI_TIME TheTime;\r
CHAR16 *ProblemParam;\r
SHELL_STATUS ShellStatus;\r
CONST CHAR16 *TempLocation;\r
UINTN TzMinutes;\r
\r
- ShellStatus = SHELL_SUCCESS;\r
- ProblemParam = NULL;\r
-\r
//\r
// Initialize variables\r
//\r
- Message = NULL;\r
+ ShellStatus = SHELL_SUCCESS;\r
+ ProblemParam = NULL;\r
\r
//\r
// initialize the shell lib (we must be in non-auto-init...)\r
// check for "-?"\r
//\r
Status = gRT->GetTime(&TheTime, NULL);\r
- ASSERT_EFI_ERROR(Status);\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
if (ShellCommandLineGetFlag(Package, L"-?")) {\r
ASSERT(FALSE);\r
} else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {\r
//\r
// ShellPrintEx the current time\r
//\r
- if (TheTime.TimeZone == 2047) {\r
+ if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {\r
TzMinutes = 0;\r
} else {\r
- TzMinutes = AbsVal(TheTime.TimeZone) % 60;\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==2047?L" ":(TheTime.TimeZone > 0?L"-":L"+"),\r
- TheTime.TimeZone==2047?0:AbsVal(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 == 2047) {\r
- TzMinutes = 0;\r
+ if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {\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 = AbsVal(TheTime.TimeZone) % 60;\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==2047?L" ":(TheTime.TimeZone > 0?L"-":L"+"),\r
- TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,\r
- TzMinutes\r
- );\r
switch (TheTime.Daylight) {\r
case 0:\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DSTNA), gShellLevel2HiiHandle);\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST0), gShellLevel2HiiHandle);\r
break;\r
case EFI_TIME_ADJUST_DAYLIGHT:\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DSTST), gShellLevel2HiiHandle);\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST1), gShellLevel2HiiHandle);\r
break;\r
case EFI_TIME_IN_DAYLIGHT:\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DSTDT), gShellLevel2HiiHandle);\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST2), gShellLevel2HiiHandle);\r
+ break;\r
+ case EFI_TIME_IN_DAYLIGHT|EFI_TIME_ADJUST_DAYLIGHT:\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST3), gShellLevel2HiiHandle);\r
break;\r
default:\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_ERROR), gShellLevel2HiiHandle, L"gRT->GetTime", L"TheTime.Daylight", TheTime.Daylight);\r
// perform level 3 operation here.\r
//\r
if ((TempLocation = ShellCommandLineGetValue(Package, L"-tz")) != NULL) {\r
- if (TempLocation[0] == L'-') {\r
- Tz = (INT16)(0 - StrDecimalToUintn(++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)StrDecimalToUintn(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 != 2047) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"-d");\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
ShellStatus = SHELL_INVALID_PARAMETER;\r
}\r
} else {\r
}\r
TempLocation = ShellCommandLineGetValue(Package, L"-d");\r
if (TempLocation != NULL) {\r
- Daylight = (UINT8)StrDecimalToUintn(TempLocation);\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), gShellLevel2HiiHandle, L"-d");\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"-d");\r
ShellStatus = SHELL_INVALID_PARAMETER;\r
}\r
} else {\r
STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList3[] = {\r
{L"-l", TypeFlag},\r
{L"-f", TypeFlag},\r
- {L"-s", TypeValue},\r
+ {L"-s", TypeTimeValue},\r
{NULL, TypeMax}\r
};\r
\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
- };\r
+ {-840 , STRING_TOKEN (STR_TIMEZONE_P14)},\r
+ {EFI_UNSPECIFIED_TIMEZONE, STRING_TOKEN (STR_TIMEZONE_LOCAL)}\r
+};\r
+\r
+/**\r
+ Verify that the TimeZoneString is valid and if so set that as the current \r
+ timezone.\r
\r
+ @param[in] TimeZoneString The pointer to a string representation of the timezone.\r
+\r
+ @retval SHELL_INVALID_PARAMETER TimeZoneString was NULL.\r
+ @retval SHELL_INVALID_PARAMETER TimeZoneString was mis-formatted.\r
+ @retval SHELL_SUCCESS The operation was successful.\r
+**/\r
SHELL_STATUS\r
EFIAPI\r
CheckAndSetTimeZone (\r
{\r
EFI_TIME TheTime;\r
EFI_STATUS Status;\r
- CONST CHAR16 *Walker;\r
+ CHAR16 *TimeZoneCopy;\r
+ CHAR16 *Walker;\r
+ CHAR16 *Walker2;\r
UINTN LoopVar;\r
\r
if (TimeZoneString == NULL) {\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
Status = gRT->GetTime(&TheTime, NULL);\r
- ASSERT_EFI_ERROR(Status);\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
- Walker = TimeZoneString;\r
+ TimeZoneCopy = NULL;\r
+ TimeZoneCopy = StrnCatGrow(&TimeZoneCopy, NULL, TimeZoneString, 0);\r
+ if (TimeZoneCopy == NULL) {\r
+ return (SHELL_OUT_OF_RESOURCES);\r
+ }\r
+ Walker = TimeZoneCopy;\r
+ Walker2 = StrStr(Walker, L":");\r
+ if (Walker2 != NULL && *Walker2 == L':') {\r
+ *Walker2 = CHAR_NULL;\r
+ }\r
if (*Walker == L'-') {\r
- TheTime.TimeZone = (INT16)((StrDecimalToUintn (++Walker)) * 60);\r
+ TheTime.TimeZone = (INT16)((ShellStrToUintn (++Walker)) * 60);\r
} else {\r
- TheTime.TimeZone = (INT16)((StrDecimalToUintn (Walker)) * -60);\r
+ TheTime.TimeZone = (INT16)((INT16)(ShellStrToUintn (Walker)) * -60);\r
}\r
- Walker = StrStr(Walker, L":");\r
- if (Walker != NULL && *Walker == L':') {\r
- Walker = Walker + 1;\r
+ if (Walker2 != NULL) {\r
+ Walker = Walker2 + 1;\r
}\r
if (Walker != NULL && Walker[0] != CHAR_NULL) {\r
if (TheTime.TimeZone < 0) {\r
- TheTime.TimeZone = (INT16)(TheTime.TimeZone - (UINT8)StrDecimalToUintn (Walker));\r
+ TheTime.TimeZone = (INT16)(TheTime.TimeZone - (UINT8)ShellStrToUintn (Walker));\r
} else {\r
- TheTime.TimeZone = (INT16)(TheTime.TimeZone + (UINT8)StrDecimalToUintn (Walker));\r
+ TheTime.TimeZone = (INT16)(TheTime.TimeZone + (UINT8)ShellStrToUintn (Walker));\r
}\r
}\r
\r
}\r
}\r
\r
+ FreePool(TimeZoneCopy);\r
+\r
if (!EFI_ERROR(Status)){\r
return (SHELL_SUCCESS);\r
}\r
// parse the command line\r
//\r
if (PcdGet8(PcdShellSupportLevel) == 2) {\r
- Status = ShellCommandLineParse (TimeZoneParamList2, &Package, &ProblemParam, FALSE);\r
+ Status = ShellCommandLineParse (TimeZoneParamList2, &Package, &ProblemParam, TRUE);\r
} else {\r
ASSERT(PcdGet8(PcdShellSupportLevel) == 3);\r
- Status = ShellCommandLineParseEx (TimeZoneParamList3, &Package, &ProblemParam, FALSE, TRUE);\r
+ Status = ShellCommandLineParseEx (TimeZoneParamList3, &Package, &ProblemParam, TRUE, TRUE);\r
}\r
if (EFI_ERROR(Status)) {\r
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
// Get Current Time Zone Info\r
//\r
Status = gRT->GetTime(&TheTime, NULL);\r
- ASSERT_EFI_ERROR(Status);\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
- if (TheTime.TimeZone != 2047) {\r
+ if (TheTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) {\r
Found = FALSE;\r
for ( LoopVar = 0\r
; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0])\r
//\r
// Print basic info only\r
//\r
- if (TheTime.TimeZone == 2047) {\r
- TzMinutes = 0;\r
- } else {\r
- TzMinutes = AbsVal(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==2047?0:(TheTime.TimeZone > 0?L"-":L"+"),\r
- TheTime.TimeZone==2047?0:AbsVal(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 == 2047) {\r
- TzMinutes = 0;\r
- } else {\r
- TzMinutes = AbsVal(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==2047?0:(TheTime.TimeZone > 0?L"-":L"+"),\r
- TheTime.TimeZone==2047?0:AbsVal(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 2047 (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