Last active
August 29, 2015 14:02
Revisions
-
aetos382 revised this gist
Jun 13, 2014 . No changes.There are no files selected for viewing
-
aetos382 revised this gist
Jun 13, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -50,13 +50,13 @@ for /f "tokens=1,2,3 delims=/" %%i in ("%today%") do ( ) rem 日が 1 より大きければ、日を 1 減らして終了 if %day% GTR 1 ( set /a day -= 1 goto :RESULT ) rem 月が 1 より大きければ、月を 1 減らして末日をセットして終了 if %month% GTR 1 ( set /a month -= 1 call :GET_LAST goto :RESULT -
aetos382 revised this gist
Jun 13, 2014 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,6 +26,10 @@ rem 400 で割り切れる年は閏年 call :GET_YESTERDAY "2000/03/01" if "%result%" == "2000/02/29" (echo OK) else (echo NG) rem 月日は 1 桁で指定しても大丈夫 call :GET_YESTERDAY "2014/6/9" if "%result%" == "2014/06/08" (echo OK) else (echo NG) exit /b :GET_YESTERDAY -
aetos382 revised this gist
Jun 13, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ rem 4 で割り切れて 100 で割り切れない年は閏年 call :GET_YESTERDAY "2012/03/01" if "%result%" == "2012/02/29" (echo OK) else (echo NG) rem 100 で割り切れて 400 で割り切れない年は閏年じゃない call :GET_YESTERDAY "2100/03/01" if "%result%" == "2100/02/28" (echo OK) else (echo NG) -
aetos382 revised this gist
Jun 13, 2014 . 1 changed file with 45 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,42 @@ @echo off rem テスト rem 何でもない日 call :GET_YESTERDAY "2014/06/13" if "%result%" == "2014/06/12" (echo OK) else (echo NG) rem 1 月以外の月初日 call :GET_YESTERDAY "2014/06/01" if "%result%" == "2014/05/31" (echo OK) else (echo NG) rem 1 月 1 日 call :GET_YESTERDAY "2014/01/01" if "%result%" == "2013/12/31" (echo OK) else (echo NG) rem 4 で割り切れて 100 で割り切れない年は閏年 call :GET_YESTERDAY "2012/03/01" if "%result%" == "2012/02/29" (echo OK) else (echo NG) rem 100 で割り切れる年は閏年じゃない call :GET_YESTERDAY "2100/03/01" if "%result%" == "2100/02/28" (echo OK) else (echo NG) rem 400 で割り切れる年は閏年 call :GET_YESTERDAY "2000/03/01" if "%result%" == "2000/02/29" (echo OK) else (echo NG) exit /b :GET_YESTERDAY rem 指定日の前日を求める関数 setlocal set today=%~1 rem デフォルト値は今日 if "%today%" == "" set today=%date% rem / 区切りで分割する for /f "tokens=1,2,3 delims=/" %%i in ("%today%") do ( @@ -36,14 +69,16 @@ rem 月と日が 1 桁ならば前に 0 を補う if "%month:~1,1%" == "" set month=0%month% if "%day:~1,1%" == "" set day=0%day% rem 結果をセット endlocal & set result=%year%/%month%/%day% exit /b :GET_LAST rem 末日を求める関数 setlocal for /f "tokens=%month% delims=," %%i in ("31,28,31,30,31,30,31,31,30,31,30,31") do set day=%%i rem 2 月でなければ閏年の計算はしない @@ -57,11 +92,13 @@ rem 4 で割り切れない年は閏年ではない if %remainder1% NEQ 0 GOTO :GET_LAST_EXIT rem 100 で割り切れる年は、400 で割り切れないならば閏年ではない if %remainder2% EQU 0 (if %remainder3% NEQ 0 GOTO :GET_LAST_EXIT) rem 日付に 1 を足す set /a day += 1 :GET_LAST_EXIT endlocal & set day=%day% exit /b -
aetos382 revised this gist
Jun 13, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -46,13 +46,13 @@ exit /b rem 末日を求める関数 for /f "tokens=%month% delims=," %%i in ("31,28,31,30,31,30,31,31,30,31,30,31") do set day=%%i rem 2 月でなければ閏年の計算はしない if %month% NEQ 2 GOTO :GET_LAST_EXIT set /a remainder1=%year% %% 4 set /a remainder2=%year% %% 100 set /a remainder3=%year% %% 400 rem 4 で割り切れない年は閏年ではない if %remainder1% NEQ 0 GOTO :GET_LAST_EXIT -
aetos382 revised this gist
Jun 13, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,10 +32,12 @@ call :GET_LAST :RESULT rem 月と日が 1 桁ならば前に 0 を補う if "%month:~1,1%" == "" set month=0%month% if "%day:~1,1%" == "" set day=0%day% rem 結果表示 echo YESTERDAY = %year%/%month%/%day% exit /b -
aetos382 created this gist
Jun 13, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ @echo on set today=%date% rem コメントアウトを外して、好きな日付に設定してテストしてね rem set today=2000/03/01 rem / 区切りで分割する for /f "tokens=1,2,3 delims=/" %%i in ("%today%") do ( set year=%%i set month=%%j set day=%%k ) rem 日が 1 より大きければ、日を 1 減らして終了 if %day% gtr 1 ( set /a day -= 1 goto :RESULT ) rem 月が 1 より大きければ、月を 1 減らして末日をセットして終了 if %month% gtr 1 ( set /a month -= 1 call :GET_LAST goto :RESULT ) rem 年を 1 減らして末日を求める set /a year -= 1 set month=12 call :GET_LAST :RESULT if "%month:~1,1%" == "" set month=0%month% if "%day:~1,1%" == "" set day=0%day% echo %year%/%month%/%day% exit /b :GET_LAST rem 末日を求める関数 for /f "tokens=%month% delims=," %%i in ("31,28,31,30,31,30,31,31,30,31,30,31") do set day=%%i set /a remainder1=%year% %% 4 set /a remainder2=%year% %% 100 set /a remainder3=%year% %% 400 rem 2 月でなければ閏年の計算はしない if %month% NEQ 2 GOTO :GET_LAST_EXIT rem 4 で割り切れない年は閏年ではない if %remainder1% NEQ 0 GOTO :GET_LAST_EXIT rem 100 で割り切れる年は、400 で割り切れないならば閏年ではない if %remainder2% EQU 0 if %remainder3% NEQ 0 GOTO :GET_LAST_EXIT rem 日付に 1 を足す set /a day += 1 :GET_LAST_EXIT exit /b