Advertisement
GlobalAccessSoftware

utility2.bat

Jan 19th, 2024 (edited)
1,298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 9.76 KB | Software | 0 0
  1.  
  2.  
  3.   :::::::::::::::::::::
  4.  :::  RC9 Update!  :::
  5.  :::::::::::::::::::::
  6.  
  7.   ::::::::::::::::::::::::::::::::::::::::::::::::::
  8.  ::: utility2.bat custom by -JpE- 202307170943  :::
  9.  ::::::::::::::::::::::::::::::::::::::::::::::::::
  10.  :::   :::   :::   :::   /\   :::   :::   :::   :::
  11.  ::::::::::::::::::::::::::::::::::::::::::::::::::
  12.  ::: Design Notes For Day of Week as Word:      :::
  13.  ::::::::::::::::::::::::::::::::::::::::::::::::::
  14.  ::: Old Farmers Need these 3 vars to work with :::
  15.  ::: PLus the 3 tables to get dow, key, century :::
  16.  ::: ========================================== :::
  17.  ::: Last two of year / 4 + Last 2 of year +    :::
  18.  ::: Day of Month + Month code & century code   :::
  19.  ::: (for 2000 thru 2099 add 1) pre 1900 add 2  :::
  20.  ::: pre 1800 add 2 more & Divide sum by 7.     :::
  21.  ::: REMAINDER is day of the week; Sunday == 1  :::
  22.  ::::::::::::::::::::::::::::::::::::::::::::::::::
  23.  ::: This ^ Formula is Crucial In The ^ Coding! :::
  24.  ::::::::::::::::::::::::::::::::::::::::::::::::::
  25.  ::: \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ :::
  26.  ::::::::::::::::::::::::::::::::::::::::::::::::::
  27.  ::: Rev8.6.7:  NEW FEATURES AND FIXES          :::
  28.  ::: if dateToLookup string is passed in, then  :::
  29.  ::: the year must be 10 digits with this       :::
  30.  ::: NOTE: RC9 Allows years up to 2,147,483,647 :::
  31.  ::: format: date2Lookup="1923-01-09"           :::
  32.  ::: If the 2nd arg isn't sent in the call,     :::
  33.  ::: then it goes with RIGHT THIS MILLISECOND!  :::
  34.  ::::::::::::::::::::::::::::::::::::::::::::::::::
  35.  
  36.     ::::::::::::::::::::::::::::::::::::::::::::::::::
  37.    ::: JAFO: Get day of week for date as a word!  :::
  38.    ::::::::::::::::::::::::::::::::::::::::::::::::::
  39.  
  40.  
  41.     if not defined vers set vers=v8.7.0.16 20240117073112 by -JpE-
  42.     if not defined testwell set /a testwell=1
  43.     if not defined util2 set util2="%bats%\utility2.bat"
  44.     if not defined util3 set util3="%bats%\utility3.bat"
  45.  
  46.  
  47. :dowword <string weekdayVar2Return, string dateToLookupOptional>
  48.   setlocal & set "weekday=%~1" & set "date1=%~2"
  49.   if not defined date1 set /a year4=(%date:~0,4%)
  50.  
  51.       if not defined date1 call :fetch year2 month day
  52.      ::: Either or, never neither ^v nor.
  53.       if defined date1 call :parsedate %date1% year4 year2 month day
  54.       set /a ly=9 & call :monthkey key %month% %year4%
  55.  
  56.     if %key% gtr 99 set /a ly=0 & set /a key-=100
  57.    ::: REM if %ly% equ 0 echo . & echo It is LeapYear! & echo .
  58.     set /a sum1=(%year2% / 4 + %year2%)
  59.     set /a sum2=(%sum1% + %day% + %key%)
  60.       call :century %year4% adj
  61.  
  62.         ::: Mod:Fix ::: if Leap Year but before Leap Day!
  63.        ::: v8.7.0.15 20240117073112 by -JpE-
  64.         if %ly% equ 0 if %month% lss 3 set /a adj-=1
  65.  
  66.   if %adj% lss 9 set /a sum2=(%sum2%+%adj%)
  67.   if %adj% equ 9 set "weekday=Y10k Problem"
  68.   if %adj% gtr 9 set /a key=7
  69.   if %adj% neq 7 set /a dowk=(%sum2% %% 7%)
  70.  
  71.     if %key% neq 7 call :getdow %dowk% weekday
  72.       if %key% equ 7 set "weekday=ERROR-47c"
  73.         if %key% equ 7 call :errr
  74.  
  75.   endlocal & set "%~1=%weekday%"
  76.   exit /b %errorlevel%
  77.  
  78.  
  79. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  80. ::: Adapted month and day if year is more than 4 digits. -ed
  81. ::: fix Y10k, Y100k, Y100k, Y1mk, etc.
  82. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  83. ::: If date string was passed in parse it to get
  84. ::: the 4 vars year4, year2, month, day; my way.
  85. ::: Mod: if more than a 4 digit year and make scalable.
  86. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  87. :parsedate <string datePassedIn, int year4Returned, int year2Returned, int monthReturned, int dayReturned>
  88.   setlocal & set "date1=%~1" & set "y4=%~2"
  89.   set "y2=%~3" & set "mo=%~4" & set "dy=%~5"
  90.   if exist %util3% call %util3% datelen :strlen %date1%
  91.  
  92.       set /a len=(%datelen%-6)
  93.       set /a l2=(%len%-2)
  94.       set /a admo=(%len%+1)
  95.       set /a addy=(%len%+4)
  96.  
  97.   ::: How long is just the Year string in characters?
  98.   if %datelen% equ 10 (
  99.     set /a "y4=%date1:~0,4%"
  100.     set /a "y2=%date1:~2,2%"
  101.     set "mo=%date1:~5,2%"
  102.     set "dy=%date1:~8,2%"
  103.   )
  104.   if %datelen% gtr 10 (
  105.    REM setlocal EnableExtensions
  106.    REM setlocal EnableDelayedExpansion
  107.       set y4=!date1:~0,%len%!
  108.       set y2=!date1:~%l2%,2!
  109. if %testwell% gtr 3 echo . & echo now testing over 4 digit years. And l2 == %l2% & echo . & pause & echo .
  110.     set mo=!date1:~%admo%,2!
  111.     set dy=!date1:~%addy%,2!
  112.    REM setlocal DisableDelayedExpansion
  113.   )
  114. if %testwell% gtr 3 echo . & echo parsedate: y4 == %y4%, y2 == %y2%, admo == %admo%, addy == %addy%
  115. if %testwell% gtr 3 echo len == %len%, mo == %mo%, dy == %dy% & echo .
  116.   if "%mo:~0,1%" equ " " set /a "mo=%mo:~1,1%"
  117.   if "%mo:~0,1%" equ "" set /a "mo=%mo:~1,1%"
  118.   if "%mo:~0,1%" equ "0" set /a "mo=%mo:~1,1%"
  119.   if "%dy:~0,1%" equ " " set /a "dy=%dy:~1,1%"
  120.   if "%dy:~0,1%" equ "" set /a "dy=%dy:~1,1%"
  121.   if "%dy:~0,1%" equ "0" set /a "dy=%dy:~1,1%"
  122.  
  123. if %testwell% gtr 3 echo . & echo ok here: y4 == %y4%, y2 == %y2%
  124. if %testwell% gtr 3 echo mo == %mo%, dy == %dy% & echo . & pause & echo .
  125.  
  126.   endlocal & set "%~2=%y4%" & set "%~3=%y2%" & set "%~4=%mo%" & set "%~5=%dy%"
  127.   exit /b %errorlevel%
  128.  
  129.  
  130. :::::::::::::::::::[ Begin The Century Group ]:::::::::::::::::::
  131.  
  132. :century <string year4, int adjWeThink>
  133.   setlocal & set /a "yr4=%~1"
  134.   if %yr4% lss 0 echo overload & if exist %util3% call %util3% t :overload 0
  135.   if %yr4% gtr 2147483646 echo overload & if exist %util3% call %util3% t :overload 0
  136.     set /a millenium=%yr4:~0,1%
  137.     set /a century=%yr4:~1,1%
  138.    ::: IF year is over 4 digits long?
  139.       if %yr4% gtr 9999 call :y10k
  140.    ::: then alter this ^ millenium and century accordingly, same namespace.
  141.     set /a evenm=(%millenium% %% 2%)
  142.     set /a evenc=(%century% %% 2%)
  143.   if %century% gtr 7 set /a century=(%century%-8)
  144.   if %century% lss 8 if %century% gtr 3 set /a century=(%century%-4)
  145.   if %evenm% leq 0 (
  146.     if %century% equ 3 set /a adj=0
  147.     if %century% equ 2 set /a adj=2
  148.     if %century% equ 1 set /a adj=4
  149.     if %century% equ 0 set /a adj=-1)
  150.   if %evenm% gtr 0 (
  151.     if %century% equ 3 set /a adj=4
  152.     if %century% equ 2 set /a adj=-1
  153.     if %century% equ 1 set /a adj=0
  154.     if %century% equ 0 set /a adj=2)
  155.   if %yr4% lss 1753 set /a adjust=9 & echo . & echo Results for years before 1753 weren't gregorian.
  156.   if %yr4% leq 6000 if %yr4% gtr 2100 call :crosscheck
  157.  REM if %yr4% leq 6000 if %yr4% gtr 2100 if %testwell% gtr 0 call :crosscheck
  158. if %testwell% gtr 3  echo done1 and adj == %adj% & echo . & pause & echo .
  159.   endlocal & set "%~2=%adj%"
  160.   exit /b %errorlevel%
  161.  
  162.  
  163. ::: In this case, yr4 is not the lookup it is just the YEAR.
  164. ::: Handles years up to 2,147,483,647 A.D.
  165. :y10k
  166. if %testwell% gtr 3 echo inside y10k now. & pause
  167.   if %yr4% gtr 2147483000 echo Uh Oh!
  168.  
  169.     ::: NEAR FATAL Error x2! Begin Again fixes it fine! :::
  170.     if %yr4% gtr 2147483646 echo overload & if exist %util3% call %util3% t :overload 0
  171.     if %yr4% leq 0 echo overload & if exist %util3% call %util3% t :overload 0
  172. :::
  173.   if exist %util3% call %util3% lenstr :strlen %yr4%
  174. if %testwell% gtr 3 echo .& echo y10k: The length of %yr4% is %lenstr%. & echo .
  175. REM & pause & echo .
  176.   set /a m2=(%lenstr%-3)
  177. if %testwell% gtr 3 echo y10k pause, lenstr == %lenstr%, and m2 == %m2% & echo . & pause
  178.  REM setlocal EnableExtensions
  179.    REM setlocal EnableDelayedExpansion
  180.       set /a millenium=(!yr4:~0,%m2%!)
  181.       set /a century=(!yr4:~%m2%,1!)
  182.    REM setlocal DisableDelayedExpansion
  183.  REM setlocal DisableExtensions
  184. if %testwell% gtr 3 echo . & echo Y0k: millenium == %millenium%, century == %century% & echo . & pause & echo .
  185.   exit /b %errorlevel%
  186.  
  187.  
  188. :crosscheck
  189.   set crosschecker="%bats%\crosschecker.bat"
  190.   if exist %crosschecker% call %crosschecker%
  191.   echo . & echo This checks out.
  192.   exit /b %errorlevel%
  193.  
  194. :::::::::::::::::::[ End of The Century Group ]:::::::::::::::::::
  195.  
  196.  
  197. :monthkey <int keyReturned, int monthNum, int year>
  198.   setlocal & set /a num=%~2 & set /a year=%~3
  199.   if %num% equ 1 set /a key=1
  200.   if %num% equ 2 set /a key=4
  201.   if %num% equ 3 set /a key=4
  202.   if %num% equ 4 set /a key=0
  203.   if %num% equ 5 set /a key=2
  204.   if %num% equ 6 set /a key=5
  205.   if %num% equ 7 set /a key=0
  206.   if %num% equ 8 set /a key=3
  207.   if %num% equ 9 set /a key=6
  208.   if %num% equ 10 set /a key=1
  209.   if %num% equ 11 set /a key=4
  210.   if %num% equ 12 set /a key=6
  211.     set /a mod=%year:~0,4% %% 4%
  212.      ::: Code it in as + a hundred if it's leapyear! :::
  213.       if %mod% equ 0 set /a key+=100
  214.   endlocal & set "%~1=%key%"
  215.   exit /b %errorlevel%
  216.  
  217.  
  218. ::: Get day of week word from day number.
  219. :getdow <int weekdayNum, string weekday2Return>
  220.   setlocal & set /a "dow=%~1"
  221.   if %dow% equ 0 set /a dow=7
  222.   if %dow% equ 1 set weekday=Sunday
  223.   if %dow% equ 2 set weekday=Monday
  224.   if %dow% equ 3 set weekday=Tuesday
  225.   if %dow% equ 4 set weekday=Wednesday
  226.   if %dow% equ 5 set weekday=Thursday
  227.   if %dow% equ 6 set weekday=Friday
  228.   if %dow% equ 7 set weekday=Saturday
  229.   endlocal & set "%~2=%weekday%"
  230.   exit /b %errorlevel%
  231.  
  232.  
  233. :fetch <int yearLast2, int monthNum, int dayOfMonth>
  234.   setlocal
  235.   set /a yearLast2=(%date:~2,2%)
  236.   set "monthNum=%date:~5,2%"
  237.   if "%monthNum:~0,1%" equ " " set /a monthNum=(%monthNum:~1,1%)
  238.   if "%monthNum:~0,1%" equ "0" set /a monthNum=(%monthNum:~1,1%)
  239.   set "dayOfMonth=%date:~8,2%"
  240.   if "%dayOfMonth:~0,1%" equ " " set /a dayOfMonth=(%dayOfMonth:~1,1%)
  241.   if "%dayOfMonth:~0,1%" equ "0" set /a dayOfMonth=(%dayOfMonth:~1,1%)
  242.   endlocal & set "%~1=%yearLast2%" & set "%~2=%monthNum%" & set "%~3=%dayOfMonth%"
  243.   exit /b %errorlevel%
  244.  
  245.  
  246. :errr
  247.   setlocal
  248.   echo . & echo Developmental CheckPoint!
  249.   echo Enviromental Pollution. & echo .
  250.   echo Something peculiar is amiss?
  251.   echo . & pause & echo .
  252.   endlocal
  253.   exit /b %errorlevel%
  254.  
  255.  
  256.  
  257.   ::: 100% -JpE-
  258.  
  259.  
  260.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement