2 Main file for time, timezone, and date shell level 2 and shell level 3 functions.
4 (C) Copyright 2012-2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "UefiShellLevel2CommandsLib.h"
13 Determine if String is a valid representation for a time or date.
15 @param[in] String The pointer to the string to test.
16 @param[in] Char The delimeter character.
17 @param[in] Min The minimum value allowed.
18 @param[in] Max The maximum value allowed.
19 @param[in] MinusOk Whether negative numbers are permitted.
21 @retval TRUE String is a valid representation.
22 @retval FALSE String is invalid.
25 InternalIsTimeLikeString (
26 IN CONST CHAR16
*String
,
30 IN CONST BOOLEAN MinusOk
39 // A single minus is ok.
41 if (*String
== L
'-') {
47 // the first char must be numeric.
49 if (!ShellIsDecimalDigitCharacter (*String
)) {
54 // loop through the characters and use the lib function
56 for ( ; String
!= NULL
&& *String
!= CHAR_NULL
; String
++) {
57 if (*String
== Char
) {
66 if (!ShellIsDecimalDigitCharacter (*String
)) {
79 Verify that the DateString is valid and if so set that as the current
82 @param[in] DateString The pointer to a string representation of the date.
84 @retval SHELL_INVALID_PARAMETER DateString was NULL.
85 @retval SHELL_INVALID_PARAMETER DateString was mis-formatted.
86 @retval SHELL_SUCCESS The operation was successful.
90 IN CONST CHAR16
*DateString
95 CHAR16
*DateStringCopy
;
99 if (!InternalIsTimeLikeString (DateString
, L
'/', 2, 2, FALSE
)) {
100 return (SHELL_INVALID_PARAMETER
);
103 Status
= gRT
->GetTime (&TheTime
, NULL
);
104 if (EFI_ERROR (Status
)) {
105 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"date", L
"gRT->GetTime", Status
);
106 return (SHELL_DEVICE_ERROR
);
109 DateStringCopy
= NULL
;
110 DateStringCopy
= StrnCatGrow (&DateStringCopy
, NULL
, DateString
, 0);
111 if (DateStringCopy
== NULL
) {
112 return (SHELL_OUT_OF_RESOURCES
);
115 Walker
= DateStringCopy
;
117 TheTime
.Month
= 0xFF;
119 TheTime
.Year
= 0xFFFF;
121 Walker1
= StrStr (Walker
, L
"/");
122 if ((Walker1
!= NULL
) && (*Walker1
== L
'/')) {
123 *Walker1
= CHAR_NULL
;
126 TheTime
.Month
= (UINT8
)ShellStrToUintn (Walker
);
127 if (Walker1
!= NULL
) {
128 Walker
= Walker1
+ 1;
131 Walker1
= Walker
!= NULL
? StrStr (Walker
, L
"/") : NULL
;
132 if ((Walker1
!= NULL
) && (*Walker1
== L
'/')) {
133 *Walker1
= CHAR_NULL
;
136 if ((Walker
!= NULL
) && (Walker
[0] != CHAR_NULL
)) {
137 TheTime
.Day
= (UINT8
)ShellStrToUintn (Walker
);
138 if (Walker1
!= NULL
) {
139 Walker
= Walker1
+ 1;
142 Walker1
= Walker
!= NULL
? StrStr (Walker
, L
"/") : NULL
;
143 if ((Walker1
!= NULL
) && (*Walker1
== L
'/')) {
144 *Walker1
= CHAR_NULL
;
147 if ((Walker
!= NULL
) && (Walker
[0] != CHAR_NULL
)) {
148 TheTime
.Year
= (UINT16
)ShellStrToUintn (Walker
);
152 if (TheTime
.Year
< 100) {
153 if (TheTime
.Year
>= 98) {
154 TheTime
.Year
= (UINT16
)(1900 + TheTime
.Year
);
156 TheTime
.Year
= (UINT16
)(2000 + TheTime
.Year
);
160 Status
= gRT
->SetTime (&TheTime
);
162 if (!EFI_ERROR (Status
)) {
163 return (SHELL_SUCCESS
);
166 return (SHELL_INVALID_PARAMETER
);
170 Function for 'date' command.
172 @param[in] ImageHandle Handle to the Image (NULL if Internal).
173 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
177 ShellCommandRunDate (
178 IN EFI_HANDLE ImageHandle
,
179 IN EFI_SYSTEM_TABLE
*SystemTable
185 CHAR16
*ProblemParam
;
186 SHELL_STATUS ShellStatus
;
187 CONST CHAR16
*Param1
;
189 ShellStatus
= SHELL_SUCCESS
;
193 // initialize the shell lib (we must be in non-auto-init...)
195 Status
= ShellInitialize ();
196 ASSERT_EFI_ERROR (Status
);
199 // parse the command line
201 Status
= ShellCommandLineParse (SfoParamList
, &Package
, &ProblemParam
, TRUE
);
202 if (EFI_ERROR (Status
)) {
203 if ((Status
== EFI_VOLUME_CORRUPTED
) && (ProblemParam
!= NULL
)) {
204 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"date", ProblemParam
);
205 FreePool (ProblemParam
);
206 ShellStatus
= SHELL_INVALID_PARAMETER
;
214 if (ShellCommandLineGetFlag (Package
, L
"-?")) {
216 } else if (ShellCommandLineGetRawValue (Package
, 2) != NULL
) {
217 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"date");
218 ShellStatus
= SHELL_INVALID_PARAMETER
;
221 // If there are 0 value parameters, then print the current date
222 // else If there are any value paramerers, then print error
224 if (ShellCommandLineGetRawValue (Package
, 1) == NULL
) {
226 // get the current date
228 Status
= gRT
->GetTime (&TheTime
, NULL
);
229 if (EFI_ERROR (Status
)) {
230 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"date", L
"gRT->GetTime", Status
);
231 return (SHELL_DEVICE_ERROR
);
235 // ShellPrintEx the date in SFO or regular format
237 if (ShellCommandLineGetFlag (Package
, L
"-sfo")) {
239 // Match UEFI Shell spec:
240 // ShellCommand,"date"
241 // Date,"DD","MM","YYYY"
243 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_SFO_HEADER
), gShellLevel2HiiHandle
, L
"date");
244 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DATE_SFO_FORMAT
), gShellLevel2HiiHandle
, TheTime
.Day
, TheTime
.Month
, TheTime
.Year
);
246 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DATE_FORMAT
), gShellLevel2HiiHandle
, TheTime
.Month
, TheTime
.Day
, TheTime
.Year
);
249 if (PcdGet8 (PcdShellSupportLevel
) == 2) {
250 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"date");
251 ShellStatus
= SHELL_INVALID_PARAMETER
;
254 // perform level 3 operation here.
256 Param1
= ShellCommandLineGetRawValue (Package
, 1);
257 if (Param1
== NULL
) {
258 ShellStatus
= SHELL_INVALID_PARAMETER
;
260 ShellStatus
= CheckAndSetDate (Param1
);
263 if (ShellStatus
!= SHELL_SUCCESS
) {
264 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"date", Param1
);
265 ShellStatus
= SHELL_INVALID_PARAMETER
;
273 // free the command line package
275 ShellCommandLineFreeVarList (Package
);
280 return (ShellStatus
);
284 // Note "-tz" is invalid for this (non-interactive) version of 'time'.
286 STATIC CONST SHELL_PARAM_ITEM TimeParamList2
[] = {
287 { L
"-d", TypeValue
},
291 STATIC CONST SHELL_PARAM_ITEM TimeParamList3
[] = {
292 { L
"-d", TypeValue
},
293 { L
"-tz", TypeValue
},
298 Verify that the TimeString is valid and if so set that as the current
301 @param[in] TimeString The pointer to a string representation of the time.
302 @param[in] Tz The value to set for TimeZone.
303 @param[in] Daylight The value to set for Daylight.
305 @retval SHELL_INVALID_PARAMETER TimeString was NULL.
306 @retval SHELL_INVALID_PARAMETER TimeString was mis-formatted.
307 @retval SHELL_SUCCESS The operation was successful.
311 IN CONST CHAR16
*TimeString
,
313 IN CONST UINT8 Daylight
318 CHAR16
*TimeStringCopy
;
322 if ((TimeString
!= NULL
) && !InternalIsTimeLikeString (TimeString
, L
':', 1, 2, FALSE
)) {
323 return (SHELL_INVALID_PARAMETER
);
326 if ((Daylight
!= 0xFF) && ((Daylight
& (EFI_TIME_IN_DAYLIGHT
|EFI_TIME_ADJUST_DAYLIGHT
)) != Daylight
)) {
327 return (SHELL_INVALID_PARAMETER
);
330 Status
= gRT
->GetTime (&TheTime
, NULL
);
331 if (EFI_ERROR (Status
)) {
332 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"time", L
"gRT->GetTime", Status
);
333 return (SHELL_DEVICE_ERROR
);
336 if (TimeString
!= NULL
) {
337 TimeStringCopy
= NULL
;
338 TimeStringCopy
= StrnCatGrow (&TimeStringCopy
, NULL
, TimeString
, 0);
339 Walker1
= TimeStringCopy
;
341 TheTime
.Minute
= 0xFF;
343 Walker2
= Walker1
!= NULL
? StrStr (Walker1
, L
":") : NULL
;
344 if ((Walker2
!= NULL
) && (*Walker2
== L
':')) {
345 *Walker2
= CHAR_NULL
;
348 TheTime
.Hour
= (UINT8
)ShellStrToUintn (Walker1
);
349 if (Walker2
!= NULL
) {
350 Walker1
= Walker2
+ 1;
353 Walker2
= Walker1
!= NULL
? StrStr (Walker1
, L
":") : NULL
;
354 if ((Walker2
!= NULL
) && (*Walker2
== L
':')) {
355 *Walker2
= CHAR_NULL
;
356 TheTime
.Second
= (UINT8
)0;
357 } else if (Walker2
== NULL
) {
358 TheTime
.Second
= (UINT8
)0;
361 if ((Walker1
!= NULL
) && (Walker1
[0] != CHAR_NULL
)) {
362 TheTime
.Minute
= (UINT8
)ShellStrToUintn (Walker1
);
363 if (Walker2
!= NULL
) {
364 Walker1
= Walker2
+ 1;
365 if ((Walker1
!= NULL
) && (Walker1
[0] != CHAR_NULL
)) {
366 TheTime
.Second
= (UINT8
)ShellStrToUintn (Walker1
);
371 SHELL_FREE_NON_NULL (TimeStringCopy
);
374 if ((Tz
>= -1440) && (Tz
<= 1440)) {
376 // EFI_TIME TimeZone is stored to meet the following calculation (see UEFI Spec):
377 // Localtime = UTC - TimeZone
378 // This means the sign must be changed for the user provided Tz.
379 // EX: User wants to set TimeZone to Pacific Standard Time, so runs
380 // time -tz -480 # set to UTC-08:00
381 // To meet the calculation, the sign must be changed.
383 TheTime
.TimeZone
= -Tz
;
384 } else if (Tz
== EFI_UNSPECIFIED_TIMEZONE
) {
385 TheTime
.TimeZone
= Tz
;
388 if (Daylight
!= 0xFF) {
389 TheTime
.Daylight
= Daylight
;
392 Status
= gRT
->SetTime (&TheTime
);
394 if (!EFI_ERROR (Status
)) {
395 return (SHELL_SUCCESS
);
398 return (SHELL_INVALID_PARAMETER
);
402 Function for 'time' command.
404 @param[in] ImageHandle Handle to the Image (NULL if Internal).
405 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
409 ShellCommandRunTime (
410 IN EFI_HANDLE ImageHandle
,
411 IN EFI_SYSTEM_TABLE
*SystemTable
417 CHAR16
*ProblemParam
;
418 SHELL_STATUS ShellStatus
;
421 CONST CHAR16
*TempLocation
;
425 // Initialize variables
427 ShellStatus
= SHELL_SUCCESS
;
431 // initialize the shell lib (we must be in non-auto-init...)
433 Status
= ShellInitialize ();
434 ASSERT_EFI_ERROR (Status
);
437 // parse the command line
439 if (PcdGet8 (PcdShellSupportLevel
) == 2) {
440 Status
= ShellCommandLineParseEx (TimeParamList2
, &Package
, &ProblemParam
, TRUE
, TRUE
);
442 ASSERT (PcdGet8 (PcdShellSupportLevel
) == 3);
443 Status
= ShellCommandLineParseEx (TimeParamList3
, &Package
, &ProblemParam
, TRUE
, TRUE
);
446 if (EFI_ERROR (Status
)) {
447 if ((Status
== EFI_VOLUME_CORRUPTED
) && (ProblemParam
!= NULL
)) {
448 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"time", ProblemParam
);
449 FreePool (ProblemParam
);
450 ShellStatus
= SHELL_INVALID_PARAMETER
;
458 Status
= gRT
->GetTime (&TheTime
, NULL
);
459 if (EFI_ERROR (Status
)) {
460 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"time", L
"gRT->GetTime", Status
);
461 return (SHELL_DEVICE_ERROR
);
464 if (ShellCommandLineGetFlag (Package
, L
"-?")) {
466 } else if (ShellCommandLineGetRawValue (Package
, 2) != NULL
) {
467 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"time");
468 ShellStatus
= SHELL_INVALID_PARAMETER
;
471 // If there are no parameters, then print the current time
473 if ( (ShellCommandLineGetRawValue (Package
, 1) == NULL
)
474 && !ShellCommandLineGetFlag (Package
, L
"-d")
475 && !ShellCommandLineGetFlag (Package
, L
"-tz"))
478 // ShellPrintEx the current time
480 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
483 TzMinutes
= (ABS (TheTime
.TimeZone
)) % 60;
486 if (TheTime
.TimeZone
!= EFI_UNSPECIFIED_TIMEZONE
) {
491 STRING_TOKEN (STR_TIME_FORMAT
),
492 gShellLevel2HiiHandle
,
496 (TheTime
.TimeZone
> 0 ? L
"-" : L
"+"),
497 ((ABS (TheTime
.TimeZone
)) / 60),
505 STRING_TOKEN (STR_TIME_FORMAT_LOCAL
),
506 gShellLevel2HiiHandle
,
513 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_CRLF
), gShellLevel2HiiHandle
);
514 } else if (ShellCommandLineGetFlag (Package
, L
"-d") && (ShellCommandLineGetValue (Package
, L
"-d") == NULL
)) {
515 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
520 STRING_TOKEN (STR_TIME_FORMAT_LOCAL
),
521 gShellLevel2HiiHandle
,
527 TzMinutes
= (ABS (TheTime
.TimeZone
)) % 60;
532 STRING_TOKEN (STR_TIME_FORMAT
),
533 gShellLevel2HiiHandle
,
537 (TheTime
.TimeZone
> 0 ? L
"-" : L
"+"),
538 ((ABS (TheTime
.TimeZone
)) / 60),
543 switch (TheTime
.Daylight
) {
545 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST0
), gShellLevel2HiiHandle
);
547 case EFI_TIME_ADJUST_DAYLIGHT
:
548 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST1
), gShellLevel2HiiHandle
);
550 case EFI_TIME_IN_DAYLIGHT
:
551 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST2
), gShellLevel2HiiHandle
);
553 case EFI_TIME_IN_DAYLIGHT
|EFI_TIME_ADJUST_DAYLIGHT
:
554 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST3
), gShellLevel2HiiHandle
);
557 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_ERROR
), gShellLevel2HiiHandle
, L
"time", L
"gRT->GetTime", L
"TheTime.Daylight", TheTime
.Daylight
);
560 if (PcdGet8 (PcdShellSupportLevel
) == 2) {
561 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"time");
562 ShellStatus
= SHELL_INVALID_PARAMETER
;
565 // perform level 3 operation here.
567 if ((TempLocation
= ShellCommandLineGetValue (Package
, L
"-tz")) != NULL
) {
568 if (gUnicodeCollation
->StriColl (gUnicodeCollation
, (CHAR16
*)TempLocation
, L
"_local") == 0) {
569 Tz
= EFI_UNSPECIFIED_TIMEZONE
;
570 } else if (TempLocation
[0] == L
'-') {
571 Tz
= (INT16
)ShellStrToUintn (++TempLocation
);
573 // When the argument of "time [-tz tz]" is not numeric, ShellStrToUintn() returns "-1".
574 // Here we can detect the argument error by checking the return of ShellStrToUintn().
577 Tz
= 1441; // make it to be out of bounds value
579 Tz
*= (-1); // sign convert
582 if (TempLocation
[0] == L
'+') {
583 Tz
= (INT16
)ShellStrToUintn (++TempLocation
);
585 Tz
= (INT16
)ShellStrToUintn (TempLocation
);
589 // Detect the return of ShellStrToUintn() to make sure the argument is valid.
592 Tz
= 1441; // make it to be out of bounds value
596 if (!((Tz
>= -1440) && (Tz
<= 1440)) && (Tz
!= EFI_UNSPECIFIED_TIMEZONE
)) {
597 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellLevel2HiiHandle
, L
"time", TempLocation
, L
"-tz");
598 ShellStatus
= SHELL_INVALID_PARAMETER
;
602 // intentionally out of bounds value will prevent changing it...
607 TempLocation
= ShellCommandLineGetValue (Package
, L
"-d");
608 if (TempLocation
!= NULL
) {
609 Daylight
= (UINT8
)ShellStrToUintn (TempLocation
);
611 // The argument of "time [-d dl]" is unsigned, if the first character is '-',
612 // the argument is incorrect. That's because ShellStrToUintn() will skip past
613 // any '-' sign and convert what's next, forgetting the sign is here.
615 if (TempLocation
[0] == '-') {
616 Daylight
= 0xff; // make it invalid = will not use
619 if ((Daylight
!= 0) && (Daylight
!= 1) && (Daylight
!= 3)) {
620 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellLevel2HiiHandle
, L
"time", TempLocation
, L
"-d");
621 ShellStatus
= SHELL_INVALID_PARAMETER
;
625 // invalid = will not use
630 if (ShellStatus
== SHELL_SUCCESS
) {
631 ShellStatus
= CheckAndSetTime (ShellCommandLineGetRawValue (Package
, 1), Tz
, Daylight
);
632 if (ShellStatus
!= SHELL_SUCCESS
) {
633 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"time", ShellCommandLineGetRawValue (Package
, 1));
634 ShellStatus
= SHELL_INVALID_PARAMETER
;
643 // free the command line package
645 ShellCommandLineFreeVarList (Package
);
650 return (ShellStatus
);
655 EFI_STRING_ID StringId
;
658 STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList2
[] = {
663 STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList3
[] = {
666 { L
"-s", TypeTimeValue
},
670 STATIC CONST TIME_ZONE_ITEM TimeZoneList
[] = {
671 { 720, STRING_TOKEN (STR_TIMEZONE_M12
) },
672 { 660, STRING_TOKEN (STR_TIMEZONE_M11
) },
673 { 600, STRING_TOKEN (STR_TIMEZONE_M10
) },
674 { 540, STRING_TOKEN (STR_TIMEZONE_M9
) },
675 { 480, STRING_TOKEN (STR_TIMEZONE_M8
) },
676 { 420, STRING_TOKEN (STR_TIMEZONE_M7
) },
677 { 360, STRING_TOKEN (STR_TIMEZONE_M6
) },
678 { 300, STRING_TOKEN (STR_TIMEZONE_M5
) },
679 { 270, STRING_TOKEN (STR_TIMEZONE_M430
) },
680 { 240, STRING_TOKEN (STR_TIMEZONE_M4
) },
681 { 210, STRING_TOKEN (STR_TIMEZONE_M330
) },
682 { 180, STRING_TOKEN (STR_TIMEZONE_M3
) },
683 { 120, STRING_TOKEN (STR_TIMEZONE_M2
) },
684 { 60, STRING_TOKEN (STR_TIMEZONE_M1
) },
685 { 0, STRING_TOKEN (STR_TIMEZONE_0
) },
686 { -60, STRING_TOKEN (STR_TIMEZONE_P1
) },
687 { -120, STRING_TOKEN (STR_TIMEZONE_P2
) },
688 { -180, STRING_TOKEN (STR_TIMEZONE_P3
) },
689 { -210, STRING_TOKEN (STR_TIMEZONE_P330
) },
690 { -240, STRING_TOKEN (STR_TIMEZONE_P4
) },
691 { -270, STRING_TOKEN (STR_TIMEZONE_P430
) },
692 { -300, STRING_TOKEN (STR_TIMEZONE_P5
) },
693 { -330, STRING_TOKEN (STR_TIMEZONE_P530
) },
694 { -345, STRING_TOKEN (STR_TIMEZONE_P545
) },
695 { -360, STRING_TOKEN (STR_TIMEZONE_P6
) },
696 { -390, STRING_TOKEN (STR_TIMEZONE_P630
) },
697 { -420, STRING_TOKEN (STR_TIMEZONE_P7
) },
698 { -480, STRING_TOKEN (STR_TIMEZONE_P8
) },
699 { -540, STRING_TOKEN (STR_TIMEZONE_P9
) },
700 { -570, STRING_TOKEN (STR_TIMEZONE_P930
) },
701 { -600, STRING_TOKEN (STR_TIMEZONE_P10
) },
702 { -660, STRING_TOKEN (STR_TIMEZONE_P11
) },
703 { -720, STRING_TOKEN (STR_TIMEZONE_P12
) },
704 { -780, STRING_TOKEN (STR_TIMEZONE_P13
) },
705 { -840, STRING_TOKEN (STR_TIMEZONE_P14
) },
706 { EFI_UNSPECIFIED_TIMEZONE
, STRING_TOKEN (STR_TIMEZONE_LOCAL
) }
710 Verify that the TimeZoneString is valid and if so set that as the current
713 @param[in] TimeZoneString The pointer to a string representation of the timezone.
715 @retval SHELL_INVALID_PARAMETER TimeZoneString was NULL.
716 @retval SHELL_INVALID_PARAMETER TimeZoneString was mis-formatted.
717 @retval SHELL_SUCCESS The operation was successful.
720 CheckAndSetTimeZone (
721 IN CONST CHAR16
*TimeZoneString
726 CHAR16
*TimeZoneCopy
;
731 if (TimeZoneString
== NULL
) {
732 return (SHELL_INVALID_PARAMETER
);
735 if (gUnicodeCollation
->StriColl (gUnicodeCollation
, (CHAR16
*)TimeZoneString
, L
"_local") == 0) {
736 Status
= gRT
->GetTime (&TheTime
, NULL
);
737 if (EFI_ERROR (Status
)) {
738 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
739 return (SHELL_DEVICE_ERROR
);
742 TheTime
.TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
743 Status
= gRT
->SetTime (&TheTime
);
744 if (!EFI_ERROR (Status
)) {
745 return (SHELL_SUCCESS
);
748 return (SHELL_INVALID_PARAMETER
);
751 if ((TimeZoneString
!= NULL
) && !InternalIsTimeLikeString (TimeZoneString
, L
':', 1, 1, TRUE
)) {
752 return (SHELL_INVALID_PARAMETER
);
755 Status
= gRT
->GetTime (&TheTime
, NULL
);
756 if (EFI_ERROR (Status
)) {
757 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"timezone", L
"gRT->GetTime", Status
);
758 return (SHELL_DEVICE_ERROR
);
762 TimeZoneCopy
= StrnCatGrow (&TimeZoneCopy
, NULL
, TimeZoneString
, 0);
763 if (TimeZoneCopy
== NULL
) {
764 return (SHELL_OUT_OF_RESOURCES
);
767 Walker
= TimeZoneCopy
;
768 Walker2
= StrStr (Walker
, L
":");
769 if ((Walker2
!= NULL
) && (*Walker2
== L
':')) {
770 *Walker2
= CHAR_NULL
;
773 if (*Walker
== L
'-') {
774 TheTime
.TimeZone
= (INT16
)((ShellStrToUintn (++Walker
)) * 60);
776 TheTime
.TimeZone
= (INT16
)((INT16
)(ShellStrToUintn (Walker
)) * -60);
779 if (Walker2
!= NULL
) {
780 Walker
= Walker2
+ 1;
783 if ((Walker
!= NULL
) && (Walker
[0] != CHAR_NULL
)) {
784 if (TheTime
.TimeZone
< 0) {
785 TheTime
.TimeZone
= (INT16
)(TheTime
.TimeZone
- (UINT8
)ShellStrToUintn (Walker
));
787 TheTime
.TimeZone
= (INT16
)(TheTime
.TimeZone
+ (UINT8
)ShellStrToUintn (Walker
));
791 Status
= EFI_INVALID_PARAMETER
;
794 ; LoopVar
< sizeof (TimeZoneList
) / sizeof (TimeZoneList
[0])
798 if (TheTime
.TimeZone
== TimeZoneList
[LoopVar
].TimeZone
) {
799 Status
= gRT
->SetTime (&TheTime
);
804 FreePool (TimeZoneCopy
);
806 if (!EFI_ERROR (Status
)) {
807 return (SHELL_SUCCESS
);
810 return (SHELL_INVALID_PARAMETER
);
814 Function for 'timezone' command.
816 @param[in] ImageHandle Handle to the Image (NULL if Internal).
817 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
821 ShellCommandRunTimeZone (
822 IN EFI_HANDLE ImageHandle
,
823 IN EFI_SYSTEM_TABLE
*SystemTable
831 CHAR16
*ProblemParam
;
832 SHELL_STATUS ShellStatus
;
838 ShellStatus
= SHELL_SUCCESS
;
842 // initialize the shell lib (we must be in non-auto-init...)
844 Status
= ShellInitialize ();
845 ASSERT_EFI_ERROR (Status
);
848 // parse the command line
850 if (PcdGet8 (PcdShellSupportLevel
) == 2) {
851 Status
= ShellCommandLineParse (TimeZoneParamList2
, &Package
, &ProblemParam
, TRUE
);
853 ASSERT (PcdGet8 (PcdShellSupportLevel
) == 3);
854 Status
= ShellCommandLineParseEx (TimeZoneParamList3
, &Package
, &ProblemParam
, TRUE
, TRUE
);
857 if (EFI_ERROR (Status
)) {
858 if ((Status
== EFI_VOLUME_CORRUPTED
) && (ProblemParam
!= NULL
)) {
859 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"timezone", ProblemParam
);
860 FreePool (ProblemParam
);
861 ShellStatus
= SHELL_INVALID_PARAMETER
;
869 if (ShellCommandLineGetCount (Package
) > 1) {
870 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"timezone");
871 ShellStatus
= SHELL_INVALID_PARAMETER
;
872 } else if (ShellCommandLineGetFlag (Package
, L
"-?")) {
874 } else if (ShellCommandLineGetFlag (Package
, L
"-s")) {
875 if ((ShellCommandLineGetFlag (Package
, L
"-l")) || (ShellCommandLineGetFlag (Package
, L
"-f"))) {
876 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"timezone", L
"-l or -f");
877 ShellStatus
= SHELL_INVALID_PARAMETER
;
879 ASSERT (PcdGet8 (PcdShellSupportLevel
) == 3);
880 if (ShellCommandLineGetValue (Package
, L
"-s") == NULL
) {
881 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellLevel2HiiHandle
, L
"timezone", L
"-s");
882 ShellStatus
= SHELL_INVALID_PARAMETER
;
887 ShellStatus
= CheckAndSetTimeZone (ShellCommandLineGetValue (Package
, L
"-s"));
888 if (ShellStatus
!= SHELL_SUCCESS
) {
889 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"timezone", ShellCommandLineGetValue (Package
, L
"-s"));
890 ShellStatus
= SHELL_INVALID_PARAMETER
;
894 } else if (ShellCommandLineGetFlag (Package
, L
"-l")) {
896 // Print a list of all time zones
899 ; LoopVar
< sizeof (TimeZoneList
) / sizeof (TimeZoneList
[0])
903 ShellPrintHiiEx (-1, -1, NULL
, TimeZoneList
[LoopVar
].StringId
, gShellLevel2HiiHandle
);
907 // Get Current Time Zone Info
909 Status
= gRT
->GetTime (&TheTime
, NULL
);
910 if (EFI_ERROR (Status
)) {
911 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"timezone", L
"gRT->GetTime", Status
);
912 return (SHELL_DEVICE_ERROR
);
915 if (TheTime
.TimeZone
!= EFI_UNSPECIFIED_TIMEZONE
) {
918 ; LoopVar
< sizeof (TimeZoneList
) / sizeof (TimeZoneList
[0])
922 if (TheTime
.TimeZone
== TimeZoneList
[LoopVar
].TimeZone
) {
923 if (ShellCommandLineGetFlag (Package
, L
"-f")) {
925 // Print all info about current time zone
927 ShellPrintHiiEx (-1, -1, NULL
, TimeZoneList
[LoopVar
].StringId
, gShellLevel2HiiHandle
);
930 // Print basic info only
932 TzMinutes
= (ABS (TheTime
.TimeZone
)) % 60;
938 STRING_TOKEN (STR_TIMEZONE_SIMPLE
),
939 gShellLevel2HiiHandle
,
940 (TheTime
.TimeZone
> 0 ? L
"-" : L
"+"),
941 (ABS (TheTime
.TimeZone
)) / 60,
953 // Print basic info only
955 TzMinutes
= (ABS (TheTime
.TimeZone
)) % 60;
961 STRING_TOKEN (STR_TIMEZONE_SIMPLE
),
962 gShellLevel2HiiHandle
,
963 (TheTime
.TimeZone
> 0 ? L
"-" : L
"+"),
964 (ABS (TheTime
.TimeZone
)) / 60,
968 if (ShellCommandLineGetFlag (Package
, L
"-f")) {
969 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_TIMEZONE_NI
), gShellLevel2HiiHandle
);
974 // TimeZone was EFI_UNSPECIFIED_TIMEZONE (local) from GetTime()
976 if (ShellCommandLineGetFlag (Package
, L
"-f")) {
978 ; LoopVar
< ARRAY_SIZE (TimeZoneList
)
982 if (TheTime
.TimeZone
== TimeZoneList
[LoopVar
].TimeZone
) {
984 // Print all info about current time zone
986 ShellPrintHiiEx (-1, -1, NULL
, TimeZoneList
[LoopVar
].StringId
, gShellLevel2HiiHandle
);
992 // Print basic info only
994 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_TIMEZONE_SIMPLE_LOCAL
), gShellLevel2HiiHandle
);
1001 // free the command line package
1003 ShellCommandLineFreeVarList (Package
);
1005 return (ShellStatus
);