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 - 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.
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.
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
);
114 Walker
= DateStringCopy
;
116 TheTime
.Month
= 0xFF;
118 TheTime
.Year
= 0xFFFF;
120 Walker1
= StrStr(Walker
, L
"/");
121 if (Walker1
!= NULL
&& *Walker1
== L
'/') {
122 *Walker1
= CHAR_NULL
;
125 TheTime
.Month
= (UINT8
)ShellStrToUintn (Walker
);
126 if (Walker1
!= NULL
) {
127 Walker
= Walker1
+ 1;
129 Walker1
= Walker
!=NULL
?StrStr(Walker
, L
"/"):NULL
;
130 if (Walker1
!= NULL
&& *Walker1
== L
'/') {
131 *Walker1
= CHAR_NULL
;
133 if (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
) {
134 TheTime
.Day
= (UINT8
)ShellStrToUintn (Walker
);
135 if (Walker1
!= NULL
) {
136 Walker
= Walker1
+ 1;
138 Walker1
= Walker
!=NULL
?StrStr(Walker
, L
"/"):NULL
;
139 if (Walker1
!= NULL
&& *Walker1
== L
'/') {
140 *Walker1
= CHAR_NULL
;
142 if (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
) {
143 TheTime
.Year
= (UINT16
)ShellStrToUintn (Walker
);
147 if (TheTime
.Year
< 100) {
148 if (TheTime
.Year
>= 98) {
149 TheTime
.Year
= (UINT16
)(1900 + TheTime
.Year
);
151 TheTime
.Year
= (UINT16
)(2000 + TheTime
.Year
);
155 Status
= gRT
->SetTime(&TheTime
);
157 if (!EFI_ERROR(Status
)){
158 return (SHELL_SUCCESS
);
160 return (SHELL_INVALID_PARAMETER
);
164 Function for 'date' command.
166 @param[in] ImageHandle Handle to the Image (NULL if Internal).
167 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
171 ShellCommandRunDate (
172 IN EFI_HANDLE ImageHandle
,
173 IN EFI_SYSTEM_TABLE
*SystemTable
179 CHAR16
*ProblemParam
;
180 SHELL_STATUS ShellStatus
;
181 CONST CHAR16
*Param1
;
183 ShellStatus
= SHELL_SUCCESS
;
187 // initialize the shell lib (we must be in non-auto-init...)
189 Status
= ShellInitialize();
190 ASSERT_EFI_ERROR(Status
);
193 // parse the command line
195 Status
= ShellCommandLineParse (SfoParamList
, &Package
, &ProblemParam
, TRUE
);
196 if (EFI_ERROR(Status
)) {
197 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
198 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"date", ProblemParam
);
199 FreePool(ProblemParam
);
200 ShellStatus
= SHELL_INVALID_PARAMETER
;
208 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
210 } else if (ShellCommandLineGetRawValue(Package
, 2) != NULL
) {
211 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"date");
212 ShellStatus
= SHELL_INVALID_PARAMETER
;
215 // If there are 0 value parameters, then print the current date
216 // else If there are any value paramerers, then print error
218 if (ShellCommandLineGetRawValue(Package
, 1) == NULL
) {
220 // get the current date
222 Status
= gRT
->GetTime(&TheTime
, NULL
);
223 if (EFI_ERROR(Status
)) {
224 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"date", L
"gRT->GetTime", Status
);
225 return (SHELL_DEVICE_ERROR
);
229 // ShellPrintEx the date in SFO or regular format
231 if (ShellCommandLineGetFlag(Package
, L
"-sfo")) {
233 // Match UEFI Shell spec:
234 // ShellCommand,"date"
235 // Date,"DD","MM","YYYY"
237 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_SFO_HEADER
), gShellLevel2HiiHandle
, L
"date");
238 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DATE_SFO_FORMAT
), gShellLevel2HiiHandle
, TheTime
.Day
, TheTime
.Month
, TheTime
.Year
);
240 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DATE_FORMAT
), gShellLevel2HiiHandle
, TheTime
.Month
, TheTime
.Day
, TheTime
.Year
);
243 if (PcdGet8(PcdShellSupportLevel
) == 2) {
244 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"date");
245 ShellStatus
= SHELL_INVALID_PARAMETER
;
248 // perform level 3 operation here.
250 Param1
= ShellCommandLineGetRawValue(Package
, 1);
251 if (Param1
== NULL
) {
252 ShellStatus
= SHELL_INVALID_PARAMETER
;
254 ShellStatus
= CheckAndSetDate(Param1
);
256 if (ShellStatus
!= SHELL_SUCCESS
) {
257 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"date", Param1
);
258 ShellStatus
= SHELL_INVALID_PARAMETER
;
265 // free the command line package
267 ShellCommandLineFreeVarList (Package
);
272 return (ShellStatus
);
276 // Note "-tz" is invalid for this (non-interactive) version of 'time'.
278 STATIC CONST SHELL_PARAM_ITEM TimeParamList2
[] = {
283 STATIC CONST SHELL_PARAM_ITEM TimeParamList3
[] = {
290 Verify that the TimeString is valid and if so set that as the current
293 @param[in] TimeString The pointer to a string representation of the time.
294 @param[in] Tz The value to set for TimeZone.
295 @param[in] Daylight The value to set for Daylight.
297 @retval SHELL_INVALID_PARAMETER TimeString was NULL.
298 @retval SHELL_INVALID_PARAMETER TimeString was mis-formatted.
299 @retval SHELL_SUCCESS The operation was successful.
303 IN CONST CHAR16
*TimeString
,
305 IN CONST UINT8 Daylight
310 CHAR16
*TimeStringCopy
;
314 if (TimeString
!= NULL
&& !InternalIsTimeLikeString(TimeString
, L
':', 1, 2, FALSE
)) {
315 return (SHELL_INVALID_PARAMETER
);
317 if (Daylight
!= 0xFF &&((Daylight
& (EFI_TIME_IN_DAYLIGHT
|EFI_TIME_ADJUST_DAYLIGHT
)) != Daylight
)) {
318 return (SHELL_INVALID_PARAMETER
);
321 Status
= gRT
->GetTime(&TheTime
, NULL
);
322 if (EFI_ERROR(Status
)) {
323 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"time", L
"gRT->GetTime", Status
);
324 return (SHELL_DEVICE_ERROR
);
327 if (TimeString
!= NULL
) {
328 TimeStringCopy
= NULL
;
329 TimeStringCopy
= StrnCatGrow(&TimeStringCopy
, NULL
, TimeString
, 0);
330 Walker1
= TimeStringCopy
;
332 TheTime
.Minute
= 0xFF;
334 Walker2
= Walker1
!=NULL
?StrStr(Walker1
, L
":"):NULL
;
335 if (Walker2
!= NULL
&& *Walker2
== L
':') {
336 *Walker2
= CHAR_NULL
;
338 TheTime
.Hour
= (UINT8
)ShellStrToUintn (Walker1
);
339 if (Walker2
!= NULL
) {
340 Walker1
= Walker2
+ 1;
342 Walker2
= Walker1
!=NULL
?StrStr(Walker1
, L
":"):NULL
;
343 if (Walker2
!= NULL
&& *Walker2
== L
':') {
344 *Walker2
= CHAR_NULL
;
345 TheTime
.Second
= (UINT8
)0;
347 else if (Walker2
== NULL
) {
348 TheTime
.Second
= (UINT8
)0;
350 if (Walker1
!= NULL
&& Walker1
[0] != CHAR_NULL
) {
351 TheTime
.Minute
= (UINT8
)ShellStrToUintn (Walker1
);
352 if (Walker2
!= NULL
) {
353 Walker1
= Walker2
+ 1;
354 if (Walker1
!= NULL
&& Walker1
[0] != CHAR_NULL
) {
355 TheTime
.Second
= (UINT8
)ShellStrToUintn (Walker1
);
359 SHELL_FREE_NON_NULL(TimeStringCopy
);
363 if (Tz
>= -1440 && Tz
<= 1440) {
365 // EFI_TIME TimeZone is stored to meet the following calculation (see UEFI Spec):
366 // Localtime = UTC - TimeZone
367 // This means the sign must be changed for the user provided Tz.
368 // EX: User wants to set TimeZone to Pacific Standard Time, so runs
369 // time -tz -480 # set to UTC-08:00
370 // To meet the calculation, the sign must be changed.
372 TheTime
.TimeZone
= -Tz
;
373 } else if (Tz
== EFI_UNSPECIFIED_TIMEZONE
) {
374 TheTime
.TimeZone
= Tz
;
377 if (Daylight
!= 0xFF) {
378 TheTime
.Daylight
= Daylight
;
381 Status
= gRT
->SetTime(&TheTime
);
383 if (!EFI_ERROR(Status
)){
384 return (SHELL_SUCCESS
);
387 return (SHELL_INVALID_PARAMETER
);
391 Function for 'time' command.
393 @param[in] ImageHandle Handle to the Image (NULL if Internal).
394 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
398 ShellCommandRunTime (
399 IN EFI_HANDLE ImageHandle
,
400 IN EFI_SYSTEM_TABLE
*SystemTable
406 CHAR16
*ProblemParam
;
407 SHELL_STATUS ShellStatus
;
410 CONST CHAR16
*TempLocation
;
414 // Initialize variables
416 ShellStatus
= SHELL_SUCCESS
;
420 // initialize the shell lib (we must be in non-auto-init...)
422 Status
= ShellInitialize();
423 ASSERT_EFI_ERROR(Status
);
426 // parse the command line
428 if (PcdGet8(PcdShellSupportLevel
) == 2) {
429 Status
= ShellCommandLineParseEx (TimeParamList2
, &Package
, &ProblemParam
, TRUE
, TRUE
);
431 ASSERT(PcdGet8(PcdShellSupportLevel
) == 3);
432 Status
= ShellCommandLineParseEx (TimeParamList3
, &Package
, &ProblemParam
, TRUE
, TRUE
);
434 if (EFI_ERROR(Status
)) {
435 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
436 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"time", ProblemParam
);
437 FreePool(ProblemParam
);
438 ShellStatus
= SHELL_INVALID_PARAMETER
;
446 Status
= gRT
->GetTime(&TheTime
, NULL
);
447 if (EFI_ERROR(Status
)) {
448 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"time", L
"gRT->GetTime", Status
);
449 return (SHELL_DEVICE_ERROR
);
452 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
454 } else if (ShellCommandLineGetRawValue(Package
, 2) != NULL
) {
455 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"time");
456 ShellStatus
= SHELL_INVALID_PARAMETER
;
459 // If there are no parameters, then print the current time
461 if (ShellCommandLineGetRawValue(Package
, 1) == NULL
462 && !ShellCommandLineGetFlag(Package
, L
"-d")
463 && !ShellCommandLineGetFlag(Package
, L
"-tz")) {
465 // ShellPrintEx the current time
467 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
470 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
473 if (TheTime
.TimeZone
!= EFI_UNSPECIFIED_TIMEZONE
) {
478 STRING_TOKEN (STR_TIME_FORMAT
),
479 gShellLevel2HiiHandle
,
483 (TheTime
.TimeZone
> 0?L
"-":L
"+"),
484 ((ABS(TheTime
.TimeZone
)) / 60),
492 STRING_TOKEN (STR_TIME_FORMAT_LOCAL
),
493 gShellLevel2HiiHandle
,
499 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_CRLF
), gShellLevel2HiiHandle
);
500 } else if (ShellCommandLineGetFlag(Package
, L
"-d") && ShellCommandLineGetValue(Package
, L
"-d") == NULL
) {
501 if (TheTime
.TimeZone
== EFI_UNSPECIFIED_TIMEZONE
) {
506 STRING_TOKEN (STR_TIME_FORMAT_LOCAL
),
507 gShellLevel2HiiHandle
,
513 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
518 STRING_TOKEN (STR_TIME_FORMAT
),
519 gShellLevel2HiiHandle
,
523 (TheTime
.TimeZone
> 0?L
"-":L
"+"),
524 ((ABS(TheTime
.TimeZone
)) / 60),
528 switch (TheTime
.Daylight
) {
530 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST0
), gShellLevel2HiiHandle
);
532 case EFI_TIME_ADJUST_DAYLIGHT
:
533 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST1
), gShellLevel2HiiHandle
);
535 case EFI_TIME_IN_DAYLIGHT
:
536 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST2
), gShellLevel2HiiHandle
);
538 case EFI_TIME_IN_DAYLIGHT
|EFI_TIME_ADJUST_DAYLIGHT
:
539 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_TIME_DST3
), gShellLevel2HiiHandle
);
542 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_ERROR
), gShellLevel2HiiHandle
, L
"time", L
"gRT->GetTime", L
"TheTime.Daylight", TheTime
.Daylight
);
545 if (PcdGet8(PcdShellSupportLevel
) == 2) {
546 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"time");
547 ShellStatus
= SHELL_INVALID_PARAMETER
;
550 // perform level 3 operation here.
552 if ((TempLocation
= ShellCommandLineGetValue(Package
, L
"-tz")) != NULL
) {
553 if (StrniCmp (TempLocation
, L
"_local", StrLen (TempLocation
)) == NULL
) {
554 Tz
= EFI_UNSPECIFIED_TIMEZONE
;
555 } else if (TempLocation
[0] == L
'-') {
557 Tz
= (INT16
) ShellStrToUintn (++TempLocation
);
559 // When the argument of "time [-tz tz]" is not numeric, ShellStrToUintn() returns "-1".
560 // Here we can detect the argument error by checking the return of ShellStrToUintn().
563 Tz
= 1441; //make it to be out of bounds value
565 Tz
*= (-1); //sign convert
568 if (TempLocation
[0] == L
'+') {
569 Tz
= (INT16
)ShellStrToUintn (++TempLocation
);
571 Tz
= (INT16
)ShellStrToUintn (TempLocation
);
574 // Detect the return of ShellStrToUintn() to make sure the argument is valid.
577 Tz
= 1441; //make it to be out of bounds value
580 if (!(Tz
>= -1440 && Tz
<= 1440) && Tz
!= EFI_UNSPECIFIED_TIMEZONE
) {
581 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellLevel2HiiHandle
, L
"time", TempLocation
, L
"-tz");
582 ShellStatus
= SHELL_INVALID_PARAMETER
;
586 // intentionally out of bounds value will prevent changing it...
590 TempLocation
= ShellCommandLineGetValue(Package
, L
"-d");
591 if (TempLocation
!= NULL
) {
592 Daylight
= (UINT8
)ShellStrToUintn(TempLocation
);
594 // The argument of "time [-d dl]" is unsigned, if the first character is '-',
595 // the argument is incorrect. That's because ShellStrToUintn() will skip past
596 // any '-' sign and convert what's next, forgetting the sign is here.
598 if (TempLocation
[0] == '-') {
599 Daylight
= 0xff; //make it invalid = will not use
601 if (Daylight
!= 0 && Daylight
!= 1 && Daylight
!= 3) {
602 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellLevel2HiiHandle
, L
"time", TempLocation
, L
"-d");
603 ShellStatus
= SHELL_INVALID_PARAMETER
;
607 // invalid = will not use
611 if (ShellStatus
== SHELL_SUCCESS
) {
612 ShellStatus
= CheckAndSetTime(ShellCommandLineGetRawValue(Package
, 1), Tz
, Daylight
);
613 if (ShellStatus
!= SHELL_SUCCESS
) {
614 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"time", ShellCommandLineGetRawValue(Package
, 1));
615 ShellStatus
= SHELL_INVALID_PARAMETER
;
624 // free the command line package
626 ShellCommandLineFreeVarList (Package
);
631 return (ShellStatus
);
636 EFI_STRING_ID StringId
;
639 STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList2
[] = {
644 STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList3
[] = {
647 {L
"-s", TypeTimeValue
},
651 STATIC CONST TIME_ZONE_ITEM TimeZoneList
[] = {
652 {720, STRING_TOKEN (STR_TIMEZONE_M12
)},
653 {660, STRING_TOKEN (STR_TIMEZONE_M11
)},
654 {600, STRING_TOKEN (STR_TIMEZONE_M10
)},
655 {540, STRING_TOKEN (STR_TIMEZONE_M9
)},
656 {480, STRING_TOKEN (STR_TIMEZONE_M8
)},
657 {420, STRING_TOKEN (STR_TIMEZONE_M7
)},
658 {360, STRING_TOKEN (STR_TIMEZONE_M6
)},
659 {300, STRING_TOKEN (STR_TIMEZONE_M5
)},
660 {270, STRING_TOKEN (STR_TIMEZONE_M430
)},
661 {240, STRING_TOKEN (STR_TIMEZONE_M4
)},
662 {210, STRING_TOKEN (STR_TIMEZONE_M330
)},
663 {180, STRING_TOKEN (STR_TIMEZONE_M3
)},
664 {120, STRING_TOKEN (STR_TIMEZONE_M2
)},
665 {60 , STRING_TOKEN (STR_TIMEZONE_M1
)},
666 {0 , STRING_TOKEN (STR_TIMEZONE_0
)},
667 {-60 , STRING_TOKEN (STR_TIMEZONE_P1
)},
668 {-120 , STRING_TOKEN (STR_TIMEZONE_P2
)},
669 {-180 , STRING_TOKEN (STR_TIMEZONE_P3
)},
670 {-210 , STRING_TOKEN (STR_TIMEZONE_P330
)},
671 {-240 , STRING_TOKEN (STR_TIMEZONE_P4
)},
672 {-270 , STRING_TOKEN (STR_TIMEZONE_P430
)},
673 {-300 , STRING_TOKEN (STR_TIMEZONE_P5
)},
674 {-330 , STRING_TOKEN (STR_TIMEZONE_P530
)},
675 {-345 , STRING_TOKEN (STR_TIMEZONE_P545
)},
676 {-360 , STRING_TOKEN (STR_TIMEZONE_P6
)},
677 {-390 , STRING_TOKEN (STR_TIMEZONE_P630
)},
678 {-420 , STRING_TOKEN (STR_TIMEZONE_P7
)},
679 {-480 , STRING_TOKEN (STR_TIMEZONE_P8
)},
680 {-540 , STRING_TOKEN (STR_TIMEZONE_P9
)},
681 {-570 , STRING_TOKEN (STR_TIMEZONE_P930
)},
682 {-600 , STRING_TOKEN (STR_TIMEZONE_P10
)},
683 {-660 , STRING_TOKEN (STR_TIMEZONE_P11
)},
684 {-720 , STRING_TOKEN (STR_TIMEZONE_P12
)},
685 {-780 , STRING_TOKEN (STR_TIMEZONE_P13
)},
686 {-840 , STRING_TOKEN (STR_TIMEZONE_P14
)},
687 {EFI_UNSPECIFIED_TIMEZONE
, STRING_TOKEN (STR_TIMEZONE_LOCAL
)}
691 Verify that the TimeZoneString is valid and if so set that as the current
694 @param[in] TimeZoneString The pointer to a string representation of the timezone.
696 @retval SHELL_INVALID_PARAMETER TimeZoneString was NULL.
697 @retval SHELL_INVALID_PARAMETER TimeZoneString was mis-formatted.
698 @retval SHELL_SUCCESS The operation was successful.
701 CheckAndSetTimeZone (
702 IN CONST CHAR16
*TimeZoneString
707 CHAR16
*TimeZoneCopy
;
712 if (TimeZoneString
== NULL
) {
713 return (SHELL_INVALID_PARAMETER
);
716 if (StrniCmp (TimeZoneString
, L
"_local", StrLen (TimeZoneString
)) == NULL
) {
717 Status
= gRT
->GetTime (&TheTime
, NULL
);
718 if (EFI_ERROR (Status
)) {
719 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"gRT->GetTime", Status
);
720 return (SHELL_DEVICE_ERROR
);
723 TheTime
.TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
724 Status
= gRT
->SetTime (&TheTime
);
725 if (!EFI_ERROR(Status
)){
726 return (SHELL_SUCCESS
);
728 return (SHELL_INVALID_PARAMETER
);
730 if (TimeZoneString
!= NULL
&& !InternalIsTimeLikeString(TimeZoneString
, L
':', 1, 1, TRUE
)) {
731 return (SHELL_INVALID_PARAMETER
);
734 Status
= gRT
->GetTime(&TheTime
, NULL
);
735 if (EFI_ERROR(Status
)) {
736 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"timezone", L
"gRT->GetTime", Status
);
737 return (SHELL_DEVICE_ERROR
);
741 TimeZoneCopy
= StrnCatGrow(&TimeZoneCopy
, NULL
, TimeZoneString
, 0);
742 if (TimeZoneCopy
== NULL
) {
743 return (SHELL_OUT_OF_RESOURCES
);
745 Walker
= TimeZoneCopy
;
746 Walker2
= StrStr(Walker
, L
":");
747 if (Walker2
!= NULL
&& *Walker2
== L
':') {
748 *Walker2
= CHAR_NULL
;
750 if (*Walker
== L
'-') {
751 TheTime
.TimeZone
= (INT16
)((ShellStrToUintn (++Walker
)) * 60);
753 TheTime
.TimeZone
= (INT16
)((INT16
)(ShellStrToUintn (Walker
)) * -60);
755 if (Walker2
!= NULL
) {
756 Walker
= Walker2
+ 1;
758 if (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
) {
759 if (TheTime
.TimeZone
< 0) {
760 TheTime
.TimeZone
= (INT16
)(TheTime
.TimeZone
- (UINT8
)ShellStrToUintn (Walker
));
762 TheTime
.TimeZone
= (INT16
)(TheTime
.TimeZone
+ (UINT8
)ShellStrToUintn (Walker
));
766 Status
= EFI_INVALID_PARAMETER
;
769 ; LoopVar
< sizeof(TimeZoneList
) / sizeof(TimeZoneList
[0])
772 if (TheTime
.TimeZone
== TimeZoneList
[LoopVar
].TimeZone
) {
773 Status
= gRT
->SetTime(&TheTime
);
778 FreePool(TimeZoneCopy
);
780 if (!EFI_ERROR(Status
)){
781 return (SHELL_SUCCESS
);
783 return (SHELL_INVALID_PARAMETER
);
788 Function for 'timezone' command.
790 @param[in] ImageHandle Handle to the Image (NULL if Internal).
791 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
795 ShellCommandRunTimeZone (
796 IN EFI_HANDLE ImageHandle
,
797 IN EFI_SYSTEM_TABLE
*SystemTable
805 CHAR16
*ProblemParam
;
806 SHELL_STATUS ShellStatus
;
812 ShellStatus
= SHELL_SUCCESS
;
816 // initialize the shell lib (we must be in non-auto-init...)
818 Status
= ShellInitialize();
819 ASSERT_EFI_ERROR(Status
);
822 // parse the command line
824 if (PcdGet8(PcdShellSupportLevel
) == 2) {
825 Status
= ShellCommandLineParse (TimeZoneParamList2
, &Package
, &ProblemParam
, TRUE
);
827 ASSERT(PcdGet8(PcdShellSupportLevel
) == 3);
828 Status
= ShellCommandLineParseEx (TimeZoneParamList3
, &Package
, &ProblemParam
, TRUE
, TRUE
);
830 if (EFI_ERROR(Status
)) {
831 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
832 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"timezone", ProblemParam
);
833 FreePool(ProblemParam
);
834 ShellStatus
= SHELL_INVALID_PARAMETER
;
842 if (ShellCommandLineGetCount(Package
) > 1) {
843 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"timezone");
844 ShellStatus
= SHELL_INVALID_PARAMETER
;
845 } else if (ShellCommandLineGetFlag(Package
, L
"-?")) {
847 } else if (ShellCommandLineGetFlag(Package
, L
"-s")) {
848 if ((ShellCommandLineGetFlag(Package
, L
"-l")) || (ShellCommandLineGetFlag(Package
, L
"-f"))) {
849 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"timezone", L
"-l or -f");
850 ShellStatus
= SHELL_INVALID_PARAMETER
;
852 ASSERT(PcdGet8(PcdShellSupportLevel
) == 3);
853 if (ShellCommandLineGetValue(Package
, L
"-s") == NULL
) {
854 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellLevel2HiiHandle
, L
"timezone", L
"-s");
855 ShellStatus
= SHELL_INVALID_PARAMETER
;
860 ShellStatus
= CheckAndSetTimeZone(ShellCommandLineGetValue(Package
, L
"-s"));
861 if (ShellStatus
!= SHELL_SUCCESS
) {
862 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel2HiiHandle
, L
"timezone", ShellCommandLineGetValue(Package
, L
"-s"));
863 ShellStatus
= SHELL_INVALID_PARAMETER
;
867 } else if (ShellCommandLineGetFlag(Package
, L
"-l")) {
869 // Print a list of all time zones
872 ; LoopVar
< sizeof(TimeZoneList
) / sizeof(TimeZoneList
[0])
875 ShellPrintHiiEx (-1, -1, NULL
, TimeZoneList
[LoopVar
].StringId
, gShellLevel2HiiHandle
);
879 // Get Current Time Zone Info
881 Status
= gRT
->GetTime(&TheTime
, NULL
);
882 if (EFI_ERROR(Status
)) {
883 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN
), gShellLevel2HiiHandle
, L
"timezone", L
"gRT->GetTime", Status
);
884 return (SHELL_DEVICE_ERROR
);
887 if (TheTime
.TimeZone
!= EFI_UNSPECIFIED_TIMEZONE
) {
890 ; LoopVar
< sizeof(TimeZoneList
) / sizeof(TimeZoneList
[0])
893 if (TheTime
.TimeZone
== TimeZoneList
[LoopVar
].TimeZone
) {
894 if (ShellCommandLineGetFlag(Package
, L
"-f")) {
896 // Print all info about current time zone
898 ShellPrintHiiEx (-1, -1, NULL
, TimeZoneList
[LoopVar
].StringId
, gShellLevel2HiiHandle
);
901 // Print basic info only
903 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
909 STRING_TOKEN(STR_TIMEZONE_SIMPLE
),
910 gShellLevel2HiiHandle
,
911 (TheTime
.TimeZone
> 0?L
"-":L
"+"),
912 (ABS(TheTime
.TimeZone
)) / 60,
921 // Print basic info only
923 TzMinutes
= (ABS(TheTime
.TimeZone
)) % 60;
929 STRING_TOKEN(STR_TIMEZONE_SIMPLE
),
930 gShellLevel2HiiHandle
,
931 (TheTime
.TimeZone
> 0?L
"-":L
"+"),
932 (ABS(TheTime
.TimeZone
)) / 60,
935 if (ShellCommandLineGetFlag(Package
, L
"-f")) {
936 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN(STR_TIMEZONE_NI
), gShellLevel2HiiHandle
);
941 // TimeZone was EFI_UNSPECIFIED_TIMEZONE (local) from GetTime()
943 if (ShellCommandLineGetFlag (Package
, L
"-f")) {
945 ; LoopVar
< ARRAY_SIZE (TimeZoneList
)
948 if (TheTime
.TimeZone
== TimeZoneList
[LoopVar
].TimeZone
) {
950 // Print all info about current time zone
952 ShellPrintHiiEx (-1, -1, NULL
, TimeZoneList
[LoopVar
].StringId
, gShellLevel2HiiHandle
);
958 // Print basic info only
960 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_TIMEZONE_SIMPLE_LOCAL
), gShellLevel2HiiHandle
);
967 // free the command line package
969 ShellCommandLineFreeVarList (Package
);
971 return (ShellStatus
);