2 Main file for time, timezone, and date shell level 2 and shell level 3 functions.
4 (C) Copyright 2012-2014, Hewlett-Packard Development Company, L.P.
5 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UefiShellLevel2CommandsLib.h"
19 Determine if String is a valid representation for a time or date.
21 @param[in] String The pointer to the string to test.
22 @param[in] Char The delimeter character.
23 @param[in] Min The minimum value allowed.
24 @param[in] Max The maximum value allowed.
25 @param[in] MinusOk Whether negative numbers are permitted.
27 @retval TRUE String is a valid representation.
28 @retval FALSE String is invalid.
32 InternalIsTimeLikeString (
33 IN CONST CHAR16
*String
,
37 IN CONST BOOLEAN MinusOk
45 // A single minus is ok.
47 if (*String
== L
'-') {
53 // the first char must be numeric.
55 if (!ShellIsDecimalDigitCharacter(*String
)) {
59 // loop through the characters and use the lib function
61 for ( ; String
!= NULL
&& *String
!= CHAR_NULL
; String
++){
62 if (*String
== Char
) {
69 if (!ShellIsDecimalDigitCharacter(*String
)) {
80 Verify that the DateString is valid and if so set that as the current
83 @param[in] DateString The pointer to a string representation of the date.
85 @retval SHELL_INVALID_PARAMETER DateString was NULL.
86 @retval SHELL_INVALID_PARAMETER DateString was mis-formatted.
87 @retval SHELL_SUCCESS The operation was successful.
92 IN CONST CHAR16
*DateString
97 CHAR16
*DateStringCopy
;
101 if (!InternalIsTimeLikeString(DateString
, L
'/', 2, 2, FALSE
)) {
102 return (SHELL_INVALID_PARAMETER
);
105 Status
= gRT
->GetTime(&TheTime
, NULL
);
106 if (EFI_ERROR(Status
)) {
107 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
108 return (SHELL_DEVICE_ERROR
);
111 DateStringCopy
= NULL
;
112 DateStringCopy
= StrnCatGrow(&DateStringCopy
, NULL
, DateString
, 0);
113 if (DateStringCopy
== NULL
) {
114 return (SHELL_OUT_OF_RESOURCES
);
116 Walker
= DateStringCopy
;
118 TheTime
.Month
= 0xFF;
120 TheTime
.Year
= 0xFFFF;
122 Walker1
= StrStr(Walker
, L
"/");
123 if (Walker1
!= NULL
&& *Walker1
== L
'/') {
124 *Walker1
= CHAR_NULL
;
127 TheTime
.Month
= (UINT8
)ShellStrToUintn (Walker
);
128 if (Walker1
!= NULL
) {
129 Walker
= Walker1
+ 1;
131 Walker1
= Walker
!=NULL
?StrStr(Walker
, L
"/"):NULL
;
132 if (Walker1
!= NULL
&& *Walker1
== L
'/') {
133 *Walker1
= CHAR_NULL
;
135 if (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
) {
136 TheTime
.Day
= (UINT8
)ShellStrToUintn (Walker
);
137 if (Walker1
!= NULL
) {
138 Walker
= Walker1
+ 1;
140 Walker1
= Walker
!=NULL
?StrStr(Walker
, L
"/"):NULL
;
141 if (Walker1
!= NULL
&& *Walker1
== L
'/') {
142 *Walker1
= CHAR_NULL
;
144 if (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
) {
145 TheTime
.Year
= (UINT16
)ShellStrToUintn (Walker
);
149 if (TheTime
.Year
< 100) {
150 if (TheTime
.Year
>= 98) {
151 TheTime
.Year
= (UINT16
)(1900 + TheTime
.Year
);
153 TheTime
.Year
= (UINT16
)(2000 + TheTime
.Year
);
157 Status
= gRT
->SetTime(&TheTime
);
159 if (!EFI_ERROR(Status
)){
160 return (SHELL_SUCCESS
);
162 return (SHELL_INVALID_PARAMETER
);
166 Function for 'date' command.
168 @param[in] ImageHandle Handle to the Image (NULL if Internal).
169 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
173 ShellCommandRunDate (
174 IN EFI_HANDLE ImageHandle
,
175 IN EFI_SYSTEM_TABLE
*SystemTable
181 CHAR16
*ProblemParam
;
182 SHELL_STATUS ShellStatus
;
183 CONST CHAR16
*Param1
;
185 ShellStatus
= SHELL_SUCCESS
;
189 // initialize the shell lib (we must be in non-auto-init...)
191 Status
= ShellInitialize();
192 ASSERT_EFI_ERROR(Status
);
195 // parse the command line
197 Status
= ShellCommandLineParse (SfoParamList
, &Package
, &ProblemParam
, TRUE
);
198 if (EFI_ERROR(Status
)) {
199 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
200 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
201 FreePool(ProblemParam
);
202 ShellStatus
= SHELL_INVALID_PARAMETER
;
210 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
212 } else if (ShellCommandLineGetRawValue(Package
, 2) != NULL
) {
213 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
214 ShellStatus
= SHELL_INVALID_PARAMETER
;
217 // If there are 0 value parameters, then print the current date
218 // else If there are any value paramerers, then print error
220 if (ShellCommandLineGetRawValue(Package
, 1) == NULL
) {
222 // get the current date
224 Status
= gRT
->GetTime(&TheTime
, NULL
);
225 if (EFI_ERROR(Status
)) {
226 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
227 return (SHELL_DEVICE_ERROR
);
231 // ShellPrintEx the date in SFO or regular format
233 if (ShellCommandLineGetFlag(Package
, L
"-sfo")) {
235 // Match UEFI Shell spec:
236 // ShellCommand,"date"
237 // Date,"DD","MM","YYYY"
239 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_SFO_HEADER
), gShellLevel2HiiHandle
, L
"date");
240 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DATE_SFO_FORMAT
), gShellLevel2HiiHandle
, TheTime
.Day
, TheTime
.Month
, TheTime
.Year
);
242 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DATE_FORMAT
), gShellLevel2HiiHandle
, TheTime
.Month
, TheTime
.Day
, TheTime
.Year
);
245 if (PcdGet8(PcdShellSupportLevel
) == 2) {
246 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
247 ShellStatus
= SHELL_INVALID_PARAMETER
;
250 // perform level 3 operation here.
252 Param1
= ShellCommandLineGetRawValue(Package
, 1);
253 if (Param1
== NULL
) {
254 ShellStatus
= SHELL_INVALID_PARAMETER
;
256 ShellStatus
= CheckAndSetDate(Param1
);
258 if (ShellStatus
!= SHELL_SUCCESS
) {
259 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, Param1
);
260 ShellStatus
= SHELL_INVALID_PARAMETER
;
267 // free the command line package
269 ShellCommandLineFreeVarList (Package
);
274 return (ShellStatus
);
278 // Note "-tz" is invalid for this (non-interactive) version of 'time'.
280 STATIC CONST SHELL_PARAM_ITEM TimeParamList2
[] = {
285 STATIC CONST SHELL_PARAM_ITEM TimeParamList3
[] = {
292 Verify that the TimeString is valid and if so set that as the current
295 @param[in] TimeString The pointer to a string representation of the time.
296 @param[in] Tz The value to set for TimeZone.
297 @param[in] Daylight The value to set for Daylight.
299 @retval SHELL_INVALID_PARAMETER TimeString was NULL.
300 @retval SHELL_INVALID_PARAMETER TimeString was mis-formatted.
301 @retval SHELL_SUCCESS The operation was successful.
306 IN CONST CHAR16
*TimeString
,
308 IN CONST UINT8 Daylight
313 CHAR16
*TimeStringCopy
;
317 if (TimeString
!= NULL
&& !InternalIsTimeLikeString(TimeString
, L
':', 1, 2, FALSE
)) {
318 return (SHELL_INVALID_PARAMETER
);
320 if (Daylight
!= 0xFF &&((Daylight
& (EFI_TIME_IN_DAYLIGHT
|EFI_TIME_ADJUST_DAYLIGHT
)) != Daylight
)) {
321 return (SHELL_INVALID_PARAMETER
);
324 Status
= gRT
->GetTime(&TheTime
, NULL
);
325 if (EFI_ERROR(Status
)) {
326 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
327 return (SHELL_DEVICE_ERROR
);
330 if (TimeString
!= NULL
) {
331 TimeStringCopy
= NULL
;
332 TimeStringCopy
= StrnCatGrow(&TimeStringCopy
, NULL
, TimeString
, 0);
333 Walker1
= TimeStringCopy
;
335 TheTime
.Minute
= 0xFF;
337 Walker2
= Walker1
!=NULL
?StrStr(Walker1
, L
":"):NULL
;
338 if (Walker2
!= NULL
&& *Walker2
== L
':') {
339 *Walker2
= CHAR_NULL
;
341 TheTime
.Hour
= (UINT8
)ShellStrToUintn (Walker1
);
342 if (Walker2
!= NULL
) {
343 Walker1
= Walker2
+ 1;
345 Walker2
= Walker1
!=NULL
?StrStr(Walker1
, L
":"):NULL
;
346 if (Walker2
!= NULL
&& *Walker2
== L
':') {
347 *Walker2
= CHAR_NULL
;
348 TheTime
.Second
= (UINT8
)0;
350 else if (Walker2
== NULL
) {
351 TheTime
.Second
= (UINT8
)0;
353 if (Walker1
!= NULL
&& Walker1
[0] != CHAR_NULL
) {
354 TheTime
.Minute
= (UINT8
)ShellStrToUintn (Walker1
);
355 if (Walker2
!= NULL
) {
356 Walker1
= Walker2
+ 1;
357 if (Walker1
!= NULL
&& Walker1
[0] != CHAR_NULL
) {
358 TheTime
.Second
= (UINT8
)ShellStrToUintn (Walker1
);
362 SHELL_FREE_NON_NULL(TimeStringCopy
);
366 if (Tz
>= -1440 && Tz
<= 1440) {
368 // EFI_TIME TimeZone is stored to meet the following calculation (see UEFI Spec):
369 // Localtime = UTC - TimeZone
370 // This means the sign must be changed for the user provided Tz.
371 // EX: User wants to set TimeZone to Pacific Standard Time, so runs
372 // time -tz -480 # set to UTC-08:00
373 // To meet the calculation, the sign must be changed.
375 TheTime
.TimeZone
= -Tz
;
376 } else if (Tz
== EFI_UNSPECIFIED_TIMEZONE
) {
377 TheTime
.TimeZone
= Tz
;
380 if (Daylight
!= 0xFF) {
381 TheTime
.Daylight
= Daylight
;
384 Status
= gRT
->SetTime(&TheTime
);
386 if (!EFI_ERROR(Status
)){
387 return (SHELL_SUCCESS
);
390 return (SHELL_INVALID_PARAMETER
);
394 Function for 'time' command.
396 @param[in] ImageHandle Handle to the Image (NULL if Internal).
397 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
401 ShellCommandRunTime (
402 IN EFI_HANDLE ImageHandle
,
403 IN EFI_SYSTEM_TABLE
*SystemTable
409 CHAR16
*ProblemParam
;
410 SHELL_STATUS ShellStatus
;
413 CONST CHAR16
*TempLocation
;
417 // Initialize variables
419 ShellStatus
= SHELL_SUCCESS
;
423 // initialize the shell lib (we must be in non-auto-init...)
425 Status
= ShellInitialize();
426 ASSERT_EFI_ERROR(Status
);
429 // parse the command line
431 if (PcdGet8(PcdShellSupportLevel
) == 2) {
432 Status
= ShellCommandLineParseEx (TimeParamList2
, &Package
, &ProblemParam
, TRUE
, TRUE
);
434 ASSERT(PcdGet8(PcdShellSupportLevel
) == 3);
435 Status
= ShellCommandLineParseEx (TimeParamList3
, &Package
, &ProblemParam
, TRUE
, TRUE
);
437 if (EFI_ERROR(Status
)) {
438 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
439 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
440 FreePool(ProblemParam
);
441 ShellStatus
= SHELL_INVALID_PARAMETER
;
449 Status
= gRT
->GetTime(&TheTime
, NULL
);
450 if (EFI_ERROR(Status
)) {
451 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
452 return (SHELL_DEVICE_ERROR
);
455 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
457 } else if (ShellCommandLineGetRawValue(Package
, 2) != NULL
) {
458 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
459 ShellStatus
= SHELL_INVALID_PARAMETER
;
462 // If there are no parameters, then print the current time
464 if (ShellCommandLineGetRawValue(Package
, 1) == NULL
465 && !ShellCommandLineGetFlag(Package
, L
"-d")
466 && !ShellCommandLineGetFlag(Package
, L
"-tz")) {
468 // ShellPrintEx the current time
470 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
473 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
476 if (TheTime
.TimeZone
!= EFI_UNSPECIFIED_TIMEZONE
) {
481 STRING_TOKEN (STR_TIME_FORMAT
),
482 gShellLevel2HiiHandle
,
486 (TheTime
.TimeZone
> 0?L
"-":L
"+"),
487 ((ABS(TheTime
.TimeZone
)) / 60),
495 STRING_TOKEN (STR_TIME_FORMAT_LOCAL
),
496 gShellLevel2HiiHandle
,
502 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_CRLF
), gShellLevel2HiiHandle
);
503 } else if (ShellCommandLineGetFlag(Package
, L
"-d") && ShellCommandLineGetValue(Package
, L
"-d") == NULL
) {
504 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
509 STRING_TOKEN (STR_TIME_FORMAT_LOCAL
),
510 gShellLevel2HiiHandle
,
516 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
521 STRING_TOKEN (STR_TIME_FORMAT
),
522 gShellLevel2HiiHandle
,
526 (TheTime
.TimeZone
> 0?L
"-":L
"+"),
527 ((ABS(TheTime
.TimeZone
)) / 60),
531 switch (TheTime
.Daylight
) {
533 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST0
), gShellLevel2HiiHandle
);
535 case EFI_TIME_ADJUST_DAYLIGHT
:
536 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST1
), gShellLevel2HiiHandle
);
538 case EFI_TIME_IN_DAYLIGHT
:
539 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST2
), gShellLevel2HiiHandle
);
541 case EFI_TIME_IN_DAYLIGHT
|EFI_TIME_ADJUST_DAYLIGHT
:
542 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST3
), gShellLevel2HiiHandle
);
545 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_ERROR
), gShellLevel2HiiHandle
, L
"gRT->GetTime", L
"TheTime.Daylight", TheTime
.Daylight
);
548 if (PcdGet8(PcdShellSupportLevel
) == 2) {
549 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
550 ShellStatus
= SHELL_INVALID_PARAMETER
;
553 // perform level 3 operation here.
555 if ((TempLocation
= ShellCommandLineGetValue(Package
, L
"-tz")) != NULL
) {
556 if (StrniCmp (TempLocation
, L
"_local", StrLen (TempLocation
)) == NULL
) {
557 Tz
= EFI_UNSPECIFIED_TIMEZONE
;
558 } else if (TempLocation
[0] == L
'-') {
560 Tz
= (INT16
) ShellStrToUintn (++TempLocation
);
562 // When the argument of "time [-tz tz]" is not numeric, ShellStrToUintn() returns "-1".
563 // Here we can detect the argument error by checking the return of ShellStrToUintn().
566 Tz
= 1441; //make it to be out of bounds value
568 Tz
*= (-1); //sign convert
571 if (TempLocation
[0] == L
'+') {
572 Tz
= (INT16
)ShellStrToUintn (++TempLocation
);
574 Tz
= (INT16
)ShellStrToUintn (TempLocation
);
577 // Detect the return of ShellStrToUintn() to make sure the argument is valid.
580 Tz
= 1441; //make it to be out of bounds value
583 if (!(Tz
>= -1440 && Tz
<= 1440) && Tz
!= EFI_UNSPECIFIED_TIMEZONE
) {
584 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellLevel2HiiHandle
, L
"-tz");
585 ShellStatus
= SHELL_INVALID_PARAMETER
;
589 // intentionally out of bounds value will prevent changing it...
593 TempLocation
= ShellCommandLineGetValue(Package
, L
"-d");
594 if (TempLocation
!= NULL
) {
595 Daylight
= (UINT8
)ShellStrToUintn(TempLocation
);
597 // The argument of "time [-d dl]" is unsigned, if the first character is '-',
598 // the argument is incorrect. That's because ShellStrToUintn() will skip past
599 // any '-' sign and convert what's next, forgetting the sign is here.
601 if (TempLocation
[0] == '-') {
602 Daylight
= 0xff; //make it invalid = will not use
604 if (Daylight
!= 0 && Daylight
!= 1 && Daylight
!= 3) {
605 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellLevel2HiiHandle
, L
"-d");
606 ShellStatus
= SHELL_INVALID_PARAMETER
;
610 // invalid = will not use
614 if (ShellStatus
== SHELL_SUCCESS
) {
615 ShellStatus
= CheckAndSetTime(ShellCommandLineGetRawValue(Package
, 1), Tz
, Daylight
);
616 if (ShellStatus
!= SHELL_SUCCESS
) {
617 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ShellCommandLineGetRawValue(Package
, 1));
618 ShellStatus
= SHELL_INVALID_PARAMETER
;
627 // free the command line package
629 ShellCommandLineFreeVarList (Package
);
634 return (ShellStatus
);
639 EFI_STRING_ID StringId
;
642 STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList2
[] = {
647 STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList3
[] = {
650 {L
"-s", TypeTimeValue
},
654 STATIC CONST TIME_ZONE_ITEM TimeZoneList
[] = {
655 {720, STRING_TOKEN (STR_TIMEZONE_M12
)},
656 {660, STRING_TOKEN (STR_TIMEZONE_M11
)},
657 {600, STRING_TOKEN (STR_TIMEZONE_M10
)},
658 {540, STRING_TOKEN (STR_TIMEZONE_M9
)},
659 {480, STRING_TOKEN (STR_TIMEZONE_M8
)},
660 {420, STRING_TOKEN (STR_TIMEZONE_M7
)},
661 {360, STRING_TOKEN (STR_TIMEZONE_M6
)},
662 {300, STRING_TOKEN (STR_TIMEZONE_M5
)},
663 {270, STRING_TOKEN (STR_TIMEZONE_M430
)},
664 {240, STRING_TOKEN (STR_TIMEZONE_M4
)},
665 {210, STRING_TOKEN (STR_TIMEZONE_M330
)},
666 {180, STRING_TOKEN (STR_TIMEZONE_M3
)},
667 {120, STRING_TOKEN (STR_TIMEZONE_M2
)},
668 {60 , STRING_TOKEN (STR_TIMEZONE_M1
)},
669 {0 , STRING_TOKEN (STR_TIMEZONE_0
)},
670 {-60 , STRING_TOKEN (STR_TIMEZONE_P1
)},
671 {-120 , STRING_TOKEN (STR_TIMEZONE_P2
)},
672 {-180 , STRING_TOKEN (STR_TIMEZONE_P3
)},
673 {-210 , STRING_TOKEN (STR_TIMEZONE_P330
)},
674 {-240 , STRING_TOKEN (STR_TIMEZONE_P4
)},
675 {-270 , STRING_TOKEN (STR_TIMEZONE_P430
)},
676 {-300 , STRING_TOKEN (STR_TIMEZONE_P5
)},
677 {-330 , STRING_TOKEN (STR_TIMEZONE_P530
)},
678 {-345 , STRING_TOKEN (STR_TIMEZONE_P545
)},
679 {-360 , STRING_TOKEN (STR_TIMEZONE_P6
)},
680 {-390 , STRING_TOKEN (STR_TIMEZONE_P630
)},
681 {-420 , STRING_TOKEN (STR_TIMEZONE_P7
)},
682 {-480 , STRING_TOKEN (STR_TIMEZONE_P8
)},
683 {-540 , STRING_TOKEN (STR_TIMEZONE_P9
)},
684 {-570 , STRING_TOKEN (STR_TIMEZONE_P930
)},
685 {-600 , STRING_TOKEN (STR_TIMEZONE_P10
)},
686 {-660 , STRING_TOKEN (STR_TIMEZONE_P11
)},
687 {-720 , STRING_TOKEN (STR_TIMEZONE_P12
)},
688 {-780 , STRING_TOKEN (STR_TIMEZONE_P13
)},
689 {-840 , STRING_TOKEN (STR_TIMEZONE_P14
)},
690 {EFI_UNSPECIFIED_TIMEZONE
, STRING_TOKEN (STR_TIMEZONE_LOCAL
)}
694 Verify that the TimeZoneString is valid and if so set that as the current
697 @param[in] TimeZoneString The pointer to a string representation of the timezone.
699 @retval SHELL_INVALID_PARAMETER TimeZoneString was NULL.
700 @retval SHELL_INVALID_PARAMETER TimeZoneString was mis-formatted.
701 @retval SHELL_SUCCESS The operation was successful.
705 CheckAndSetTimeZone (
706 IN CONST CHAR16
*TimeZoneString
711 CHAR16
*TimeZoneCopy
;
716 if (TimeZoneString
== NULL
) {
717 return (SHELL_INVALID_PARAMETER
);
720 if (StrniCmp (TimeZoneString
, L
"_local", StrLen (TimeZoneString
)) == NULL
) {
721 Status
= gRT
->GetTime (&TheTime
, NULL
);
722 if (EFI_ERROR (Status
)) {
723 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
724 return (SHELL_DEVICE_ERROR
);
727 TheTime
.TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
728 Status
= gRT
->SetTime (&TheTime
);
729 if (!EFI_ERROR(Status
)){
730 return (SHELL_SUCCESS
);
732 return (SHELL_INVALID_PARAMETER
);
734 if (TimeZoneString
!= NULL
&& !InternalIsTimeLikeString(TimeZoneString
, L
':', 1, 1, TRUE
)) {
735 return (SHELL_INVALID_PARAMETER
);
738 Status
= gRT
->GetTime(&TheTime
, NULL
);
739 if (EFI_ERROR(Status
)) {
740 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
741 return (SHELL_DEVICE_ERROR
);
745 TimeZoneCopy
= StrnCatGrow(&TimeZoneCopy
, NULL
, TimeZoneString
, 0);
746 if (TimeZoneCopy
== NULL
) {
747 return (SHELL_OUT_OF_RESOURCES
);
749 Walker
= TimeZoneCopy
;
750 Walker2
= StrStr(Walker
, L
":");
751 if (Walker2
!= NULL
&& *Walker2
== L
':') {
752 *Walker2
= CHAR_NULL
;
754 if (*Walker
== L
'-') {
755 TheTime
.TimeZone
= (INT16
)((ShellStrToUintn (++Walker
)) * 60);
757 TheTime
.TimeZone
= (INT16
)((INT16
)(ShellStrToUintn (Walker
)) * -60);
759 if (Walker2
!= NULL
) {
760 Walker
= Walker2
+ 1;
762 if (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
) {
763 if (TheTime
.TimeZone
< 0) {
764 TheTime
.TimeZone
= (INT16
)(TheTime
.TimeZone
- (UINT8
)ShellStrToUintn (Walker
));
766 TheTime
.TimeZone
= (INT16
)(TheTime
.TimeZone
+ (UINT8
)ShellStrToUintn (Walker
));
770 Status
= EFI_INVALID_PARAMETER
;
773 ; LoopVar
< sizeof(TimeZoneList
) / sizeof(TimeZoneList
[0])
776 if (TheTime
.TimeZone
== TimeZoneList
[LoopVar
].TimeZone
) {
777 Status
= gRT
->SetTime(&TheTime
);
782 FreePool(TimeZoneCopy
);
784 if (!EFI_ERROR(Status
)){
785 return (SHELL_SUCCESS
);
787 return (SHELL_INVALID_PARAMETER
);
792 Function for 'timezone' command.
794 @param[in] ImageHandle Handle to the Image (NULL if Internal).
795 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
799 ShellCommandRunTimeZone (
800 IN EFI_HANDLE ImageHandle
,
801 IN EFI_SYSTEM_TABLE
*SystemTable
809 CHAR16
*ProblemParam
;
810 SHELL_STATUS ShellStatus
;
816 ShellStatus
= SHELL_SUCCESS
;
820 // initialize the shell lib (we must be in non-auto-init...)
822 Status
= ShellInitialize();
823 ASSERT_EFI_ERROR(Status
);
826 // parse the command line
828 if (PcdGet8(PcdShellSupportLevel
) == 2) {
829 Status
= ShellCommandLineParse (TimeZoneParamList2
, &Package
, &ProblemParam
, TRUE
);
831 ASSERT(PcdGet8(PcdShellSupportLevel
) == 3);
832 Status
= ShellCommandLineParseEx (TimeZoneParamList3
, &Package
, &ProblemParam
, TRUE
, TRUE
);
834 if (EFI_ERROR(Status
)) {
835 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
836 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
837 FreePool(ProblemParam
);
838 ShellStatus
= SHELL_INVALID_PARAMETER
;
846 if (ShellCommandLineGetCount(Package
) > 1) {
847 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
848 ShellStatus
= SHELL_INVALID_PARAMETER
;
849 } else if (ShellCommandLineGetFlag(Package
, L
"-?")) {
851 } else if (ShellCommandLineGetFlag(Package
, L
"-s")) {
852 if ((ShellCommandLineGetFlag(Package
, L
"-l")) || (ShellCommandLineGetFlag(Package
, L
"-f"))) {
853 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"-l or -f");
854 ShellStatus
= SHELL_INVALID_PARAMETER
;
856 ASSERT(PcdGet8(PcdShellSupportLevel
) == 3);
857 if (ShellCommandLineGetValue(Package
, L
"-s") == NULL
) {
858 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellLevel2HiiHandle
, L
"-s");
859 ShellStatus
= SHELL_INVALID_PARAMETER
;
864 ShellStatus
= CheckAndSetTimeZone(ShellCommandLineGetValue(Package
, L
"-s"));
865 if (ShellStatus
!= SHELL_SUCCESS
) {
866 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ShellCommandLineGetValue(Package
, L
"-s"));
867 ShellStatus
= SHELL_INVALID_PARAMETER
;
871 } else if (ShellCommandLineGetFlag(Package
, L
"-l")) {
873 // Print a list of all time zones
876 ; LoopVar
< sizeof(TimeZoneList
) / sizeof(TimeZoneList
[0])
879 ShellPrintHiiEx (-1, -1, NULL
, TimeZoneList
[LoopVar
].StringId
, gShellLevel2HiiHandle
);
883 // Get Current Time Zone Info
885 Status
= gRT
->GetTime(&TheTime
, NULL
);
886 if (EFI_ERROR(Status
)) {
887 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
888 return (SHELL_DEVICE_ERROR
);
891 if (TheTime
.TimeZone
!= EFI_UNSPECIFIED_TIMEZONE
) {
894 ; LoopVar
< sizeof(TimeZoneList
) / sizeof(TimeZoneList
[0])
897 if (TheTime
.TimeZone
== TimeZoneList
[LoopVar
].TimeZone
) {
898 if (ShellCommandLineGetFlag(Package
, L
"-f")) {
900 // Print all info about current time zone
902 ShellPrintHiiEx (-1, -1, NULL
, TimeZoneList
[LoopVar
].StringId
, gShellLevel2HiiHandle
);
905 // Print basic info only
907 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
913 STRING_TOKEN(STR_TIMEZONE_SIMPLE
),
914 gShellLevel2HiiHandle
,
915 (TheTime
.TimeZone
> 0?L
"-":L
"+"),
916 (ABS(TheTime
.TimeZone
)) / 60,
925 // Print basic info only
927 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
933 STRING_TOKEN(STR_TIMEZONE_SIMPLE
),
934 gShellLevel2HiiHandle
,
935 (TheTime
.TimeZone
> 0?L
"-":L
"+"),
936 (ABS(TheTime
.TimeZone
)) / 60,
939 if (ShellCommandLineGetFlag(Package
, L
"-f")) {
940 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN(STR_TIMEZONE_NI
), gShellLevel2HiiHandle
);
945 // TimeZone was EFI_UNSPECIFIED_TIMEZONE (local) from GetTime()
947 if (ShellCommandLineGetFlag (Package
, L
"-f")) {
949 ; LoopVar
< sizeof (TimeZoneList
) / sizeof (TimeZoneList
[0])
952 if (TheTime
.TimeZone
== TimeZoneList
[LoopVar
].TimeZone
) {
954 // Print all info about current time zone
956 ShellPrintHiiEx (-1, -1, NULL
, TimeZoneList
[LoopVar
].StringId
, gShellLevel2HiiHandle
);
962 // Print basic info only
964 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_TIMEZONE_SIMPLE_LOCAL
), gShellLevel2HiiHandle
);
971 // free the command line package
973 ShellCommandLineFreeVarList (Package
);
975 return (ShellStatus
);