TianoCore EDK2 master
Loading...
Searching...
No Matches
TimeDate.c
Go to the documentation of this file.
1
11
24BOOLEAN
26 IN CONST CHAR16 *String,
27 IN CONST CHAR16 Char,
28 IN CONST UINTN Min,
29 IN CONST UINTN Max,
30 IN CONST BOOLEAN MinusOk
31 )
32{
33 UINTN Count;
34
35 Count = 0;
36
37 if (MinusOk) {
38 //
39 // A single minus is ok.
40 //
41 if (*String == L'-') {
42 String++;
43 }
44 }
45
46 //
47 // the first char must be numeric.
48 //
49 if (!ShellIsDecimalDigitCharacter (*String)) {
50 return (FALSE);
51 }
52
53 //
54 // loop through the characters and use the lib function
55 //
56 for ( ; String != NULL && *String != CHAR_NULL; String++) {
57 if (*String == Char) {
58 Count++;
59 if (Count > Max) {
60 return (FALSE);
61 }
62
63 continue;
64 }
65
66 if (!ShellIsDecimalDigitCharacter (*String)) {
67 return (FALSE);
68 }
69 }
70
71 if (Count < Min) {
72 return (FALSE);
73 }
74
75 return (TRUE);
76}
77
90 IN CONST CHAR16 *DateString
91 )
92{
93 EFI_TIME TheTime;
94 EFI_STATUS Status;
95 CHAR16 *DateStringCopy;
96 CHAR16 *Walker;
97 CHAR16 *Walker1;
98
99 if (!InternalIsTimeLikeString (DateString, L'/', 2, 2, FALSE)) {
101 }
102
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);
107 }
108
109 DateStringCopy = NULL;
110 DateStringCopy = StrnCatGrow (&DateStringCopy, NULL, DateString, 0);
111 if (DateStringCopy == NULL) {
112 return (SHELL_OUT_OF_RESOURCES);
113 }
114
115 Walker = DateStringCopy;
116
117 TheTime.Month = 0xFF;
118 TheTime.Day = 0xFF;
119 TheTime.Year = 0xFFFF;
120
121 Walker1 = StrStr (Walker, L"/");
122 if ((Walker1 != NULL) && (*Walker1 == L'/')) {
123 *Walker1 = CHAR_NULL;
124 }
125
126 TheTime.Month = (UINT8)ShellStrToUintn (Walker);
127 if (Walker1 != NULL) {
128 Walker = Walker1 + 1;
129 }
130
131 Walker1 = Walker != NULL ? StrStr (Walker, L"/") : NULL;
132 if ((Walker1 != NULL) && (*Walker1 == L'/')) {
133 *Walker1 = CHAR_NULL;
134 }
135
136 if ((Walker != NULL) && (Walker[0] != CHAR_NULL)) {
137 TheTime.Day = (UINT8)ShellStrToUintn (Walker);
138 if (Walker1 != NULL) {
139 Walker = Walker1 + 1;
140 }
141
142 Walker1 = Walker != NULL ? StrStr (Walker, L"/") : NULL;
143 if ((Walker1 != NULL) && (*Walker1 == L'/')) {
144 *Walker1 = CHAR_NULL;
145 }
146
147 if ((Walker != NULL) && (Walker[0] != CHAR_NULL)) {
148 TheTime.Year = (UINT16)ShellStrToUintn (Walker);
149 }
150 }
151
152 if (TheTime.Year < 100) {
153 if (TheTime.Year >= 98) {
154 TheTime.Year = (UINT16)(1900 + TheTime.Year);
155 } else {
156 TheTime.Year = (UINT16)(2000 + TheTime.Year);
157 }
158 }
159
160 Status = gRT->SetTime (&TheTime);
161
162 if (!EFI_ERROR (Status)) {
163 return (SHELL_SUCCESS);
164 }
165
167}
168
176EFIAPI
178 IN EFI_HANDLE ImageHandle,
179 IN EFI_SYSTEM_TABLE *SystemTable
180 )
181{
182 EFI_STATUS Status;
183 LIST_ENTRY *Package;
184 EFI_TIME TheTime;
185 CHAR16 *ProblemParam;
186 SHELL_STATUS ShellStatus;
187 CONST CHAR16 *Param1;
188
189 ShellStatus = SHELL_SUCCESS;
190 ProblemParam = NULL;
191
192 //
193 // initialize the shell lib (we must be in non-auto-init...)
194 //
195 Status = ShellInitialize ();
196 ASSERT_EFI_ERROR (Status);
197
198 //
199 // parse the command line
200 //
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;
207 } else {
208 ASSERT (FALSE);
209 }
210 } else {
211 //
212 // check for "-?"
213 //
214 if (ShellCommandLineGetFlag (Package, L"-?")) {
215 ASSERT (FALSE);
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;
219 } else {
220 //
221 // If there are 0 value parameters, then print the current date
222 // else If there are any value paramerers, then print error
223 //
224 if (ShellCommandLineGetRawValue (Package, 1) == NULL) {
225 //
226 // get the current date
227 //
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);
232 }
233
234 //
235 // ShellPrintEx the date in SFO or regular format
236 //
237 if (ShellCommandLineGetFlag (Package, L"-sfo")) {
238 //
239 // Match UEFI Shell spec:
240 // ShellCommand,"date"
241 // Date,"DD","MM","YYYY"
242 //
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);
245 } else {
246 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DATE_FORMAT), gShellLevel2HiiHandle, TheTime.Month, TheTime.Day, TheTime.Year);
247 }
248 } else {
249 if (PcdGet8 (PcdShellSupportLevel) == 2) {
250 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"date");
251 ShellStatus = SHELL_INVALID_PARAMETER;
252 } else {
253 //
254 // perform level 3 operation here.
255 //
256 Param1 = ShellCommandLineGetRawValue (Package, 1);
257 if (Param1 == NULL) {
258 ShellStatus = SHELL_INVALID_PARAMETER;
259 } else {
260 ShellStatus = CheckAndSetDate (Param1);
261 }
262
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;
266 }
267 }
268 }
269 }
270 }
271
272 //
273 // free the command line package
274 //
276
277 //
278 // return the status
279 //
280 return (ShellStatus);
281}
282
283//
284// Note "-tz" is invalid for this (non-interactive) version of 'time'.
285//
286STATIC CONST SHELL_PARAM_ITEM TimeParamList2[] = {
287 { L"-d", TypeValue },
288 { NULL, TypeMax }
289};
290
291STATIC CONST SHELL_PARAM_ITEM TimeParamList3[] = {
292 { L"-d", TypeValue },
293 { L"-tz", TypeValue },
294 { NULL, TypeMax }
295};
296
311 IN CONST CHAR16 *TimeString,
312 IN CONST INT16 Tz,
313 IN CONST UINT8 Daylight
314 )
315{
316 EFI_TIME TheTime;
317 EFI_STATUS Status;
318 CHAR16 *TimeStringCopy;
319 CHAR16 *Walker1;
320 CHAR16 *Walker2;
321
322 if ((TimeString != NULL) && !InternalIsTimeLikeString (TimeString, L':', 1, 2, FALSE)) {
324 }
325
326 if ((Daylight != 0xFF) && ((Daylight & (EFI_TIME_IN_DAYLIGHT|EFI_TIME_ADJUST_DAYLIGHT)) != Daylight)) {
328 }
329
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);
334 }
335
336 if (TimeString != NULL) {
337 TimeStringCopy = NULL;
338 TimeStringCopy = StrnCatGrow (&TimeStringCopy, NULL, TimeString, 0);
339 Walker1 = TimeStringCopy;
340 TheTime.Hour = 0xFF;
341 TheTime.Minute = 0xFF;
342
343 Walker2 = Walker1 != NULL ? StrStr (Walker1, L":") : NULL;
344 if ((Walker2 != NULL) && (*Walker2 == L':')) {
345 *Walker2 = CHAR_NULL;
346 }
347
348 TheTime.Hour = (UINT8)ShellStrToUintn (Walker1);
349 if (Walker2 != NULL) {
350 Walker1 = Walker2 + 1;
351 }
352
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;
359 }
360
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);
367 }
368 }
369 }
370
371 SHELL_FREE_NON_NULL (TimeStringCopy);
372 }
373
374 if ((Tz >= -1440) && (Tz <= 1440)) {
375 //
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.
382 //
383 TheTime.TimeZone = -Tz;
384 } else if (Tz == EFI_UNSPECIFIED_TIMEZONE) {
385 TheTime.TimeZone = Tz;
386 }
387
388 if (Daylight != 0xFF) {
389 TheTime.Daylight = Daylight;
390 }
391
392 Status = gRT->SetTime (&TheTime);
393
394 if (!EFI_ERROR (Status)) {
395 return (SHELL_SUCCESS);
396 }
397
399}
400
408EFIAPI
410 IN EFI_HANDLE ImageHandle,
411 IN EFI_SYSTEM_TABLE *SystemTable
412 )
413{
414 EFI_STATUS Status;
415 LIST_ENTRY *Package;
416 EFI_TIME TheTime;
417 CHAR16 *ProblemParam;
418 SHELL_STATUS ShellStatus;
419 INT16 Tz;
420 UINT8 Daylight;
421 CONST CHAR16 *TempLocation;
422 UINTN TzMinutes;
423
424 //
425 // Initialize variables
426 //
427 ShellStatus = SHELL_SUCCESS;
428 ProblemParam = NULL;
429
430 //
431 // initialize the shell lib (we must be in non-auto-init...)
432 //
433 Status = ShellInitialize ();
434 ASSERT_EFI_ERROR (Status);
435
436 //
437 // parse the command line
438 //
439 if (PcdGet8 (PcdShellSupportLevel) == 2) {
440 Status = ShellCommandLineParseEx (TimeParamList2, &Package, &ProblemParam, TRUE, TRUE);
441 } else {
442 ASSERT (PcdGet8 (PcdShellSupportLevel) == 3);
443 Status = ShellCommandLineParseEx (TimeParamList3, &Package, &ProblemParam, TRUE, TRUE);
444 }
445
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;
451 } else {
452 ASSERT (FALSE);
453 }
454 } else {
455 //
456 // check for "-?"
457 //
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);
462 }
463
464 if (ShellCommandLineGetFlag (Package, L"-?")) {
465 ASSERT (FALSE);
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;
469 } else {
470 //
471 // If there are no parameters, then print the current time
472 //
473 if ( (ShellCommandLineGetRawValue (Package, 1) == NULL)
474 && !ShellCommandLineGetFlag (Package, L"-d")
475 && !ShellCommandLineGetFlag (Package, L"-tz"))
476 {
477 //
478 // ShellPrintEx the current time
479 //
480 if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {
481 TzMinutes = 0;
482 } else {
483 TzMinutes = (ABS (TheTime.TimeZone)) % 60;
484 }
485
486 if (TheTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) {
488 -1,
489 -1,
490 NULL,
491 STRING_TOKEN (STR_TIME_FORMAT),
492 gShellLevel2HiiHandle,
493 TheTime.Hour,
494 TheTime.Minute,
495 TheTime.Second,
496 (TheTime.TimeZone > 0 ? L"-" : L"+"),
497 ((ABS (TheTime.TimeZone)) / 60),
498 TzMinutes
499 );
500 } else {
502 -1,
503 -1,
504 NULL,
505 STRING_TOKEN (STR_TIME_FORMAT_LOCAL),
506 gShellLevel2HiiHandle,
507 TheTime.Hour,
508 TheTime.Minute,
509 TheTime.Second
510 );
511 }
512
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) {
517 -1,
518 -1,
519 NULL,
520 STRING_TOKEN (STR_TIME_FORMAT_LOCAL),
521 gShellLevel2HiiHandle,
522 TheTime.Hour,
523 TheTime.Minute,
524 TheTime.Second
525 );
526 } else {
527 TzMinutes = (ABS (TheTime.TimeZone)) % 60;
529 -1,
530 -1,
531 NULL,
532 STRING_TOKEN (STR_TIME_FORMAT),
533 gShellLevel2HiiHandle,
534 TheTime.Hour,
535 TheTime.Minute,
536 TheTime.Second,
537 (TheTime.TimeZone > 0 ? L"-" : L"+"),
538 ((ABS (TheTime.TimeZone)) / 60),
539 TzMinutes
540 );
541 }
542
543 switch (TheTime.Daylight) {
544 case 0:
545 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_TIME_DST0), gShellLevel2HiiHandle);
546 break;
547 case EFI_TIME_ADJUST_DAYLIGHT:
548 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_TIME_DST1), gShellLevel2HiiHandle);
549 break;
550 case EFI_TIME_IN_DAYLIGHT:
551 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_TIME_DST2), gShellLevel2HiiHandle);
552 break;
553 case EFI_TIME_IN_DAYLIGHT|EFI_TIME_ADJUST_DAYLIGHT:
554 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_TIME_DST3), gShellLevel2HiiHandle);
555 break;
556 default:
557 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_ERROR), gShellLevel2HiiHandle, L"time", L"gRT->GetTime", L"TheTime.Daylight", TheTime.Daylight);
558 }
559 } else {
560 if (PcdGet8 (PcdShellSupportLevel) == 2) {
561 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"time");
562 ShellStatus = SHELL_INVALID_PARAMETER;
563 } else {
564 //
565 // perform level 3 operation here.
566 //
567 if ((TempLocation = ShellCommandLineGetValue (Package, L"-tz")) != NULL) {
568 if (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16 *)TempLocation, L"_local") == 0) {
570 } else if (TempLocation[0] == L'-') {
571 Tz = (INT16)ShellStrToUintn (++TempLocation);
572 //
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().
575 //
576 if (Tz == -1) {
577 Tz = 1441; // make it to be out of bounds value
578 } else {
579 Tz *= (-1); // sign convert
580 }
581 } else {
582 if (TempLocation[0] == L'+') {
583 Tz = (INT16)ShellStrToUintn (++TempLocation);
584 } else {
585 Tz = (INT16)ShellStrToUintn (TempLocation);
586 }
587
588 //
589 // Detect the return of ShellStrToUintn() to make sure the argument is valid.
590 //
591 if (Tz == -1) {
592 Tz = 1441; // make it to be out of bounds value
593 }
594 }
595
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;
599 }
600 } else {
601 //
602 // intentionally out of bounds value will prevent changing it...
603 //
604 Tz = 1441;
605 }
606
607 TempLocation = ShellCommandLineGetValue (Package, L"-d");
608 if (TempLocation != NULL) {
609 Daylight = (UINT8)ShellStrToUintn (TempLocation);
610 //
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.
614 //
615 if (TempLocation[0] == '-') {
616 Daylight = 0xff; // make it invalid = will not use
617 }
618
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;
622 }
623 } else {
624 //
625 // invalid = will not use
626 //
627 Daylight = 0xFF;
628 }
629
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;
635 }
636 }
637 }
638 }
639 }
640 }
641
642 //
643 // free the command line package
644 //
646
647 //
648 // return the status
649 //
650 return (ShellStatus);
651}
652
653typedef struct {
654 INT16 TimeZone;
655 EFI_STRING_ID StringId;
657
658STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList2[] = {
659 { L"-l", TypeFlag },
660 { L"-f", TypeFlag },
661 { NULL, TypeMax }
662};
663STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList3[] = {
664 { L"-l", TypeFlag },
665 { L"-f", TypeFlag },
666 { L"-s", TypeTimeValue },
667 { NULL, TypeMax }
668};
669
670STATIC 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) }
707};
708
721 IN CONST CHAR16 *TimeZoneString
722 )
723{
724 EFI_TIME TheTime;
725 EFI_STATUS Status;
726 CHAR16 *TimeZoneCopy;
727 CHAR16 *Walker;
728 CHAR16 *Walker2;
729 UINTN LoopVar;
730
731 if (TimeZoneString == NULL) {
733 }
734
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);
740 }
741
742 TheTime.TimeZone = EFI_UNSPECIFIED_TIMEZONE;
743 Status = gRT->SetTime (&TheTime);
744 if (!EFI_ERROR (Status)) {
745 return (SHELL_SUCCESS);
746 }
747
749 }
750
751 if ((TimeZoneString != NULL) && !InternalIsTimeLikeString (TimeZoneString, L':', 1, 1, TRUE)) {
753 }
754
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);
759 }
760
761 TimeZoneCopy = NULL;
762 TimeZoneCopy = StrnCatGrow (&TimeZoneCopy, NULL, TimeZoneString, 0);
763 if (TimeZoneCopy == NULL) {
764 return (SHELL_OUT_OF_RESOURCES);
765 }
766
767 Walker = TimeZoneCopy;
768 Walker2 = StrStr (Walker, L":");
769 if ((Walker2 != NULL) && (*Walker2 == L':')) {
770 *Walker2 = CHAR_NULL;
771 }
772
773 if (*Walker == L'-') {
774 TheTime.TimeZone = (INT16)((ShellStrToUintn (++Walker)) * 60);
775 } else {
776 TheTime.TimeZone = (INT16)((INT16)(ShellStrToUintn (Walker)) * -60);
777 }
778
779 if (Walker2 != NULL) {
780 Walker = Walker2 + 1;
781 }
782
783 if ((Walker != NULL) && (Walker[0] != CHAR_NULL)) {
784 if (TheTime.TimeZone < 0) {
785 TheTime.TimeZone = (INT16)(TheTime.TimeZone - (UINT8)ShellStrToUintn (Walker));
786 } else {
787 TheTime.TimeZone = (INT16)(TheTime.TimeZone + (UINT8)ShellStrToUintn (Walker));
788 }
789 }
790
791 Status = EFI_INVALID_PARAMETER;
792
793 for ( LoopVar = 0
794 ; LoopVar < sizeof (TimeZoneList) / sizeof (TimeZoneList[0])
795 ; LoopVar++
796 )
797 {
798 if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) {
799 Status = gRT->SetTime (&TheTime);
800 break;
801 }
802 }
803
804 FreePool (TimeZoneCopy);
805
806 if (!EFI_ERROR (Status)) {
807 return (SHELL_SUCCESS);
808 }
809
811}
812
820EFIAPI
822 IN EFI_HANDLE ImageHandle,
823 IN EFI_SYSTEM_TABLE *SystemTable
824 )
825{
826 //
827 // non interactive
828 //
829 EFI_STATUS Status;
830 LIST_ENTRY *Package;
831 CHAR16 *ProblemParam;
832 SHELL_STATUS ShellStatus;
833 UINT8 LoopVar;
834 EFI_TIME TheTime;
835 BOOLEAN Found;
836 UINTN TzMinutes;
837
838 ShellStatus = SHELL_SUCCESS;
839 ProblemParam = NULL;
840
841 //
842 // initialize the shell lib (we must be in non-auto-init...)
843 //
844 Status = ShellInitialize ();
845 ASSERT_EFI_ERROR (Status);
846
847 //
848 // parse the command line
849 //
850 if (PcdGet8 (PcdShellSupportLevel) == 2) {
851 Status = ShellCommandLineParse (TimeZoneParamList2, &Package, &ProblemParam, TRUE);
852 } else {
853 ASSERT (PcdGet8 (PcdShellSupportLevel) == 3);
854 Status = ShellCommandLineParseEx (TimeZoneParamList3, &Package, &ProblemParam, TRUE, TRUE);
855 }
856
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;
862 } else {
863 ASSERT (FALSE);
864 }
865 } else {
866 //
867 // check for "-?"
868 //
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"-?")) {
873 ASSERT (FALSE);
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;
878 } else {
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;
883 } else {
884 //
885 // Set the time zone
886 //
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;
891 }
892 }
893 }
894 } else if (ShellCommandLineGetFlag (Package, L"-l")) {
895 //
896 // Print a list of all time zones
897 //
898 for ( LoopVar = 0
899 ; LoopVar < sizeof (TimeZoneList) / sizeof (TimeZoneList[0])
900 ; LoopVar++
901 )
902 {
903 ShellPrintHiiEx (-1, -1, NULL, TimeZoneList[LoopVar].StringId, gShellLevel2HiiHandle);
904 }
905 } else {
906 //
907 // Get Current Time Zone Info
908 //
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);
913 }
914
915 if (TheTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) {
916 Found = FALSE;
917 for ( LoopVar = 0
918 ; LoopVar < sizeof (TimeZoneList) / sizeof (TimeZoneList[0])
919 ; LoopVar++
920 )
921 {
922 if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) {
923 if (ShellCommandLineGetFlag (Package, L"-f")) {
924 //
925 // Print all info about current time zone
926 //
927 ShellPrintHiiEx (-1, -1, NULL, TimeZoneList[LoopVar].StringId, gShellLevel2HiiHandle);
928 } else {
929 //
930 // Print basic info only
931 //
932 TzMinutes = (ABS (TheTime.TimeZone)) % 60;
933
935 -1,
936 -1,
937 NULL,
938 STRING_TOKEN (STR_TIMEZONE_SIMPLE),
939 gShellLevel2HiiHandle,
940 (TheTime.TimeZone > 0 ? L"-" : L"+"),
941 (ABS (TheTime.TimeZone)) / 60,
942 TzMinutes
943 );
944 }
945
946 Found = TRUE;
947 break;
948 }
949 }
950
951 if (!Found) {
952 //
953 // Print basic info only
954 //
955 TzMinutes = (ABS (TheTime.TimeZone)) % 60;
956
958 -1,
959 -1,
960 NULL,
961 STRING_TOKEN (STR_TIMEZONE_SIMPLE),
962 gShellLevel2HiiHandle,
963 (TheTime.TimeZone > 0 ? L"-" : L"+"),
964 (ABS (TheTime.TimeZone)) / 60,
965 TzMinutes
966 );
967
968 if (ShellCommandLineGetFlag (Package, L"-f")) {
969 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_TIMEZONE_NI), gShellLevel2HiiHandle);
970 }
971 }
972 } else {
973 //
974 // TimeZone was EFI_UNSPECIFIED_TIMEZONE (local) from GetTime()
975 //
976 if (ShellCommandLineGetFlag (Package, L"-f")) {
977 for ( LoopVar = 0
978 ; LoopVar < ARRAY_SIZE (TimeZoneList)
979 ; LoopVar++
980 )
981 {
982 if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) {
983 //
984 // Print all info about current time zone
985 //
986 ShellPrintHiiEx (-1, -1, NULL, TimeZoneList[LoopVar].StringId, gShellLevel2HiiHandle);
987 break;
988 }
989 }
990 } else {
991 //
992 // Print basic info only
993 //
994 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_TIMEZONE_SIMPLE_LOCAL), gShellLevel2HiiHandle);
995 }
996 }
997 }
998 }
999
1000 //
1001 // free the command line package
1002 //
1004
1005 return (ShellStatus);
1006}
UINT64 UINTN
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
Definition: String.c:224
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
#define ABS(a)
Definition: Base.h:1020
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_OUT_OF_RESOURCES
Definition: Shell.h:73
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_DEVICE_ERROR
Definition: Shell.h:63
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
CONST CHAR16 *EFIAPI ShellCommandLineGetValue(IN CONST LIST_ENTRY *CheckPackage, IN CHAR16 *KeyString)
UINTN EFIAPI ShellStrToUintn(IN CONST CHAR16 *String)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
Definition: ShellLib.h:755
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellCommandLineGetFlag(IN CONST LIST_ENTRY *CONST CheckPackage, IN CONST CHAR16 *CONST KeyString)
@ TypeValue
A flag that has some data following it with a space (IE "-a 1").
Definition: ShellLib.h:700
@ TypeTimeValue
A flag that has a time value following it (IE "-a -5:00").
Definition: ShellLib.h:705
@ TypeFlag
A flag that is present or not present only (IE "-a").
Definition: ShellLib.h:699
BOOLEAN EFIAPI ShellIsDecimalDigitCharacter(IN CHAR16 Char)
Definition: UefiShellLib.c:194
SHELL_PARAM_ITEM SfoParamList[]
Helper structure for -sfo only (besides -? and -b)
Definition: UefiShellLib.c:22
CHAR16 *EFIAPI StrnCatGrow(IN OUT CHAR16 **Destination, IN OUT UINTN *CurrentSize, IN CONST CHAR16 *Source, IN UINTN Count)
EFI_STATUS EFIAPI ShellCommandLineParseEx(IN CONST SHELL_PARAM_ITEM *CheckList, OUT LIST_ENTRY **CheckPackage, OUT CHAR16 **ProblemParam OPTIONAL, IN BOOLEAN AutoPageBreak, IN BOOLEAN AlwaysAllowNumbers)
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
UINTN EFIAPI ShellCommandLineGetCount(IN CONST LIST_ENTRY *CheckPackage)
SHELL_STATUS EFIAPI ShellCommandRunTime(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: TimeDate.c:409
SHELL_STATUS EFIAPI ShellCommandRunTimeZone(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: TimeDate.c:821
SHELL_STATUS CheckAndSetTime(IN CONST CHAR16 *TimeString, IN CONST INT16 Tz, IN CONST UINT8 Daylight)
Definition: TimeDate.c:310
SHELL_STATUS CheckAndSetTimeZone(IN CONST CHAR16 *TimeZoneString)
Definition: TimeDate.c:720
SHELL_STATUS EFIAPI ShellCommandRunDate(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: TimeDate.c:177
SHELL_STATUS CheckAndSetDate(IN CONST CHAR16 *DateString)
Definition: TimeDate.c:89
BOOLEAN InternalIsTimeLikeString(IN CONST CHAR16 *String, IN CONST CHAR16 Char, IN CONST UINTN Min, IN CONST UINTN Max, IN CONST BOOLEAN MinusOk)
Definition: TimeDate.c:25
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define STRING_TOKEN(t)
#define EFI_UNSPECIFIED_TIMEZONE
Definition: UefiSpec.h:58