Anonymous user
Last Friday of each month: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments, used a template for the output section.
m (→{{header|Factor}}: update to Factor 0.98) |
m (→{{header|REXX}}: added/changed whitespace and comments, used a template for the output section.) |
||
Line 3,227:
The documentation for the '''lastDOW''' function (used in the REXX program below):
╔════════════════════════════════════════════════════════════════════╗
║ lastDOW: procedure to return the date of the last day─of─week of ║
Line 3,254:
║ then obtained straightforwardly, or via subtraction. ║
╚════════════════════════════════════════════════════════════════════╝
<lang rexx>/*REXX program displays the dates of the last Fridays of each month for any given year.*/
parse arg yyyy /*obtain optional argument from the CL.*/
do j=1 for 12 /*traipse through all the year's months*/
say lastDOW('Friday', j, yyyy) /*find last Friday for the Jth month.*/
end /*j*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
lastDOW: procedure; arg dow .,mm .,yy .; parse arg a.1,a.2,a.3
if mm=='' | mm=='*' then mm= left( date('U'), 2)
if yy=='' | yy=='*' then yy= left( date('S'), 4)
if length(yy)==2 then yy= left( date('S'), 2)yy
/*Note mandatory leading blank in strings below*/
$=" Monday TUesday Wednesday THursday Friday SAturday SUnday"
!=" JAnuary February MARch APril MAY JUNe JULy AUgust September October November December"
upper $ ! /*uppercase strings*/
if dow=='' then call .er "wasn't specified", 1 /*no month given ? */
if arg()>3 then call .er 'arguments specified', 4 /*too many args ? */
do j=1 for 3 /*any plural args ?*/
if words( arg(j) ) > 1
end
dw= pos(' 'dow, $) /*find day-of-week*/
if
if m\==lastpos(' 'mm,!) then call .er 'is ambiguous:', 2
end
▲ m=pos(' 'mm,!) /*maybe its good...*/
▲ if m==0 then call .er 'is invalid:',1
▲ if m\==lastpos(' 'mm,!) then call .er 'is ambigious:',2
if \datatype(mm, 'W')
if \datatype(yy, 'W')
if mm<1 | mm>12
if yy=0
if yy<0
if yy>9999
tdow= wordpos( word( substr($, dw), 1), $) -
/*day# of last dom.*/
_= date('B', right(yy + (mm=12), 4)right(mm // 12 + 1, 2, 0)"01", 'S') - 1
?= _ // 7
if ?\==tdow then _= _ - ? - 7 + tdow + 7 * (?>tdow)
return date('weekday', _, "B") date(, _, 'B') /*return the answer*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
.er: arg ,_; say; say '***error*** (in LASTDOW)';
say word('day-of-week month year excess', arg(2)) arg(1) a._ /*plug in a choice.*/
say; exit 13
<pre>
Friday 27 Jan 2012
|