2 Main file for time, timezone, and date shell level 2 and shell level 3 functions.
4 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiShellLevel2CommandsLib.h"
18 Determine if String is a valid representation for a time or date.
20 @param[in] String The pointer to the string to test.
21 @param[in] Char The delimeter character.
22 @param[in] Min The minimum value allowed.
23 @param[in] Max The maximum value allowed.
24 @param[in] MinusOk Whether negative numbers are permitted.
26 @retval TRUE String is a valid representation.
27 @retval FALSE String is invalid.
31 InternalIsTimeLikeString (
32 IN CONST CHAR16
*String
,
36 IN CONST BOOLEAN MinusOk
44 // A single minus is ok.
46 if (*String
== L
'-') {
52 // the first char must be numeric.
54 if (!ShellIsDecimalDigitCharacter(*String
)) {
58 // loop through the characters and use the lib function
60 for ( ; String
!= NULL
&& *String
!= CHAR_NULL
; String
++){
61 if (*String
== Char
) {
68 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.
91 IN CONST CHAR16
*DateString
96 CHAR16
*DateStringCopy
;
100 if (!InternalIsTimeLikeString(DateString
, L
'/', 2, 2, FALSE
)) {
101 return (SHELL_INVALID_PARAMETER
);
104 Status
= gRT
->GetTime(&TheTime
, NULL
);
105 if (EFI_ERROR(Status
)) {
106 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
107 return (SHELL_DEVICE_ERROR
);
110 DateStringCopy
= NULL
;
111 DateStringCopy
= StrnCatGrow(&DateStringCopy
, NULL
, DateString
, 0);
112 if (DateStringCopy
== NULL
) {
113 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;
130 Walker1
= Walker
!=NULL
?StrStr(Walker
, L
"/"):NULL
;
131 if (Walker1
!= NULL
&& *Walker1
== L
'/') {
132 *Walker1
= CHAR_NULL
;
134 if (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
) {
135 TheTime
.Day
= (UINT8
)ShellStrToUintn (Walker
);
136 if (Walker1
!= NULL
) {
137 Walker
= Walker1
+ 1;
139 Walker1
= Walker
!=NULL
?StrStr(Walker
, L
"/"):NULL
;
140 if (Walker1
!= NULL
&& *Walker1
== L
'/') {
141 *Walker1
= CHAR_NULL
;
143 if (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
) {
144 TheTime
.Year
= (UINT16
)ShellStrToUintn (Walker
);
148 if (TheTime
.Year
< 100) {
149 if (TheTime
.Year
>= 98) {
150 TheTime
.Year
= (UINT16
)(1900 + TheTime
.Year
);
152 TheTime
.Year
= (UINT16
)(2000 + TheTime
.Year
);
156 Status
= gRT
->SetTime(&TheTime
);
158 if (!EFI_ERROR(Status
)){
159 return (SHELL_SUCCESS
);
161 return (SHELL_INVALID_PARAMETER
);
165 Function for 'date' command.
167 @param[in] ImageHandle Handle to the Image (NULL if Internal).
168 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
172 ShellCommandRunDate (
173 IN EFI_HANDLE ImageHandle
,
174 IN EFI_SYSTEM_TABLE
*SystemTable
180 CHAR16
*ProblemParam
;
181 SHELL_STATUS ShellStatus
;
182 CONST CHAR16
*Param1
;
184 ShellStatus
= SHELL_SUCCESS
;
188 // initialize the shell lib (we must be in non-auto-init...)
190 Status
= ShellInitialize();
191 ASSERT_EFI_ERROR(Status
);
194 // parse the command line
196 Status
= ShellCommandLineParse (SfoParamList
, &Package
, &ProblemParam
, TRUE
);
197 if (EFI_ERROR(Status
)) {
198 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
199 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
200 FreePool(ProblemParam
);
201 ShellStatus
= SHELL_INVALID_PARAMETER
;
209 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
211 } else if (ShellCommandLineGetRawValue(Package
, 2) != NULL
) {
212 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
213 ShellStatus
= SHELL_INVALID_PARAMETER
;
216 // If there are 0 value parameters, then print the current date
217 // else If there are any value paramerers, then print error
219 if (ShellCommandLineGetRawValue(Package
, 1) == NULL
) {
221 // get the current date
223 Status
= gRT
->GetTime(&TheTime
, NULL
);
224 ASSERT_EFI_ERROR(Status
);
227 // ShellPrintEx the date in SFO or regular format
229 if (ShellCommandLineGetFlag(Package
, L
"-sfo")) {
230 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DATE_SFO_FORMAT
), gShellLevel2HiiHandle
, TheTime
.Month
, TheTime
.Day
, TheTime
.Year
);
232 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DATE_FORMAT
), gShellLevel2HiiHandle
, TheTime
.Month
, TheTime
.Day
, TheTime
.Year
);
235 if (PcdGet8(PcdShellSupportLevel
) == 2) {
236 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
237 ShellStatus
= SHELL_INVALID_PARAMETER
;
240 // perform level 3 operation here.
242 Param1
= ShellCommandLineGetRawValue(Package
, 1);
243 if (Param1
== NULL
) {
244 ShellStatus
= SHELL_INVALID_PARAMETER
;
246 ShellStatus
= CheckAndSetDate(Param1
);
248 if (ShellStatus
!= SHELL_SUCCESS
) {
249 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, Param1
);
250 ShellStatus
= SHELL_INVALID_PARAMETER
;
257 // free the command line package
259 ShellCommandLineFreeVarList (Package
);
264 return (ShellStatus
);
268 // Note "-tz" is invalid for this (non-interactive) version of 'time'.
270 STATIC CONST SHELL_PARAM_ITEM TimeParamList2
[] = {
275 STATIC CONST SHELL_PARAM_ITEM TimeParamList3
[] = {
282 Verify that the TimeString is valid and if so set that as the current
285 @param[in] TimeString The pointer to a string representation of the time.
286 @param[in] Tz The value to set for TimeZone.
287 @param[in] Daylight The value to set for Daylight.
289 @retval SHELL_INVALID_PARAMETER TimeString was NULL.
290 @retval SHELL_INVALID_PARAMETER TimeString was mis-formatted.
291 @retval SHELL_SUCCESS The operation was successful.
296 IN CONST CHAR16
*TimeString
,
298 IN CONST UINT8 Daylight
303 CHAR16
*TimeStringCopy
;
307 if (TimeString
!= NULL
&& !InternalIsTimeLikeString(TimeString
, L
':', 1, 2, FALSE
)) {
308 return (SHELL_INVALID_PARAMETER
);
310 if (Daylight
!= 0xFF &&((Daylight
& (EFI_TIME_IN_DAYLIGHT
|EFI_TIME_ADJUST_DAYLIGHT
)) != Daylight
)) {
311 return (SHELL_INVALID_PARAMETER
);
314 Status
= gRT
->GetTime(&TheTime
, NULL
);
315 ASSERT_EFI_ERROR(Status
);
317 if (TimeString
!= NULL
) {
318 TimeStringCopy
= NULL
;
319 TimeStringCopy
= StrnCatGrow(&TimeStringCopy
, NULL
, TimeString
, 0);
320 Walker1
= TimeStringCopy
;
322 TheTime
.Minute
= 0xFF;
324 Walker2
= Walker1
!=NULL
?StrStr(Walker1
, L
":"):NULL
;
325 if (Walker2
!= NULL
&& *Walker2
== L
':') {
326 *Walker2
= CHAR_NULL
;
328 TheTime
.Hour
= (UINT8
)ShellStrToUintn (Walker1
);
329 if (Walker2
!= NULL
) {
330 Walker1
= Walker2
+ 1;
332 Walker2
= Walker1
!=NULL
?StrStr(Walker1
, L
":"):NULL
;
333 if (Walker2
!= NULL
&& *Walker2
== L
':') {
334 *Walker2
= CHAR_NULL
;
336 if (Walker1
!= NULL
&& Walker1
[0] != CHAR_NULL
) {
337 TheTime
.Minute
= (UINT8
)ShellStrToUintn (Walker1
);
338 if (Walker2
!= NULL
) {
339 Walker1
= Walker2
+ 1;
341 if (Walker1
!= NULL
&& Walker1
[0] != CHAR_NULL
) {
342 TheTime
.Second
= (UINT8
)ShellStrToUintn (Walker1
);
345 SHELL_FREE_NON_NULL(TimeStringCopy
);
349 if ((Tz
>= -1440 && Tz
<= 1440)||(Tz
== 0x7FF)) {
350 TheTime
.TimeZone
= Tz
;
353 if (Daylight
!= 0xFF) {
354 TheTime
.Daylight
= Daylight
;
357 Status
= gRT
->SetTime(&TheTime
);
359 if (!EFI_ERROR(Status
)){
360 return (SHELL_SUCCESS
);
363 return (SHELL_INVALID_PARAMETER
);
367 Function for 'time' command.
369 @param[in] ImageHandle Handle to the Image (NULL if Internal).
370 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
374 ShellCommandRunTime (
375 IN EFI_HANDLE ImageHandle
,
376 IN EFI_SYSTEM_TABLE
*SystemTable
383 CHAR16
*ProblemParam
;
384 SHELL_STATUS ShellStatus
;
387 CONST CHAR16
*TempLocation
;
390 ShellStatus
= SHELL_SUCCESS
;
394 // Initialize variables
399 // initialize the shell lib (we must be in non-auto-init...)
401 Status
= ShellInitialize();
402 ASSERT_EFI_ERROR(Status
);
405 // parse the command line
407 if (PcdGet8(PcdShellSupportLevel
) == 2) {
408 Status
= ShellCommandLineParseEx (TimeParamList2
, &Package
, &ProblemParam
, TRUE
, TRUE
);
410 ASSERT(PcdGet8(PcdShellSupportLevel
) == 3);
411 Status
= ShellCommandLineParseEx (TimeParamList3
, &Package
, &ProblemParam
, TRUE
, TRUE
);
413 if (EFI_ERROR(Status
)) {
414 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
415 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
416 FreePool(ProblemParam
);
417 ShellStatus
= SHELL_INVALID_PARAMETER
;
425 Status
= gRT
->GetTime(&TheTime
, NULL
);
426 ASSERT_EFI_ERROR(Status
);
427 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
429 } else if (ShellCommandLineGetRawValue(Package
, 2) != NULL
) {
430 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
431 ShellStatus
= SHELL_INVALID_PARAMETER
;
434 // If there are no parameters, then print the current time
436 if (ShellCommandLineGetRawValue(Package
, 1) == NULL
437 && !ShellCommandLineGetFlag(Package
, L
"-d")
438 && !ShellCommandLineGetFlag(Package
, L
"-tz")) {
440 // ShellPrintEx the current time
442 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
445 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
452 STRING_TOKEN (STR_TIME_FORMAT
),
453 gShellLevel2HiiHandle
,
457 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?L
" ":(TheTime
.TimeZone
> 0?L
"-":L
"+"),
458 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(ABS(TheTime
.TimeZone
)) / 60,
461 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_CRLF
), gShellLevel2HiiHandle
);
462 } else if (ShellCommandLineGetFlag(Package
, L
"-d") && ShellCommandLineGetValue(Package
, L
"-d") == NULL
) {
463 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
466 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
473 STRING_TOKEN (STR_TIME_FORMAT
),
474 gShellLevel2HiiHandle
,
478 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?L
" ":(TheTime
.TimeZone
> 0?L
"-":L
"+"),
479 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(ABS(TheTime
.TimeZone
)) / 60,
482 switch (TheTime
.Daylight
) {
484 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST0
), gShellLevel2HiiHandle
);
486 case EFI_TIME_ADJUST_DAYLIGHT
:
487 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST1
), gShellLevel2HiiHandle
);
489 case EFI_TIME_IN_DAYLIGHT
:
490 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST2
), gShellLevel2HiiHandle
);
492 case EFI_TIME_IN_DAYLIGHT
|EFI_TIME_ADJUST_DAYLIGHT
:
493 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST3
), gShellLevel2HiiHandle
);
496 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_ERROR
), gShellLevel2HiiHandle
, L
"gRT->GetTime", L
"TheTime.Daylight", TheTime
.Daylight
);
499 if (PcdGet8(PcdShellSupportLevel
) == 2) {
500 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
501 ShellStatus
= SHELL_INVALID_PARAMETER
;
504 // perform level 3 operation here.
506 if ((TempLocation
= ShellCommandLineGetValue(Package
, L
"-tz")) != NULL
) {
507 if (TempLocation
[0] == L
'-') {
508 Tz
= (INT16
)(0 - ShellStrToUintn(++TempLocation
));
510 Tz
= (INT16
)ShellStrToUintn(TempLocation
);
512 if (!(Tz
>= -1440 && Tz
<= 1440) && Tz
!= EFI_UNSPECIFIED_TIMEZONE
) {
513 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellLevel2HiiHandle
, L
"-tz");
514 ShellStatus
= SHELL_INVALID_PARAMETER
;
518 // intentionally out of bounds value will prevent changing it...
522 TempLocation
= ShellCommandLineGetValue(Package
, L
"-d");
523 if (TempLocation
!= NULL
) {
524 Daylight
= (UINT8
)ShellStrToUintn(TempLocation
);
525 if (Daylight
!= 0 && Daylight
!= 1 && Daylight
!= 3) {
526 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellLevel2HiiHandle
, L
"-d");
527 ShellStatus
= SHELL_INVALID_PARAMETER
;
531 // invalid = will not use
535 if (ShellStatus
== SHELL_SUCCESS
) {
536 ShellStatus
= CheckAndSetTime(ShellCommandLineGetRawValue(Package
, 1), Tz
, Daylight
);
537 if (ShellStatus
!= SHELL_SUCCESS
) {
538 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ShellCommandLineGetRawValue(Package
, 1));
539 ShellStatus
= SHELL_INVALID_PARAMETER
;
548 // free the command line package
550 ShellCommandLineFreeVarList (Package
);
555 return (ShellStatus
);
560 EFI_STRING_ID StringId
;
563 STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList2
[] = {
568 STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList3
[] = {
575 STATIC CONST TIME_ZONE_ITEM TimeZoneList
[] = {
576 {720, STRING_TOKEN (STR_TIMEZONE_M12
)},
577 {660, STRING_TOKEN (STR_TIMEZONE_M11
)},
578 {600, STRING_TOKEN (STR_TIMEZONE_M10
)},
579 {540, STRING_TOKEN (STR_TIMEZONE_M9
)},
580 {480, STRING_TOKEN (STR_TIMEZONE_M8
)},
581 {420, STRING_TOKEN (STR_TIMEZONE_M7
)},
582 {360, STRING_TOKEN (STR_TIMEZONE_M6
)},
583 {300, STRING_TOKEN (STR_TIMEZONE_M5
)},
584 {270, STRING_TOKEN (STR_TIMEZONE_M430
)},
585 {240, STRING_TOKEN (STR_TIMEZONE_M4
)},
586 {210, STRING_TOKEN (STR_TIMEZONE_M330
)},
587 {180, STRING_TOKEN (STR_TIMEZONE_M3
)},
588 {120, STRING_TOKEN (STR_TIMEZONE_M2
)},
589 {60 , STRING_TOKEN (STR_TIMEZONE_M1
)},
590 {0 , STRING_TOKEN (STR_TIMEZONE_0
)},
591 {-60 , STRING_TOKEN (STR_TIMEZONE_P1
)},
592 {-120 , STRING_TOKEN (STR_TIMEZONE_P2
)},
593 {-180 , STRING_TOKEN (STR_TIMEZONE_P3
)},
594 {-210 , STRING_TOKEN (STR_TIMEZONE_P330
)},
595 {-240 , STRING_TOKEN (STR_TIMEZONE_P4
)},
596 {-270 , STRING_TOKEN (STR_TIMEZONE_P430
)},
597 {-300 , STRING_TOKEN (STR_TIMEZONE_P5
)},
598 {-330 , STRING_TOKEN (STR_TIMEZONE_P530
)},
599 {-345 , STRING_TOKEN (STR_TIMEZONE_P545
)},
600 {-360 , STRING_TOKEN (STR_TIMEZONE_P6
)},
601 {-390 , STRING_TOKEN (STR_TIMEZONE_P630
)},
602 {-420 , STRING_TOKEN (STR_TIMEZONE_P7
)},
603 {-480 , STRING_TOKEN (STR_TIMEZONE_P8
)},
604 {-540 , STRING_TOKEN (STR_TIMEZONE_P9
)},
605 {-570 , STRING_TOKEN (STR_TIMEZONE_P930
)},
606 {-600 , STRING_TOKEN (STR_TIMEZONE_P10
)},
607 {-660 , STRING_TOKEN (STR_TIMEZONE_P11
)},
608 {-720 , STRING_TOKEN (STR_TIMEZONE_P12
)},
609 {-780 , STRING_TOKEN (STR_TIMEZONE_P13
)},
610 {-840 , STRING_TOKEN (STR_TIMEZONE_P14
)}
614 Verify that the TimeZoneString is valid and if so set that as the current
617 @param[in] TimeZoneString The pointer to a string representation of the timezone.
619 @retval SHELL_INVALID_PARAMETER TimeZoneString was NULL.
620 @retval SHELL_INVALID_PARAMETER TimeZoneString was mis-formatted.
621 @retval SHELL_SUCCESS The operation was successful.
625 CheckAndSetTimeZone (
626 IN CONST CHAR16
*TimeZoneString
631 CHAR16
*TimeZoneCopy
;
636 if (TimeZoneString
== NULL
) {
637 return (SHELL_INVALID_PARAMETER
);
640 if (TimeZoneString
!= NULL
&& !InternalIsTimeLikeString(TimeZoneString
, L
':', 1, 1, TRUE
)) {
641 return (SHELL_INVALID_PARAMETER
);
644 Status
= gRT
->GetTime(&TheTime
, NULL
);
645 ASSERT_EFI_ERROR(Status
);
648 TimeZoneCopy
= StrnCatGrow(&TimeZoneCopy
, NULL
, TimeZoneString
, 0);
649 Walker
= TimeZoneCopy
;
650 Walker2
= StrStr(Walker
, L
":");
651 if (Walker2
!= NULL
&& *Walker2
== L
':') {
652 *Walker2
= CHAR_NULL
;
654 if (*Walker
== L
'-') {
655 TheTime
.TimeZone
= (INT16
)((ShellStrToUintn (++Walker
)) * 60);
657 TheTime
.TimeZone
= (INT16
)((ShellStrToUintn (Walker
)) * -60);
659 if (Walker2
!= NULL
) {
660 Walker
= Walker2
+ 1;
662 if (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
) {
663 if (TheTime
.TimeZone
< 0) {
664 TheTime
.TimeZone
= (INT16
)(TheTime
.TimeZone
- (UINT8
)ShellStrToUintn (Walker
));
666 TheTime
.TimeZone
= (INT16
)(TheTime
.TimeZone
+ (UINT8
)ShellStrToUintn (Walker
));
670 Status
= EFI_INVALID_PARAMETER
;
673 ; LoopVar
< sizeof(TimeZoneList
) / sizeof(TimeZoneList
[0])
676 if (TheTime
.TimeZone
== TimeZoneList
[LoopVar
].TimeZone
) {
677 Status
= gRT
->SetTime(&TheTime
);
682 FreePool(TimeZoneCopy
);
684 if (!EFI_ERROR(Status
)){
685 return (SHELL_SUCCESS
);
687 return (SHELL_INVALID_PARAMETER
);
692 Function for 'timezone' command.
694 @param[in] ImageHandle Handle to the Image (NULL if Internal).
695 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
699 ShellCommandRunTimeZone (
700 IN EFI_HANDLE ImageHandle
,
701 IN EFI_SYSTEM_TABLE
*SystemTable
709 CHAR16
*ProblemParam
;
710 SHELL_STATUS ShellStatus
;
716 ShellStatus
= SHELL_SUCCESS
;
720 // initialize the shell lib (we must be in non-auto-init...)
722 Status
= ShellInitialize();
723 ASSERT_EFI_ERROR(Status
);
726 // parse the command line
728 if (PcdGet8(PcdShellSupportLevel
) == 2) {
729 Status
= ShellCommandLineParse (TimeZoneParamList2
, &Package
, &ProblemParam
, FALSE
);
731 ASSERT(PcdGet8(PcdShellSupportLevel
) == 3);
732 Status
= ShellCommandLineParseEx (TimeZoneParamList3
, &Package
, &ProblemParam
, FALSE
, TRUE
);
734 if (EFI_ERROR(Status
)) {
735 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
736 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
737 FreePool(ProblemParam
);
738 ShellStatus
= SHELL_INVALID_PARAMETER
;
746 if (ShellCommandLineGetCount(Package
) > 1) {
747 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
748 ShellStatus
= SHELL_INVALID_PARAMETER
;
749 } else if (ShellCommandLineGetFlag(Package
, L
"-?")) {
751 } else if (ShellCommandLineGetFlag(Package
, L
"-s")) {
752 if ((ShellCommandLineGetFlag(Package
, L
"-l")) || (ShellCommandLineGetFlag(Package
, L
"-f"))) {
753 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"-l or -f");
754 ShellStatus
= SHELL_INVALID_PARAMETER
;
756 ASSERT(PcdGet8(PcdShellSupportLevel
) == 3);
757 if (ShellCommandLineGetValue(Package
, L
"-s") == NULL
) {
758 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellLevel2HiiHandle
, L
"-s");
759 ShellStatus
= SHELL_INVALID_PARAMETER
;
764 ShellStatus
= CheckAndSetTimeZone(ShellCommandLineGetValue(Package
, L
"-s"));
765 if (ShellStatus
!= SHELL_SUCCESS
) {
766 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ShellCommandLineGetValue(Package
, L
"-s"));
767 ShellStatus
= SHELL_INVALID_PARAMETER
;
771 } else if (ShellCommandLineGetFlag(Package
, L
"-l")) {
773 // Print a list of all time zones
776 ; LoopVar
< sizeof(TimeZoneList
) / sizeof(TimeZoneList
[0])
779 ShellPrintHiiEx (-1, -1, NULL
, TimeZoneList
[LoopVar
].StringId
, gShellLevel2HiiHandle
);
783 // Get Current Time Zone Info
785 Status
= gRT
->GetTime(&TheTime
, NULL
);
786 ASSERT_EFI_ERROR(Status
);
788 if (TheTime
.TimeZone
!= EFI_UNSPECIFIED_TIMEZONE
) {
791 ; LoopVar
< sizeof(TimeZoneList
) / sizeof(TimeZoneList
[0])
794 if (TheTime
.TimeZone
== TimeZoneList
[LoopVar
].TimeZone
) {
795 if (ShellCommandLineGetFlag(Package
, L
"-f")) {
797 // Print all info about current time zone
799 ShellPrintHiiEx (-1, -1, NULL
, TimeZoneList
[LoopVar
].StringId
, gShellLevel2HiiHandle
);
802 // Print basic info only
804 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
807 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
814 STRING_TOKEN(STR_TIMEZONE_SIMPLE
),
815 gShellLevel2HiiHandle
,
816 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(TheTime
.TimeZone
> 0?L
"-":L
"+"),
817 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(ABS(TheTime
.TimeZone
)) / 60,
826 // Print basic info only
828 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
831 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
837 STRING_TOKEN(STR_TIMEZONE_SIMPLE
),
838 gShellLevel2HiiHandle
,
839 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(TheTime
.TimeZone
> 0?L
"-":L
"+"),
840 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(ABS(TheTime
.TimeZone
)) / 60,
842 if (ShellCommandLineGetFlag(Package
, L
"-f")) {
843 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN(STR_TIMEZONE_NI
), gShellLevel2HiiHandle
);
848 // TimeZone was EFI_UNSPECIFIED_TIMEZONE (unknown) from GetTime()
855 // free the command line package
857 ShellCommandLineFreeVarList (Package
);
859 return (ShellStatus
);