Here is the "holiday" function. The "tomorrow", "realdays" and "workdays"
functions will follow, as will the tester command-file. (Don't worry, the
others will be shorter).
Anyone who wants to is welcome to post them on their web sites, translate to
other languages, etc, as long as they give credit to me and to MMfab.
:print holiday.func.shr;page=0
option nolist
parm CCYYMMDD = ""
if bound (HOL_ERRORS) or bound (HOL_DOW)
deletevar HOL_@
endif
setvar HOL_ERRORS 0
if "!CCYYMMDD" = ""
setvar HOL_CYMD HPYYYYMMDD
setvar HOL_DOW !HPDAY
if HOL_CYMD <> HPYYYYMMDD
# If the date has changed, we just hit midnite and the
# day-of-week we just set might be the new day; in this
# case set the date & day-of-week again, and we should
# be ok (unless the following 2 commands take 24 hours :)
setvar HOL_CYMD HPYYYYMMDD
setvar HOL_DOW !HPDAY
endif
else
setvar HOL_CYMD "!CCYYMMDD"
if not numeric (HOL_CYMD)
echo **date parm, if entered, must be numeric**
setvar HOL_ERRORS HOL_ERRORS + 1
endif
if len (HOL_CYMD) <> 8
echo **date parm must be exactly 8 digits, unless omitted**
setvar HOL_ERRORS HOL_ERRORS + 1
elseif numeric (HOL_CYMD)
if rht (HOL_CYMD, 2) > "31"
echo **last 2 digits of date parm can't be more than 31**
setvar HOL_ERRORS HOL_ERRORS + 1
elseif rht (HOL_CYMD, 2) = "00"
echo **last 2 digits of date parm can't be "00"**
setvar HOL_ERRORS HOL_ERRORS + 1
endif
if str (HOL_CYMD, 5, 2) > "12"
echo **bytes 5 & 6 of date parm can't be more than 12**
setvar HOL_ERRORS HOL_ERRORS + 1
elseif str (HOL_CYMD, 5, 2) = "00"
echo **characters 5 & 6 of date parm can't be "00"**
setvar HOL_ERRORS HOL_ERRORS + 1
endif
endif
if HOL_ERRORS > 0
echo **exiting because the date-parm was not a valid**
echo **8-digit date in yyyymmdd format **
setvar HOL_MSG "*ERROR*"
return FALSE
endif
endif
setvar HOL_YYYY str (HOL_CYMD, 1, 4)
setvar HOL_MM str (HOL_CYMD, 5, 2)
setvar HOL_DD str (HOL_CYMD, 7, 2)
#
# Set day of week, unless already set because processing "today"
#
if not bound (HOL_DOW)
# Day-of-week with my adaption of a "Zeller" formula
# off the internet.
if HOL_MM < "03"
setvar HOL_ZMONTH !HOL_MM + 12
setvar HOL_ZYEAR !HOL_YYYY - 1
else
setvar HOL_ZMONTH !HOL_MM
setvar HOL_ZYEAR !HOL_YYYY
endif
setvar HOL_DOW ( &
((13 * HOL_ZMONTH + 3) / 5) + !HOL_DD + HOL_ZYEAR &
+ (HOL_ZYEAR/4) - (HOL_ZYEAR/100) + (HOL_ZYEAR/400) &
+ 1 ) mod 7 + 1
deletevar HOL_Z@
endif
# -------------------------------------------------------
# Do not casually modify above here.
#
# Set up any special / unofficial holidays here,
# OK to replace any dates that are past with the date of a
# holiday the company just announced (Jewish new year,
# days before / after Christmas & New Years, etc, etc).
if HOL_CYMD="20090703" or HOL_CYMD="20090928" &
or HOL_CYMD="20081226" or HOL_CYMD="20090102"
setvar HOL_MSG "Special company holiday :)"
return TRUE
endif
if HOL_CYMD >= "20091228" and HOL_CYMD <= "20091231"
setvar HOL_MSG "Mandatory X-mas vacation"
return TRUE
endif
# Do not casually modify below here, except to set company
# policy on which holidays you actually get.
# -------------------------------------------------------
#
# Now check for specific regular holidays, month-by-month.
setvar HOL_MSG ""
if HOL_MM = "01"
if HOL_DD = "01"
setvar HOL_MSG "New Years Day"
return TRUE
endif
if ( !HOL_DOW=2 and !HOL_DD>=15 and !HOL_DD<=21 )
setvar HOL_MSG "Martin Luther King day - do we get it?"
# return TRUE
endif
return FALSE
elseif HOL_MM = "02"
if (!HOL_DOW=2 and !HOL_DD>=15 and !HOL_DD<=21)
setvar HOL_MSG "President's Day"
return TRUE
endif
return FALSE
elseif HOL_MM = "05"
if (!HOL_DOW=2 and !HOL_DD>=25 and !HOL_DD<=31)
setvar HOL_MSG "Memorial Day"
return TRUE
endif
return FALSE
elseif HOL_MM = "07"
if HOL_DD = "04"
setvar HOL_MSG "July 4th"
return TRUE
endif
return FALSE
elseif HOL_MM = "09"
if ( !HOL_DOW=2 and !HOL_DD>=1 and !HOL_DD<=7 )
setvar HOL_MSG "Labor Day"
return TRUE
endif
return FALSE
elseif HOL_MM = "11"
if HOL_DD = "11"
setvar HOL_MSG "Veterans Day - but do we get it ?"
# return TRUE
endif
if ( !HOL_DOW=5 and !HOL_DD>=22 and !HOL_DD<=28 )
setvar HOL_MSG "Thanksgiving"
return TRUE
endif
if ( !HOL_DOW=6 and !HOL_DD>=23 and !HOL_DD<=29 )
setvar HOL_MSG "The day after Thanksgiving"
return TRUE
endif
return FALSE
elseif HOL_MM = "12"
if HOL_DD = "25"
setvar HOL_MSG "Christmas"
return TRUE
endif
return FALSE
endif
# showvar HOL_@
return FALSE
# Function "holiday" to return 'TRUE' on company holidays
# Dave Powell, MMfab, Inc 05/12/2009
#
# Logic adapted from the "datetest" command file
# posted by Tracy Pierce on the HP-3000L on 09/26/2002
#
# Leftover variables:
# - HOL_CYMD the 8-digit date it checked (string type).
# - HOL_YYYY 4-digit year
# - HOL_MM 2-digit month
# - HOL_DD 2-digit day (these 3 are also string type
# - HOL_DOW day-of-week (Sun=1, etc -- use this one)
# - HOL_ERRORS numeric
# - HOL_MSG Name of the holiday it thinks it is, or
# "" (or "*ERROR*")
#
# Holidays that it currently has the fine-print for (some are
# commented out)
# - New Years Day Jan 1
# - Martin Luther King Day Jan, Mon between day 15 & 21
# - President's Day Feb, Mon 15 & 21
# - Memorial Day May, Mon 25 & 31
# - Independence Day Jul 4
# - Labor Day Sep, Mon 1 & 7
# - Veterans Day Nov 11
# - Thanksgiving Day Nov, Thu 22 / 28
# - "indigestion day" Nov, Fri 23 / 29
# - Christmas Dec 25
#
# Does not check for Easter because its hard, and because our
# separate Sunday logic means we will always know its a day off.
#
#
# Syntax: if holiday () then <checks today>
# calc holiday (20090511)
# if holiday ("20090511") then
# calc holiday (SomeDateVariable)
# etc
#
# Sample company logic:
# setvar WORKDAY not (HPDAY=1 or HPDAY=7 or HOLIDAY())
# (for a company that does not work Saturdays)
#
# or
# setvar OFFDAY HPDAY=1 or HOLIDAY()
# setvar WORKDAY HPDAY<>7 and not OFFDAY
# setvar MAYBEDAY HPDAY=7 and not OFFDAY
# <do every-day-including-Sunday-&-holiday stuff>
# if not OFFDAY
# <do whatever we want on Saturday but not on offdays>
# if WORKDAY
# <do the work-day-only stuff>
# endif
# endif
# (for a company that sometimes has a few people in
# Saturday morning, so it's not a regular work day or
# a complete day off).
#
# Variable-naming convention:
# - 'DD', "MM", "YYYY" etc mean string variables with the
# length you might guess from the name.
# - "DOW", 'DAY', "YEAR", "MONTH" mean integer-type variables.
#
# Changes / "improvements" in this file over original "datetest"
# - Function syntax, so you can say
# if holiday() then
# instead of
# xeq datetest
# if IForgetTheVariableName = WhatWasThatValue then
# - Separate "if"s for each holiday, to make it easier to
# turn them on or off depending on your site's policies.
# - Then turns off some holidays I don't I think I can
# count on MMfab always taking.
# - It sets a variable to the name of whatever holiday it
# thinks it is, to make debugging easier.
# - Has a spot to put in extra / unofficial days off when
# the company announces them (like the day before / after
# Christmas).
# - Returns true if the holiday falls on a Saturday or Sunday.
# - Midnite protection.
# - Checks that the date is numeric, with plausible month & day
# (does not check that the day is too high for that month)
# - More readable ?
# - Improved day-of-week calculation.
# Downgrades:
# - Won't try to guess the century -- cannot handle 6-digit
# input.
#
#
# All input errors return "FALSE" on the assumption that the
# programmer, at least, can't take a holiday until he fixes
# the bug :)
#
# --------------------------------------------------
# See also: WORKDAYS.FUNC.SHR, TOMORROW.FUNC.SHR
# HOLITEST.TESTCMD.SHR, REALDAYS.FUNC.SHR
#
#
# --------------------------------------------------
# --------------------------------------------------
#
# Day-of-Week note:
# The 3 methods mostly agree, but 12-25-2100 is a Sunday
# according to method 1, but a Saturday according to methods
# 2 & 3. Babwani's modified 2007 date-calc spreadsheet also
# says Sat. Method 2 is the HOL_X@ variables, 3 uses [log in to unmask]
#
# ------------------------------------------------------------
# Alternate day-of-week calculations:
# below are the original 3 versions of the DOW calc, and
# the code to compare and bitch if they gave different results:
#
## # 1st, the method in the original "datetest" command file
# setvar HOL_DOW str("000031059090120151181212243273304334", &
# !HOL_MM * 3 - 2, 3)
# setvar HOL_DOW !HOL_DOW + !HOL_DD
# if !HOL_MM > 2 and ( !HOL_YYYY / 4 * 4 = !HOL_YYYY )
# setvar HOL_DOW HOL_DOW + 1
# endif
# setvar HOL_YWK !HOL_YYYY - 1
# setvar HOL_DOW !HOL_DOW + ( !HOL_YWK / 400 ) * 146097
# setvar HOL_YWK !HOL_YWK mod 400
# setvar HOL_DOW !HOL_DOW + ( !HOL_YWK / 100 ) * 36524
# setvar HOL_YWK !HOL_YWK mod 100
# setvar HOL_DOW !HOL_DOW + ( !HOL_YWK / 4 ) * 1461
# setvar HOL_YWK !HOL_YWK mod 4
# setvar HOL_DOW !HOL_DOW + ( !HOL_YWK * 365 )
# setvar HOL_DOW ( HOL_DOW mod 7 ) + 1
# deletevar HOL_YWK
#
## # Next, the method posted to the 3000-l by Mike Hornsby 06/04/2004
## # except, add 1 at the end because his was 0-6 and we need
## # 1-7.
# setvar HOL_XYR !HOL_YYYY-((12-!HOL_MM)/10)
# setvar HOL_XMONTH !HOL_MM+(((12-!HOL_MM)/10)*12)
# setvar HOL_XDAY !HOL_DD+(!HOL_XMONTH*2)+(((!HOL_XMONTH+1)*6)/10)
# setvar HOL_XLEAP_YR (HOL_XYR/4) - (HOL_XYR/100) + (HOL_XYR/400)
# setvar HOL_XDAY (HOL_XDAY+HOL_XYR+HOL_XLEAP_YR+1) mod 7 + 1
#
## # Next, day-of-week with my adaption of a "Zeller" formula
## # off the internet.
# if HOL_MM < "03"
# setvar HOL_ZMONTH !HOL_MM + 12
# setvar HOL_ZYEAR !HOL_YYYY - 1
# else
# setvar HOL_ZMONTH !HOL_MM
# setvar HOL_ZYEAR !HOL_YYYY
# endif
# setvar HOL_ZDAY ( &
# ((13 * HOL_ZMONTH + 3) / 5) + !HOL_DD + HOL_ZYEAR &
# + (HOL_ZYEAR/4) - (HOL_ZYEAR/100) + (HOL_ZYEAR/400) &
# + 1 ) mod 7 + 1
#
## # Now, see if the day-of-week calcs agree
# if HOL_DOW <> HOL_XDAY &
# or HOL_DOW <> HOL_ZDAY &
# or HOL_ZDAY <> HOL_XDAY
# setvar HOL_ERRORS HOL_ERRORS + 1
# echo **day-of-week error**
# echo HOL_DOW = !HOL_DOW
# echo HOL_XDAY = !HOL_XDAY
# echo HOL_ZDAY = !HOL_ZDAY
# endif
# setvar HOL_DOW HOL_ZDAY
# setvar HOL_DAY HOL_DOW
# deletevar HOL_X@, HOL_Z@
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|