Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1999 Intel Corporation
  3. Module Name:
  4. date.c
  5. Abstract:
  6. Revision History
  7. --*/
  8. #include "shell.h"
  9. EFI_STATUS
  10. InitializeDate (
  11. IN EFI_HANDLE ImageHandle,
  12. IN EFI_SYSTEM_TABLE *SystemTable
  13. );
  14. EFI_DRIVER_ENTRY_POINT(InitializeDate)
  15. EFI_STATUS
  16. InitializeDate (
  17. IN EFI_HANDLE ImageHandle,
  18. IN EFI_SYSTEM_TABLE *SystemTable
  19. )
  20. /*+++
  21. date [mm/dd/yyyy]
  22. --*/
  23. {
  24. EFI_STATUS Status;
  25. EFI_TIME Time;
  26. CHAR16 *DateString;
  27. UINT32 i;
  28. InstallInternalShellCommand (
  29. ImageHandle, SystemTable, InitializeDate,
  30. L"date", /* command */
  31. L"date [mm/dd/yyyy]", /* command syntax */
  32. L"Get or set date", /* 1 line descriptor */
  33. NULL /* command help page */
  34. );
  35. InitializeShellApplication (ImageHandle, SystemTable);
  36. if (SI->Argc > 2) {
  37. Print(L"date [mm/dd/yyyy]\n");
  38. return EFI_SUCCESS;
  39. }
  40. if (SI->Argc == 1) {
  41. Status = RT->GetTime(&Time,NULL);
  42. if (!EFI_ERROR(Status)) {
  43. Print(L"%02d/%02d/%04d\n",Time.Month,Time.Day,Time.Year);
  44. }
  45. return EFI_SUCCESS;
  46. }
  47. if (StrCmp(SI->Argv[1],L"/?") == 0) {
  48. Print(L"date [mm/dd/yyyy]\n");
  49. return EFI_SUCCESS;
  50. }
  51. if (StrCmp(SI->Argv[1],L"/h") == 0) {
  52. Print(L"date [mm/dd/yyyy]\n");
  53. return EFI_SUCCESS;
  54. }
  55. Status = RT->GetTime(&Time,NULL);
  56. if (EFI_ERROR(Status)) {
  57. Print(L"error : Clock not functional\n");
  58. return Status;
  59. }
  60. DateString = SI->Argv[1];
  61. Time.Month = (UINT8)Atoi(DateString);
  62. if (Time.Month<1 || Time.Month>12) {
  63. Print(L"error : invalid month\n");
  64. return EFI_INVALID_PARAMETER;
  65. }
  66. for(i=0;i<StrLen(DateString) && DateString[i]!='/';i++);
  67. if (DateString[i]=='/') {
  68. i++;
  69. Time.Day = (UINT8)Atoi(&(DateString[i]));
  70. if (Time.Day<1 || Time.Day>31) {
  71. Print(L"error : invalid day\n");
  72. return EFI_INVALID_PARAMETER;
  73. }
  74. for(;i<StrLen(DateString) && DateString[i]!='/';i++);
  75. if (DateString[i]=='/') {
  76. i++;
  77. Time.Year = (UINT16)Atoi(&(DateString[i]));
  78. if (Time.Year<100) {
  79. Time.Year = Time.Year + 1900;
  80. if (Time.Year < 1998) {
  81. Time.Year = Time.Year + 100;
  82. }
  83. }
  84. if (Time.Year < 1998) {
  85. Print(L"error : invalid year\n");
  86. return EFI_INVALID_PARAMETER;
  87. }
  88. Status = RT->SetTime(&Time);
  89. if (EFI_ERROR(Status)) {
  90. Print(L"error : Clock not functional\n");
  91. return Status;
  92. }
  93. return EFI_SUCCESS;
  94. }
  95. }
  96. Print(L"error : invalid date format\n");
  97. return EFI_INVALID_PARAMETER;
  98. }