A better way, I don't know. Here's a different way:
setvar dt "m!hpmonth"+"d"+str("123456789ABCDEFGHIJKLMNOPQRSTUV",hpdate,1)
setvar dtw dt+"w!hpday"
if pos(dt,"m1d1m7d4m12dP")>0 or
pos(dtw,"m1d2w2m7d3w6m7d5w2m12dOw6m12dVw6")>0
setvar holiday true
elseif pmatch("m5d[P-V]w2", dtw) or pmatch("m9d[1-7]w2", dtw)
setvar holiday true
elseif pmatch("m11d[L-R]w5", dtw)
setvar holiday true
else
setvar holiday false
endif
Think job security!
More seriously, I think it's a bit easier to read and maintain if you
don't nest the IF's, but instead repeat the HPMONTH test.
Greg Stigers wrote:
> In the following, I want to set HOLIDAY to false when none of the
> conditions
> are true. I originally set it to false first, then let the tests set
> it to
> true as needed. I later decided to try moving it within the various
> tests,
> and failed. Is there a better way to do this? For instance, should I
> include
> the HPMONTH test as part of all the conditions under its test, instead of
> nesting them?
>
> #In January, test for New Year's Day and the day after on a Monday
> IF !HPMONTH = 1
> IF !HPDATE = 1
> SETVAR HOLIDAY TRUE
> #Test for Monday after New Year's Day when New Year's Day falls on Sunday
> ELSEIF !HPDATE = 2 AND !HPDAY = 2
> SETVAR HOLIDAY TRUE
> ENDIF
> #Test for Memorial Day
> ELSEIF !HPMONTH = 5 AND !HPDAY = 2 AND !HPDATE >= 25
> SETVAR HOLIDAY TRUE
> #Test for Fourth of July or Friday the 3rd or Saturday the 5th
> ELSEIF !HPMONTH = 7
> IF !HPDAY = 4
> SETVAR HOLIDAY TRUE
> #Test for Friday the 3rd of July when the Fourth is a Saturday
> ELSEIF !HPDAY = 6 AND !HPDATE = 3
> SETVAR HOLIDAY TRUE
> #Test for Monday the fifth of July when the Fourth of July is Sunday
> ELSEIF AND !HPDAY = 2 AND !HPDATE = 5
> SETVAR HOLIDAY TRUE
> ENDIF
> #Test for Labor Day, in September, Monday, of the first week
> ELSEIF !HPMONTH = 9 AND !HPDAY = 2 AND !HPDATE <= 7
> SETVAR HOLIDAY TRUE
> #Test for Thanksgiving, November, Thursday, fourth week
> ELSEIF !HPMONTH = 11 AND !HPDAY = 5 AND !HPDATE >=21 AND !HPDATE <= 27
> SETVAR HOLIDAY TRUE
> #In December: Christmas Eve, Christmas, Monday 26th & Saturday New Year's
> Eve
> ELSEIF !HPMONTH = 12
> #Test for Christmas Eve on a Friday when Christmas is a Saturday
> IF !HPDATE = 24 AND !HPDAY = 6
> SETVAR HOLIDAY TRUE
> #Test for Christmas Day
> ELSEIF !HPDATE = 25
> SETVAR HOLIDAY TRUE
> #Test for the Monday after Christmas when Christmas is on a Sunday
> ELSEIF !HPDATE = 26 AND !HPDAY = 2
> SETVAR HOLIDAY TRUE
> #Test for New Year's Eve Friday when New Year's Day falls on Saturday
> ELSEIF !HPDATE = 31 AND !HPDAY = 6
> SETVAR HOLIDAY TRUE
> ENDIF
> ELSE
> SETVAR HOLIDAY FALSE
> ENDIF
> #Show the result
> SHOWVAR HOLIDAY
>
> Greg Stigers
>
> * To join/leave the list, search archives, change list settings, *
> * etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
>
>
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|