0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

日本の祝日を判定する

0
Posted at
jpholiday.bat
@echo off

set SELF=%~n0
set FILE=%TEMP%\%SELF%.csv
set HELP=Usage: %SELF% [YYYY/mm/dd]

setlocal enabledelayedexpansion
  if "%~1" == "" (
    set v=%DATE%
  ) else (
    set v=%~1
  )
  
  (echo %v%) | findstr /r "[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]" > NUL || (
    echo %HELP% >&2
    exit /b -1
  )
  
  set y=%v:~0,4%
  set m=%v:~5,2%
  set d=%v:~8,2%
  
  for %%i in (1231 0101 0102 0103) do (
    if "%m%%d%" == "%%i" (exit /b 0)
  )
  
  if not exist "%FILE%" (
    copy NUL "%FILE%" > NUL
    for /f "tokens=1,2 delims=," %%a in ('curl -s "https://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv"') do (
      for /f "tokens=1-3 delims=/" %%i in ("%%a") do (
        set y4=%%i
        set mm=0%%j
        set dd=0%%k
        (echo !y4!/!mm:~-2!/!dd:~-2!,%%b) >> "%FILE%"
      )
    )
  )
  
  call :Z %y% %m% %d% w
  if %w% equ 0 (exit /b 0)
  if %w% equ 6 (exit /b 0)
  
  find "%y%/%m%/%d%" "%FILE%" > NUL && (exit /b 0)
  
  exit /b 1
endlocal
goto :EOF

:Z
setlocal
  set y=%1
  set m=%2
  set w=0
  
  if %m% leq 2 (
    set /a y-=1
    set /a m+=12
  )
  
  set /a w=(5*%y%/4-%y%/100+%y%/400+(26*%m%+16)/10+%3)%%7
endlocal & set %4=%w%
goto :EOF

実行結果は以下のとおりです。
jpholiday.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?