%META:TOPICINFO{author="ChrisBartram" date="1149890711" format="1.1" version="1.1"}% %META:TOPICPARENT{name="Hp3000DateXeqs"}%
parm m="0",v=""

######################################################
##  MONTH [parm1][,parm2]
##
##  This command file returns dates equal to the
##  first day and last day of a requested month in
##  the following formats:
##
##  FIRST DAY -
##       dayf = mmddyy
##       dayf1 = mmddyyyy
##       dayf2 = mm/dd/yy
##       dayf3 = mmm dd, yyyy
##       dayf4 = (day-of-week), mmm dd, yyyy
##
##  LAST DAY -
##       dayl = mmddyy
##       dayl1 = mmddyyyy
##       dayl2 = mm/dd/yy
##       dayl3 = mmm dd, yyyy
##       dayl4 = (day-of-week), mmm dd, yyyy
##
##  MISCELLANEOUS -
##       month = mmm
##       dayfl = mmddyyyymmddyyyy (Concatenated 1st
##               and last days of the month.)
##
##  PARM1 -
##  An offset may be entered as the 1st parm of the
##  command filename.  A positive integer is entered
##  for a future month. A negative integer is entered
##  for a past month.  The range of allowable values
##  is -12 to 12.  The default is 0 for the current
##  month.
##
##  PARM2 -
##  A string may be entered as the 2nd parm of the
##  command filename.  the string is concatenated
##  to the variable names used to return the format-
##  ted dates to the caller.  The string must begin
##  with an alpha character and be no more than 3
##  characters in length.  The default is a null
##  string.
##
##  EXAMPLES -
##     MONTH ,C     Current month is returned in var-
##                  iables beginning with the letter
##                  C (i.e., CDAYF, CDAYL, etc.).
##     MONTH 4,M04  A month 4 months into the future
##                  is returned in variables beginning
##                  with the string M04 (i.e.,
##                  M04DAYF, M04DAYF1, etc.).
##
##  This command file may be executed within a UDC,
##  a job stream or interactively to define formatted
##  date variables in the user's environment to be
##  used in report generation, job scheduling or any-
##  where else a formatted date may be required.
##
##  Written by: Steve Barrett
##     Created: 03/23/92
##    Modified: 03/24/92, 03/25/92, 05/29/92
######################################################

##  CHECK THE VALIDITY OF THE PARAMETER INPUTS.

if "!m" <> "0"
 if len("!m") > 1
      setvar t1 str("!m",1,1)
      if ("!t1" <> "+") and ("!t1" <> "-")
           if numeric("!t1") = FALSE
                echo PARM1 IS NOT AN INTEGER VALUE.
                deletevar t1
                return
           endif
           setvar t1 str("!m",2,(len("!m")-1))
           if numeric("!t1") = FALSE
                echo PARM1 IS NOT AN INTEGER VALUE.
                deletevar t1
                return
           endif
      deletevar t1
      endif
 endif
 if len("!m") = 1
      if ("!m" = "+") or ("!m" = "-") or (numeric("!m") = FALSE)
           echo PARM1 IS NOT AN INTEGER VALUE.
           return
      endif
 endif
endif
if (!m > 12) or (!m < -12)
 echo PARM1 IS NOT IN THE ACCEPTABLE RANGE (-12 to 12).
 return
endif
if "!v" <> ""
 if (len("!v") > 3) or (alpha((str("!v",1,1))) = FALSE)
      echo PARM2 IS GREATER THAN 3 CHARACTERS IN LENGTH.
      echo OR, PARM2 DOES NOT BEGIN WITH AN ALPHA CHARACTER.
      return
 endif
 if len("!v") > 1
      if alphanum(str("!v",2,(len("!v")-1))) = FALSE
           echo PARM2 IS NOT ALPHANUMERIC.
           return
      endif
 endif
endif

##  DEFINE VARIABLES.

