:: check-comments.btm
::
:: Checks the current date and warns X days before
:: comments are due.
::
:: FOR TESTING you can include a date in isodate format:
:: check-comments 2016-03-29
@echo off
SETLOCAL
Set Iso_Fmt=4
Set PrepDays=1
Set PrepWarnDays=1
:: Get "today"
Set Iso_Today=%_isodate
:: *********************
:: ** Test **
:: *********************
IF "%1" NE "" Set Iso_Today=%1
:: For test purposes, if check-comments.btm is called with an
:: ISO-date parameter that date will be used instead.
:: goto TEST_SET_DATE_INFO
:: Return "theoretical" date: 1st or 15th in Comments_Due_Date
GOSUB GET_THEORETICAL_DUE_DATE
:: Calculate actual DueDate, PrepDate, and Warning Date
GOSUB CALCULATE_DATES %Comments_Due_Date
unset Comments_Due_Date
:: Check "today" against the dates, show applicable warnings
GOSUB SHOW_WARNINGS %Iso_Today
ENDLOCAL
QUIT
::******************************************************
:GET_THEORETICAL_DUE_DATE
::
:: Creates and sets Comments_Due_Date to the next
:: theoretical due date (1st or 15th) based on "today's" date.
::
:: This gets fed to the routines that calculate the actual
:: dates for warning, prep and due
::
::******************************************************
Set today_DOM=%@Day[%Iso_Today]
:: Default to 15th of THIS month
Set Comments_Due_Date=%@left[7,%Iso_Today]-15
:: If today is 1st, change to 1st
IFF %today_DOM EQ 1 THEN
Set Comments_Due_Date=%Iso_Today
ELSEIFF %today_DOM GT 15 THEN
:: If today is after the 15th
:: Add 20 days, to kick into next month
Set Comments_Due_Date=%@DatePlus[%Iso_Today,20,%Iso_Fmt]
:: Set date to 1st of next month
Set Comments_Due_Date=%@left[7,%Comments_Due_Date]-01
ENDIFF
UNSET today_DOM
RETURN
:: End of GET_THEORETICAL_DUE_DATE
::******************************************************
:CALCULATE_DATES [in_date]
::
:: Calculate actual DueDate, PrepDate, and Warning Date for
:: PrepDate. Adjust for weekends.
::
:: DueDate must be contain an isodate
::
:: Sets DueDate, PrepDate and WarnDate
::
::******************************************************
:: Starting with theoretical due date (1st or 15th) return
:: actual due date
Set DueDate=%@INLIEU[%in_date, %Iso_Fmt, 2]
:: PrepDate is 1 day before DueDate
Set PrepDate=%@DATEPLUS[%DueDate,-%PrepDays,%Iso_Fmt]
:: If PrepDate is a weekend, move to Friday
Set PrepDate=%@INLIEU[%PrepDate, %Iso_Fmt, 1]
:: WarnDate is 1 day before PrepDate
Set WarnDate=%@DATEPLUS[%PrepDate,-%PrepWarnDays,%Iso_Fmt]
:: If WarnDate is a weekend, move to Friday
Set WarnDate=%@INLIEU[%WarnDate, %Iso_Fmt, 1]
RETURN
:: End of CALCULATE_DATES
::******************************************************
:SHOW_DATE_INFO
::
:: Display DueDate, PrepDate and WarnDates
:: ONLY FOR TEST AND DEVELOPMENT
::******************************************************
Echo.
Echo Due Date: %DueDate (%@DOWF[%DueDate])
Echo Prep Date: %PrepDate (%@DOWF[%PrepDate]) (%PrepDays days)
Echo Warn Date: %WarnDate (%@DOWF[%WarnDate]) (%PrepWarnDays days)
Echo.
PAUSE
RETURN
:: End of SHOW_DATE_INFO
::******************************************************
:SHOW_WARNINGS [in_date]
::
:: in_date should always be "today" unless testing
::
:: Displays warnings for the various days.
::
::******************************************************
:: GOSUB SHOW_DATE_INFO
Set Show_Pause=Yes
COLOR BRIGHT RED ON BRIGHT WHITE
IFF %in_date EQ %WarnDate THEN
Echo.
Echo COMMENTS ARE DUE %@DateConv[%DueDate,%Iso_Fmt,17]
Echo.
Echo THEY MUST BE PREPARED ON %@DateConv[%PrepDate,%Iso_Fmt,17]
ELSEIFF %in_date EQ %PrepDate THEN
Echo.
Echo COMMENTS ARE DUE %@DateConv[%DueDate,%Iso_Fmt,17]
Echo.
Echo THEY MUST BE PREPARED TODAY %@DateConv[%PrepDate,%Iso_Fmt,17]
ELSEIFF %in_date EQ %DueDate THEN
Echo.
Echo COMMENTS ARE DUE TODAY %@DateConv[%DueDate,%Iso_Fmt,17]
ELSE
Set Show_Pause=No
ENDIFF
COLOR BLUE ON BRIGHT WHITE
IFF %Show_Pause EQ Yes THEN
Echo.
PAUSE
Echo.
ENDIFF
unset Show_Pause
RETURN
:: End of SHOW_WARNINGS [in_date]