Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for stardate.bat

(view source code of stardate.bat as plain text)

  1. @ECHO OFF
  2. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  3. IF NOT  "%~1"==""           GOTO Syntax
  4. WMIC.EXE /? > NUL  2>&1 ||  GOTO Syntax
  5.  
  6. SETLOCAL ENABLEDELAYEDEXPANSION
  7. FOR /F "tokens=1* delims==" %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:list') DO (
  8. 	IF NOT "%%~B"=="" (
  9. 		FOR /F %%C IN ("%%~B") DO (
  10. 			SET %%~A=%%~C
  11. 		)
  12. 	)
  13. )
  14.  
  15. CALL :LeapYear
  16. CALL :DayOfYear
  17.  
  18. IF %Year% GEQ 2323 (
  19. 	SET /A "YY = %Year% - 2323"
  20. 	SET ERA=
  21. ) ELSE (
  22. 	SET /A "YY = 2323 - %Year%"
  23. 	SET ERA= BW ^(Before Warp^)
  24. )
  25. SET /A "DDD = ( %DayOfYear%000 + 182 ) / 365"
  26. SET /A "T   = ( %Hour% * 60 + %Minute% + 72 ) / 144"
  27. SET /A "SD  = %YY% * 1000 + %DDD%"
  28.  
  29. SET StarDate=%SD%.%T%%ERA%
  30. SET StarDate
  31. ENDLOCAL & SET StarDate=%StarDate%
  32. GOTO:EOF
  33.  
  34.  
  35. :DayOfYear
  36. :: Fill array with cumulative number of days of past months
  37. SET /A DaysPast.1  = 0
  38. SET /A DaysPast.2  = %DaysPast.1%  + 31
  39. SET /A DaysPast.3  = %DaysPast.2%  + 28 + %LeapYear%
  40. SET /A DaysPast.4  = %DaysPast.3%  + 31
  41. SET /A DaysPast.5  = %DaysPast.4%  + 30
  42. SET /A DaysPast.6  = %DaysPast.5%  + 31
  43. SET /A DaysPast.7  = %DaysPast.6%  + 30
  44. SET /A DaysPast.8  = %DaysPast.7%  + 31
  45. SET /A DaysPast.9  = %DaysPast.8%  + 31
  46. SET /A DaysPast.10 = %DaysPast.9%  + 30
  47. SET /A DaysPast.11 = %DaysPast.10% + 31
  48. SET /A DaysPast.12 = %DaysPast.11% + 30
  49. SET /A DayOfYear   = !DaysPast.%Month%! + %Day%
  50. GOTO:EOF
  51.  
  52.  
  53. :LeapYear
  54. SET LeapYear=0
  55. SET /A "Test = %Year% %% 4"
  56. IF %Test% EQU 0 SET LeapYear=1
  57. SET /A "Test = %Year% %% 100"
  58. IF %Test% EQU 0 SET LeapYear=0
  59. SET /A "Test = %Year% %% 400"
  60. IF %Test% EQU 0 SET LeapYear=1
  61. GOTO:EOF
  62.  
  63.  
  64. :Syntax
  65. ECHO.
  66. ECHO StarDate.bat,  Version 2.00 for Windows XP Professional and later
  67. ECHO Display the current StarDate and save its value in a variable
  68. ECHO.
  69. ECHO Usage:  STARDATE
  70. ECHO.
  71. ECHO Notes:  Requires WMIC (Windows XP Professional an later).
  72. ECHO         Result is saved in environment variable %%StarDate%%.
  73. ECHO         Based on an algorithm found at The Star Trek Gallery:
  74. ECHO         http://www.trainerscity.com/startrek/stardate.php
  75. ECHO.
  76. ECHO Written by Rob van der Woude
  77. ECHO http://www.robvanderwoude.com
  78.  
  79. IF "%OS%"=="Windows_NT" EXIT /B 1
  80.  

page last modified: 2024-04-16; loaded in 0.0084 seconds