setvar dyf "!v"+"dayf"
setvar dyf1 "!v"+"dayf1"
setvar dyf2 "!v"+"dayf2"
setvar dyf3 "!v"+"dayf3"
setvar dyf4 "!v"+"dayf4"
setvar dyl "!v"+"dayl"
setvar dyl1 "!v"+"dayl1"
setvar dyl2 "!v"+"dayl2"
setvar dyl3 "!v"+"dayl3"
setvar dyl4 "!v"+"dayl4"
setvar mnth "!v"+"month"
setvar dyfl "!v"+"dayfl"
setvar mo (!hpmonth + !m)
setvar yr !hpyear
setvar year (!yr + 1900)
if !yr < 50
 setvar year (!yr + 2000)
endif
setvar leapyes "312931303130313130313031"
setvar leapno "312831303130313130313031"
setvar months "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"
setvar wkday "SUNMONTUEWEDTHUFRISAT"
setvar wdleapy "034025036146"
setvar wdleapn "144025036146"

##  INCREMENT OR DECREMENT THE MONTH.

if !mo <= 0
 setvar mo (!mo + 12)
 setvar year (!year - 1)
endif
if !mo > 12
 setvar mo (!mo - 12)
 setvar year (!year + 1)
endif
setvar nodays "!leapno"
if (!year mod 4) = 0
 setvar nodays "!leapyes"
endif
setvar day str(nodays,(!mo*2-1),2)
if !mo < 10
 setvar mo "0"+"!mo"
endif

##  CALCULATE THE DAY OF THE WEEK.

setvar yr str("!year",3,2)
setvar century str("!year",1,2)
setvar wday wdleapn
if (!year mod 4) = 0
 setvar wday wdleapy
endif
setvar dv str(wday,!mo,1)
setvar ldayval (!yr/4)+!yr+!dv+!day
setvar fdayval (!yr/4)+!yr+!dv+1
if !century = 20
 setvar ldayval (!ldayval - 1)
 setvar fdayval (!fdayval - 1)
endif
setvar ldayval (!ldayval mod 7)
setvar fdayval (!fdayval mod 7)
if !ldayval = 0
 setvar ldayval 7
endif
if !fdayval = 0
 setvar fdayval 7
endif
setvar ldaywk str(wkday,(!ldayval*3-2),3)
setvar fdaywk str(wkday,(!fdayval*3-2),3)
setvar mon str(months,(!mo*3-2),3)

##  DEFINE THE VARIABLES TO BE RETURNED TO THE CALLER.

setvar !dyl "!mo"+"!day"+"!yr"
setvar !dyl1 "!mo"+"!day"+"!year"
setvar !dyl2 "!mo"+"/"+"!day"+"/"+"!yr"
setvar !dyl3 "!mon"+" "+"!day"+", "+"!year"
setvar !dyl4 " "+"!ldaywk"+", "+"!mon"+" "+"!day"+", "+"!year"
setvar !dyf "!mo"+"01"+"!yr"
setvar !dyf1 "!mo"+"01"+"!year"
setvar !dyf2 "!mo"+"/"+"01"+"/"+"!yr"
setvar !dyf3 "!mon"+" "+"01"+", "+"!year"
setvar !dyf4 " "+"!fdaywk"+", "+"!mon"+" "+"01"+", "+"!year"
setvar !dyfl "!mo"+"01"+"!year"+"!mo"+"!day"+"!year"
setvar !mnth "!mon"

##  CLEAN UP THE ENVIRONMENT.

deletevar mo,day,yr,year,ldaywk,fdaywk,months,wkday,ldayval,dv,wday
deletevar fdayval,wdleapy,wdleapn,century,leapyes,leapno,nodays
deletevar dyl,dyl1,dyl2,dyl3,dyl4,dyf,dyf1,dyf2,dyf3,dyf4,dyfl,mnth

-- Main.ChrisBartram - 09 Jun 2006