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 if (EFI_ERROR(Status
)) {
225 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
226 return (SHELL_DEVICE_ERROR
);
230 // ShellPrintEx the date in SFO or regular format
232 if (ShellCommandLineGetFlag(Package
, L
"-sfo")) {
233 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DATE_SFO_FORMAT
), gShellLevel2HiiHandle
, TheTime
.Month
, TheTime
.Day
, TheTime
.Year
);
235 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DATE_FORMAT
), gShellLevel2HiiHandle
, TheTime
.Month
, TheTime
.Day
, TheTime
.Year
);
238 if (PcdGet8(PcdShellSupportLevel
) == 2) {
239 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
240 ShellStatus
= SHELL_INVALID_PARAMETER
;
243 // perform level 3 operation here.
245 Param1
= ShellCommandLineGetRawValue(Package
, 1);
246 if (Param1
== NULL
) {
247 ShellStatus
= SHELL_INVALID_PARAMETER
;
249 ShellStatus
= CheckAndSetDate(Param1
);
251 if (ShellStatus
!= SHELL_SUCCESS
) {
252 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, Param1
);
253 ShellStatus
= SHELL_INVALID_PARAMETER
;
260 // free the command line package
262 ShellCommandLineFreeVarList (Package
);
267 return (ShellStatus
);
271 // Note "-tz" is invalid for this (non-interactive) version of 'time'.
273 STATIC CONST SHELL_PARAM_ITEM TimeParamList2
[] = {
278 STATIC CONST SHELL_PARAM_ITEM TimeParamList3
[] = {
285 Verify that the TimeString is valid and if so set that as the current
288 @param[in] TimeString The pointer to a string representation of the time.
289 @param[in] Tz The value to set for TimeZone.
290 @param[in] Daylight The value to set for Daylight.
292 @retval SHELL_INVALID_PARAMETER TimeString was NULL.
293 @retval SHELL_INVALID_PARAMETER TimeString was mis-formatted.
294 @retval SHELL_SUCCESS The operation was successful.
299 IN CONST CHAR16
*TimeString
,
301 IN CONST UINT8 Daylight
306 CHAR16
*TimeStringCopy
;
310 if (TimeString
!= NULL
&& !InternalIsTimeLikeString(TimeString
, L
':', 1, 2, FALSE
)) {
311 return (SHELL_INVALID_PARAMETER
);
313 if (Daylight
!= 0xFF &&((Daylight
& (EFI_TIME_IN_DAYLIGHT
|EFI_TIME_ADJUST_DAYLIGHT
)) != Daylight
)) {
314 return (SHELL_INVALID_PARAMETER
);
317 Status
= gRT
->GetTime(&TheTime
, NULL
);
318 if (EFI_ERROR(Status
)) {
319 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
320 return (SHELL_DEVICE_ERROR
);
323 if (TimeString
!= NULL
) {
324 TimeStringCopy
= NULL
;
325 TimeStringCopy
= StrnCatGrow(&TimeStringCopy
, NULL
, TimeString
, 0);
326 Walker1
= TimeStringCopy
;
328 TheTime
.Minute
= 0xFF;
330 Walker2
= Walker1
!=NULL
?StrStr(Walker1
, L
":"):NULL
;
331 if (Walker2
!= NULL
&& *Walker2
== L
':') {
332 *Walker2
= CHAR_NULL
;
334 TheTime
.Hour
= (UINT8
)ShellStrToUintn (Walker1
);
335 if (Walker2
!= NULL
) {
336 Walker1
= Walker2
+ 1;
338 Walker2
= Walker1
!=NULL
?StrStr(Walker1
, L
":"):NULL
;
339 if (Walker2
!= NULL
&& *Walker2
== L
':') {
340 *Walker2
= CHAR_NULL
;
342 if (Walker1
!= NULL
&& Walker1
[0] != CHAR_NULL
) {
343 TheTime
.Minute
= (UINT8
)ShellStrToUintn (Walker1
);
344 if (Walker2
!= NULL
) {
345 Walker1
= Walker2
+ 1;
347 if (Walker1
!= NULL
&& Walker1
[0] != CHAR_NULL
) {
348 TheTime
.Second
= (UINT8
)ShellStrToUintn (Walker1
);
351 SHELL_FREE_NON_NULL(TimeStringCopy
);
355 if ((Tz
>= -1440 && Tz
<= 1440)||(Tz
== 0x7FF)) {
356 TheTime
.TimeZone
= Tz
;
359 if (Daylight
!= 0xFF) {
360 TheTime
.Daylight
= Daylight
;
363 Status
= gRT
->SetTime(&TheTime
);
365 if (!EFI_ERROR(Status
)){
366 return (SHELL_SUCCESS
);
369 return (SHELL_INVALID_PARAMETER
);
373 Function for 'time' command.
375 @param[in] ImageHandle Handle to the Image (NULL if Internal).
376 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
380 ShellCommandRunTime (
381 IN EFI_HANDLE ImageHandle
,
382 IN EFI_SYSTEM_TABLE
*SystemTable
388 CHAR16
*ProblemParam
;
389 SHELL_STATUS ShellStatus
;
392 CONST CHAR16
*TempLocation
;
396 // Initialize variables
398 ShellStatus
= SHELL_SUCCESS
;
402 // initialize the shell lib (we must be in non-auto-init...)
404 Status
= ShellInitialize();
405 ASSERT_EFI_ERROR(Status
);
408 // parse the command line
410 if (PcdGet8(PcdShellSupportLevel
) == 2) {
411 Status
= ShellCommandLineParseEx (TimeParamList2
, &Package
, &ProblemParam
, TRUE
, TRUE
);
413 ASSERT(PcdGet8(PcdShellSupportLevel
) == 3);
414 Status
= ShellCommandLineParseEx (TimeParamList3
, &Package
, &ProblemParam
, TRUE
, TRUE
);
416 if (EFI_ERROR(Status
)) {
417 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
418 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
419 FreePool(ProblemParam
);
420 ShellStatus
= SHELL_INVALID_PARAMETER
;
428 Status
= gRT
->GetTime(&TheTime
, NULL
);
429 if (EFI_ERROR(Status
)) {
430 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
431 return (SHELL_DEVICE_ERROR
);
434 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
436 } else if (ShellCommandLineGetRawValue(Package
, 2) != NULL
) {
437 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
438 ShellStatus
= SHELL_INVALID_PARAMETER
;
441 // If there are no parameters, then print the current time
443 if (ShellCommandLineGetRawValue(Package
, 1) == NULL
444 && !ShellCommandLineGetFlag(Package
, L
"-d")
445 && !ShellCommandLineGetFlag(Package
, L
"-tz")) {
447 // ShellPrintEx the current time
449 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
452 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
459 STRING_TOKEN (STR_TIME_FORMAT
),
460 gShellLevel2HiiHandle
,
464 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?L
" ":(TheTime
.TimeZone
> 0?L
"-":L
"+"),
465 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(ABS(TheTime
.TimeZone
)) / 60,
468 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_CRLF
), gShellLevel2HiiHandle
);
469 } else if (ShellCommandLineGetFlag(Package
, L
"-d") && ShellCommandLineGetValue(Package
, L
"-d") == NULL
) {
470 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
473 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
480 STRING_TOKEN (STR_TIME_FORMAT
),
481 gShellLevel2HiiHandle
,
485 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?L
" ":(TheTime
.TimeZone
> 0?L
"-":L
"+"),
486 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(ABS(TheTime
.TimeZone
)) / 60,
489 switch (TheTime
.Daylight
) {
491 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST0
), gShellLevel2HiiHandle
);
493 case EFI_TIME_ADJUST_DAYLIGHT
:
494 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST1
), gShellLevel2HiiHandle
);
496 case EFI_TIME_IN_DAYLIGHT
:
497 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST2
), gShellLevel2HiiHandle
);
499 case EFI_TIME_IN_DAYLIGHT
|EFI_TIME_ADJUST_DAYLIGHT
:
500 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST3
), gShellLevel2HiiHandle
);
503 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_ERROR
), gShellLevel2HiiHandle
, L
"gRT->GetTime", L
"TheTime.Daylight", TheTime
.Daylight
);
506 if (PcdGet8(PcdShellSupportLevel
) == 2) {
507 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
508 ShellStatus
= SHELL_INVALID_PARAMETER
;
511 // perform level 3 operation here.
513 if ((TempLocation
= ShellCommandLineGetValue(Package
, L
"-tz")) != NULL
) {
514 if (TempLocation
[0] == L
'-') {
515 Tz
= (INT16
)(0 - ShellStrToUintn(++TempLocation
));
517 Tz
= (INT16
)ShellStrToUintn(TempLocation
);
519 if (!(Tz
>= -1440 && Tz
<= 1440) && Tz
!= EFI_UNSPECIFIED_TIMEZONE
) {
520 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellLevel2HiiHandle
, L
"-tz");
521 ShellStatus
= SHELL_INVALID_PARAMETER
;
525 // intentionally out of bounds value will prevent changing it...
529 TempLocation
= ShellCommandLineGetValue(Package
, L
"-d");
530 if (TempLocation
!= NULL
) {
531 Daylight
= (UINT8
)ShellStrToUintn(TempLocation
);
532 if (Daylight
!= 0 && Daylight
!= 1 && Daylight
!= 3) {
533 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellLevel2HiiHandle
, L
"-d");
534 ShellStatus
= SHELL_INVALID_PARAMETER
;
538 // invalid = will not use
542 if (ShellStatus
== SHELL_SUCCESS
) {
543 ShellStatus
= CheckAndSetTime(ShellCommandLineGetRawValue(Package
, 1), Tz
, Daylight
);
544 if (ShellStatus
!= SHELL_SUCCESS
) {
545 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ShellCommandLineGetRawValue(Package
, 1));
546 ShellStatus
= SHELL_INVALID_PARAMETER
;
555 // free the command line package
557 ShellCommandLineFreeVarList (Package
);
562 return (ShellStatus
);
567 EFI_STRING_ID StringId
;
570 STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList2
[] = {
575 STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList3
[] = {
582 STATIC CONST TIME_ZONE_ITEM TimeZoneList
[] = {
583 {720, STRING_TOKEN (STR_TIMEZONE_M12
)},
584 {660, STRING_TOKEN (STR_TIMEZONE_M11
)},
585 {600, STRING_TOKEN (STR_TIMEZONE_M10
)},
586 {540, STRING_TOKEN (STR_TIMEZONE_M9
)},
587 {480, STRING_TOKEN (STR_TIMEZONE_M8
)},
588 {420, STRING_TOKEN (STR_TIMEZONE_M7
)},
589 {360, STRING_TOKEN (STR_TIMEZONE_M6
)},
590 {300, STRING_TOKEN (STR_TIMEZONE_M5
)},
591 {270, STRING_TOKEN (STR_TIMEZONE_M430
)},
592 {240, STRING_TOKEN (STR_TIMEZONE_M4
)},
593 {210, STRING_TOKEN (STR_TIMEZONE_M330
)},
594 {180, STRING_TOKEN (STR_TIMEZONE_M3
)},
595 {120, STRING_TOKEN (STR_TIMEZONE_M2
)},
596 {60 , STRING_TOKEN (STR_TIMEZONE_M1
)},
597 {0 , STRING_TOKEN (STR_TIMEZONE_0
)},
598 {-60 , STRING_TOKEN (STR_TIMEZONE_P1
)},
599 {-120 , STRING_TOKEN (STR_TIMEZONE_P2
)},
600 {-180 , STRING_TOKEN (STR_TIMEZONE_P3
)},
601 {-210 , STRING_TOKEN (STR_TIMEZONE_P330
)},
602 {-240 , STRING_TOKEN (STR_TIMEZONE_P4
)},
603 {-270 , STRING_TOKEN (STR_TIMEZONE_P430
)},
604 {-300 , STRING_TOKEN (STR_TIMEZONE_P5
)},
605 {-330 , STRING_TOKEN (STR_TIMEZONE_P530
)},
606 {-345 , STRING_TOKEN (STR_TIMEZONE_P545
)},
607 {-360 , STRING_TOKEN (STR_TIMEZONE_P6
)},
608 {-390 , STRING_TOKEN (STR_TIMEZONE_P630
)},
609 {-420 , STRING_TOKEN (STR_TIMEZONE_P7
)},
610 {-480 , STRING_TOKEN (STR_TIMEZONE_P8
)},
611 {-540 , STRING_TOKEN (STR_TIMEZONE_P9
)},
612 {-570 , STRING_TOKEN (STR_TIMEZONE_P930
)},
613 {-600 , STRING_TOKEN (STR_TIMEZONE_P10
)},
614 {-660 , STRING_TOKEN (STR_TIMEZONE_P11
)},
615 {-720 , STRING_TOKEN (STR_TIMEZONE_P12
)},
616 {-780 , STRING_TOKEN (STR_TIMEZONE_P13
)},
617 {-840 , STRING_TOKEN (STR_TIMEZONE_P14
)}
621 Verify that the TimeZoneString is valid and if so set that as the current
624 @param[in] TimeZoneString The pointer to a string representation of the timezone.
626 @retval SHELL_INVALID_PARAMETER TimeZoneString was NULL.
627 @retval SHELL_INVALID_PARAMETER TimeZoneString was mis-formatted.
628 @retval SHELL_SUCCESS The operation was successful.
632 CheckAndSetTimeZone (
633 IN CONST CHAR16
*TimeZoneString
638 CHAR16
*TimeZoneCopy
;
643 if (TimeZoneString
== NULL
) {
644 return (SHELL_INVALID_PARAMETER
);
647 if (TimeZoneString
!= NULL
&& !InternalIsTimeLikeString(TimeZoneString
, L
':', 1, 1, TRUE
)) {
648 return (SHELL_INVALID_PARAMETER
);
651 Status
= gRT
->GetTime(&TheTime
, NULL
);
652 if (EFI_ERROR(Status
)) {
653 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
654 return (SHELL_DEVICE_ERROR
);
658 TimeZoneCopy
= StrnCatGrow(&TimeZoneCopy
, NULL
, TimeZoneString
, 0);
659 if (TimeZoneCopy
== NULL
) {
660 return (SHELL_OUT_OF_RESOURCES
);
662 Walker
= TimeZoneCopy
;
663 Walker2
= StrStr(Walker
, L
":");
664 if (Walker2
!= NULL
&& *Walker2
== L
':') {
665 *Walker2
= CHAR_NULL
;
667 if (*Walker
== L
'-') {
668 TheTime
.TimeZone
= (INT16
)((ShellStrToUintn (++Walker
)) * 60);
670 TheTime
.TimeZone
= (INT16
)((INT16
)(ShellStrToUintn (Walker
)) * -60);
672 if (Walker2
!= NULL
) {
673 Walker
= Walker2
+ 1;
675 if (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
) {
676 if (TheTime
.TimeZone
< 0) {
677 TheTime
.TimeZone
= (INT16
)(TheTime
.TimeZone
- (UINT8
)ShellStrToUintn (Walker
));
679 TheTime
.TimeZone
= (INT16
)(TheTime
.TimeZone
+ (UINT8
)ShellStrToUintn (Walker
));
683 Status
= EFI_INVALID_PARAMETER
;
686 ; LoopVar
< sizeof(TimeZoneList
) / sizeof(TimeZoneList
[0])
689 if (TheTime
.TimeZone
== TimeZoneList
[LoopVar
].TimeZone
) {
690 Status
= gRT
->SetTime(&TheTime
);
695 FreePool(TimeZoneCopy
);
697 if (!EFI_ERROR(Status
)){
698 return (SHELL_SUCCESS
);
700 return (SHELL_INVALID_PARAMETER
);
705 Function for 'timezone' command.
707 @param[in] ImageHandle Handle to the Image (NULL if Internal).
708 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
712 ShellCommandRunTimeZone (
713 IN EFI_HANDLE ImageHandle
,
714 IN EFI_SYSTEM_TABLE
*SystemTable
722 CHAR16
*ProblemParam
;
723 SHELL_STATUS ShellStatus
;
729 ShellStatus
= SHELL_SUCCESS
;
733 // initialize the shell lib (we must be in non-auto-init...)
735 Status
= ShellInitialize();
736 ASSERT_EFI_ERROR(Status
);
739 // parse the command line
741 if (PcdGet8(PcdShellSupportLevel
) == 2) {
742 Status
= ShellCommandLineParse (TimeZoneParamList2
, &Package
, &ProblemParam
, TRUE
);
744 ASSERT(PcdGet8(PcdShellSupportLevel
) == 3);
745 Status
= ShellCommandLineParseEx (TimeZoneParamList3
, &Package
, &ProblemParam
, TRUE
, TRUE
);
747 if (EFI_ERROR(Status
)) {
748 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
749 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
750 FreePool(ProblemParam
);
751 ShellStatus
= SHELL_INVALID_PARAMETER
;
759 if (ShellCommandLineGetCount(Package
) > 1) {
760 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
761 ShellStatus
= SHELL_INVALID_PARAMETER
;
762 } else if (ShellCommandLineGetFlag(Package
, L
"-?")) {
764 } else if (ShellCommandLineGetFlag(Package
, L
"-s")) {
765 if ((ShellCommandLineGetFlag(Package
, L
"-l")) || (ShellCommandLineGetFlag(Package
, L
"-f"))) {
766 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"-l or -f");
767 ShellStatus
= SHELL_INVALID_PARAMETER
;
769 ASSERT(PcdGet8(PcdShellSupportLevel
) == 3);
770 if (ShellCommandLineGetValue(Package
, L
"-s") == NULL
) {
771 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellLevel2HiiHandle
, L
"-s");
772 ShellStatus
= SHELL_INVALID_PARAMETER
;
777 ShellStatus
= CheckAndSetTimeZone(ShellCommandLineGetValue(Package
, L
"-s"));
778 if (ShellStatus
!= SHELL_SUCCESS
) {
779 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ShellCommandLineGetValue(Package
, L
"-s"));
780 ShellStatus
= SHELL_INVALID_PARAMETER
;
784 } else if (ShellCommandLineGetFlag(Package
, L
"-l")) {
786 // Print a list of all time zones
789 ; LoopVar
< sizeof(TimeZoneList
) / sizeof(TimeZoneList
[0])
792 ShellPrintHiiEx (-1, -1, NULL
, TimeZoneList
[LoopVar
].StringId
, gShellLevel2HiiHandle
);
796 // Get Current Time Zone Info
798 Status
= gRT
->GetTime(&TheTime
, NULL
);
799 if (EFI_ERROR(Status
)) {
800 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
801 return (SHELL_DEVICE_ERROR
);
804 if (TheTime
.TimeZone
!= EFI_UNSPECIFIED_TIMEZONE
) {
807 ; LoopVar
< sizeof(TimeZoneList
) / sizeof(TimeZoneList
[0])
810 if (TheTime
.TimeZone
== TimeZoneList
[LoopVar
].TimeZone
) {
811 if (ShellCommandLineGetFlag(Package
, L
"-f")) {
813 // Print all info about current time zone
815 ShellPrintHiiEx (-1, -1, NULL
, TimeZoneList
[LoopVar
].StringId
, gShellLevel2HiiHandle
);
818 // Print basic info only
820 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
823 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
830 STRING_TOKEN(STR_TIMEZONE_SIMPLE
),
831 gShellLevel2HiiHandle
,
832 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(TheTime
.TimeZone
> 0?L
"-":L
"+"),
833 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(ABS(TheTime
.TimeZone
)) / 60,
842 // Print basic info only
844 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
847 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
853 STRING_TOKEN(STR_TIMEZONE_SIMPLE
),
854 gShellLevel2HiiHandle
,
855 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(TheTime
.TimeZone
> 0?L
"-":L
"+"),
856 TheTime
.TimeZone
==EFI_UNSPECIFIED_TIMEZONE
?0:(ABS(TheTime
.TimeZone
)) / 60,
858 if (ShellCommandLineGetFlag(Package
, L
"-f")) {
859 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN(STR_TIMEZONE_NI
), gShellLevel2HiiHandle
);
864 // TimeZone was EFI_UNSPECIFIED_TIMEZONE (unknown) from GetTime()
871 // free the command line package
873 ShellCommandLineFreeVarList (Package
);
875 return (ShellStatus
);