Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :::::::::::::::::::::
- ::: RC9 Update! :::
- :::::::::::::::::::::
- ::::::::::::::::::::::::::::::::::::::::::::::::::
- ::: utility2.bat custom by -JpE- 202307170943 :::
- ::::::::::::::::::::::::::::::::::::::::::::::::::
- ::: ::: ::: ::: /\ ::: ::: ::: :::
- ::::::::::::::::::::::::::::::::::::::::::::::::::
- ::: Design Notes For Day of Week as Word: :::
- ::::::::::::::::::::::::::::::::::::::::::::::::::
- ::: Old Farmers Need these 3 vars to work with :::
- ::: PLus the 3 tables to get dow, key, century :::
- ::: ========================================== :::
- ::: Last two of year / 4 + Last 2 of year + :::
- ::: Day of Month + Month code & century code :::
- ::: (for 2000 thru 2099 add 1) pre 1900 add 2 :::
- ::: pre 1800 add 2 more & Divide sum by 7. :::
- ::: REMAINDER is day of the week; Sunday == 1 :::
- ::::::::::::::::::::::::::::::::::::::::::::::::::
- ::: This ^ Formula is Crucial In The ^ Coding! :::
- ::::::::::::::::::::::::::::::::::::::::::::::::::
- ::: \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ :::
- ::::::::::::::::::::::::::::::::::::::::::::::::::
- ::: Rev8.6.7: NEW FEATURES AND FIXES :::
- ::: if dateToLookup string is passed in, then :::
- ::: the year must be 10 digits with this :::
- ::: NOTE: RC9 Allows years up to 2,147,483,647 :::
- ::: format: date2Lookup="1923-01-09" :::
- ::: If the 2nd arg isn't sent in the call, :::
- ::: then it goes with RIGHT THIS MILLISECOND! :::
- ::::::::::::::::::::::::::::::::::::::::::::::::::
- ::::::::::::::::::::::::::::::::::::::::::::::::::
- ::: JAFO: Get day of week for date as a word! :::
- ::::::::::::::::::::::::::::::::::::::::::::::::::
- if not defined vers set vers=v8.7.0.16 20240117073112 by -JpE-
- if not defined testwell set /a testwell=1
- if not defined util2 set util2="%bats%\utility2.bat"
- if not defined util3 set util3="%bats%\utility3.bat"
- :dowword <string weekdayVar2Return, string dateToLookupOptional>
- setlocal & set "weekday=%~1" & set "date1=%~2"
- if not defined date1 set /a year4=(%date:~0,4%)
- if not defined date1 call :fetch year2 month day
- ::: Either or, never neither ^v nor.
- if defined date1 call :parsedate %date1% year4 year2 month day
- set /a ly=9 & call :monthkey key %month% %year4%
- if %key% gtr 99 set /a ly=0 & set /a key-=100
- ::: REM if %ly% equ 0 echo . & echo It is LeapYear! & echo .
- set /a sum1=(%year2% / 4 + %year2%)
- set /a sum2=(%sum1% + %day% + %key%)
- call :century %year4% adj
- ::: Mod:Fix ::: if Leap Year but before Leap Day!
- ::: v8.7.0.15 20240117073112 by -JpE-
- if %ly% equ 0 if %month% lss 3 set /a adj-=1
- if %adj% lss 9 set /a sum2=(%sum2%+%adj%)
- if %adj% equ 9 set "weekday=Y10k Problem"
- if %adj% gtr 9 set /a key=7
- if %adj% neq 7 set /a dowk=(%sum2% %% 7%)
- if %key% neq 7 call :getdow %dowk% weekday
- if %key% equ 7 set "weekday=ERROR-47c"
- if %key% equ 7 call :errr
- endlocal & set "%~1=%weekday%"
- exit /b %errorlevel%
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- ::: Adapted month and day if year is more than 4 digits. -ed
- ::: fix Y10k, Y100k, Y100k, Y1mk, etc.
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- ::: If date string was passed in parse it to get
- ::: the 4 vars year4, year2, month, day; my way.
- ::: Mod: if more than a 4 digit year and make scalable.
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- :parsedate <string datePassedIn, int year4Returned, int year2Returned, int monthReturned, int dayReturned>
- setlocal & set "date1=%~1" & set "y4=%~2"
- set "y2=%~3" & set "mo=%~4" & set "dy=%~5"
- if exist %util3% call %util3% datelen :strlen %date1%
- set /a len=(%datelen%-6)
- set /a l2=(%len%-2)
- set /a admo=(%len%+1)
- set /a addy=(%len%+4)
- ::: How long is just the Year string in characters?
- if %datelen% equ 10 (
- set /a "y4=%date1:~0,4%"
- set /a "y2=%date1:~2,2%"
- set "mo=%date1:~5,2%"
- set "dy=%date1:~8,2%"
- )
- if %datelen% gtr 10 (
- REM setlocal EnableExtensions
- REM setlocal EnableDelayedExpansion
- set y4=!date1:~0,%len%!
- set y2=!date1:~%l2%,2!
- if %testwell% gtr 3 echo . & echo now testing over 4 digit years. And l2 == %l2% & echo . & pause & echo .
- set mo=!date1:~%admo%,2!
- set dy=!date1:~%addy%,2!
- REM setlocal DisableDelayedExpansion
- )
- if %testwell% gtr 3 echo . & echo parsedate: y4 == %y4%, y2 == %y2%, admo == %admo%, addy == %addy%
- if %testwell% gtr 3 echo len == %len%, mo == %mo%, dy == %dy% & echo .
- if "%mo:~0,1%" equ " " set /a "mo=%mo:~1,1%"
- if "%mo:~0,1%" equ "" set /a "mo=%mo:~1,1%"
- if "%mo:~0,1%" equ "0" set /a "mo=%mo:~1,1%"
- if "%dy:~0,1%" equ " " set /a "dy=%dy:~1,1%"
- if "%dy:~0,1%" equ "" set /a "dy=%dy:~1,1%"
- if "%dy:~0,1%" equ "0" set /a "dy=%dy:~1,1%"
- if %testwell% gtr 3 echo . & echo ok here: y4 == %y4%, y2 == %y2%
- if %testwell% gtr 3 echo mo == %mo%, dy == %dy% & echo . & pause & echo .
- endlocal & set "%~2=%y4%" & set "%~3=%y2%" & set "%~4=%mo%" & set "%~5=%dy%"
- exit /b %errorlevel%
- :::::::::::::::::::[ Begin The Century Group ]:::::::::::::::::::
- :century <string year4, int adjWeThink>
- setlocal & set /a "yr4=%~1"
- if %yr4% lss 0 echo overload & if exist %util3% call %util3% t :overload 0
- if %yr4% gtr 2147483646 echo overload & if exist %util3% call %util3% t :overload 0
- set /a millenium=%yr4:~0,1%
- set /a century=%yr4:~1,1%
- ::: IF year is over 4 digits long?
- if %yr4% gtr 9999 call :y10k
- ::: then alter this ^ millenium and century accordingly, same namespace.
- set /a evenm=(%millenium% %% 2%)
- set /a evenc=(%century% %% 2%)
- if %century% gtr 7 set /a century=(%century%-8)
- if %century% lss 8 if %century% gtr 3 set /a century=(%century%-4)
- if %evenm% leq 0 (
- if %century% equ 3 set /a adj=0
- if %century% equ 2 set /a adj=2
- if %century% equ 1 set /a adj=4
- if %century% equ 0 set /a adj=-1)
- if %evenm% gtr 0 (
- if %century% equ 3 set /a adj=4
- if %century% equ 2 set /a adj=-1
- if %century% equ 1 set /a adj=0
- if %century% equ 0 set /a adj=2)
- if %yr4% lss 1753 set /a adjust=9 & echo . & echo Results for years before 1753 weren't gregorian.
- if %yr4% leq 6000 if %yr4% gtr 2100 call :crosscheck
- REM if %yr4% leq 6000 if %yr4% gtr 2100 if %testwell% gtr 0 call :crosscheck
- if %testwell% gtr 3 echo done1 and adj == %adj% & echo . & pause & echo .
- endlocal & set "%~2=%adj%"
- exit /b %errorlevel%
- ::: In this case, yr4 is not the lookup it is just the YEAR.
- ::: Handles years up to 2,147,483,647 A.D.
- :y10k
- if %testwell% gtr 3 echo inside y10k now. & pause
- if %yr4% gtr 2147483000 echo Uh Oh!
- ::: NEAR FATAL Error x2! Begin Again fixes it fine! :::
- if %yr4% gtr 2147483646 echo overload & if exist %util3% call %util3% t :overload 0
- if %yr4% leq 0 echo overload & if exist %util3% call %util3% t :overload 0
- :::
- if exist %util3% call %util3% lenstr :strlen %yr4%
- if %testwell% gtr 3 echo .& echo y10k: The length of %yr4% is %lenstr%. & echo .
- REM & pause & echo .
- set /a m2=(%lenstr%-3)
- if %testwell% gtr 3 echo y10k pause, lenstr == %lenstr%, and m2 == %m2% & echo . & pause
- REM setlocal EnableExtensions
- REM setlocal EnableDelayedExpansion
- set /a millenium=(!yr4:~0,%m2%!)
- set /a century=(!yr4:~%m2%,1!)
- REM setlocal DisableDelayedExpansion
- REM setlocal DisableExtensions
- if %testwell% gtr 3 echo . & echo Y0k: millenium == %millenium%, century == %century% & echo . & pause & echo .
- exit /b %errorlevel%
- :crosscheck
- set crosschecker="%bats%\crosschecker.bat"
- if exist %crosschecker% call %crosschecker%
- echo . & echo This checks out.
- exit /b %errorlevel%
- :::::::::::::::::::[ End of The Century Group ]:::::::::::::::::::
- :monthkey <int keyReturned, int monthNum, int year>
- setlocal & set /a num=%~2 & set /a year=%~3
- if %num% equ 1 set /a key=1
- if %num% equ 2 set /a key=4
- if %num% equ 3 set /a key=4
- if %num% equ 4 set /a key=0
- if %num% equ 5 set /a key=2
- if %num% equ 6 set /a key=5
- if %num% equ 7 set /a key=0
- if %num% equ 8 set /a key=3
- if %num% equ 9 set /a key=6
- if %num% equ 10 set /a key=1
- if %num% equ 11 set /a key=4
- if %num% equ 12 set /a key=6
- set /a mod=%year:~0,4% %% 4%
- ::: Code it in as + a hundred if it's leapyear! :::
- if %mod% equ 0 set /a key+=100
- endlocal & set "%~1=%key%"
- exit /b %errorlevel%
- ::: Get day of week word from day number.
- :getdow <int weekdayNum, string weekday2Return>
- setlocal & set /a "dow=%~1"
- if %dow% equ 0 set /a dow=7
- if %dow% equ 1 set weekday=Sunday
- if %dow% equ 2 set weekday=Monday
- if %dow% equ 3 set weekday=Tuesday
- if %dow% equ 4 set weekday=Wednesday
- if %dow% equ 5 set weekday=Thursday
- if %dow% equ 6 set weekday=Friday
- if %dow% equ 7 set weekday=Saturday
- endlocal & set "%~2=%weekday%"
- exit /b %errorlevel%
- :fetch <int yearLast2, int monthNum, int dayOfMonth>
- setlocal
- set /a yearLast2=(%date:~2,2%)
- set "monthNum=%date:~5,2%"
- if "%monthNum:~0,1%" equ " " set /a monthNum=(%monthNum:~1,1%)
- if "%monthNum:~0,1%" equ "0" set /a monthNum=(%monthNum:~1,1%)
- set "dayOfMonth=%date:~8,2%"
- if "%dayOfMonth:~0,1%" equ " " set /a dayOfMonth=(%dayOfMonth:~1,1%)
- if "%dayOfMonth:~0,1%" equ "0" set /a dayOfMonth=(%dayOfMonth:~1,1%)
- endlocal & set "%~1=%yearLast2%" & set "%~2=%monthNum%" & set "%~3=%dayOfMonth%"
- exit /b %errorlevel%
- :errr
- setlocal
- echo . & echo Developmental CheckPoint!
- echo Enviromental Pollution. & echo .
- echo Something peculiar is amiss?
- echo . & pause & echo .
- endlocal
- exit /b %errorlevel%
- ::: 100% -JpE-
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement