Last Friday of each month: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 367: Line 367:
"2012-11-30"
"2012-11-30"
"2012-12-28")</pre>
"2012-12-28")</pre>

=={{header|COBOL}}==
<lang COBOL>
program-id. last-fri.
data division.
working-storage section.
1 wk-date.
2 yr pic 9999.
2 mo pic 99 value 1.
2 da pic 99 value 1.
1 rd-date redefines wk-date pic 9(8).
1 binary.
2 int-date pic 9(8).
2 dow pic 9(4).
2 friday pic 9(4) value 5.
procedure division.
display "Enter a calendar year (1601 thru 9999): "
with no advancing
accept yr
if yr >= 1601 and <= 9999
continue
else
display "Invalid year"
stop run
end-if
perform 12 times
move 1 to da
add 1 to mo
if mo > 12 *> to avoid y10k in 9999
move 12 to mo
move 31 to da
end-if
compute int-date = function
integer-of-date (rd-date)
if mo =12 and da = 31 *> to avoid y10k in 9999
continue
else
subtract 1 from int-date
end-if
compute rd-date = function
date-of-integer (int-date)
compute dow = function mod
((int-date - 1) 7) + 1
compute dow = function mod ((dow - friday) 7)
subtract dow from da
display yr "-" mo "-" da
add 1 to mo
end-perform
stop run
.
end program last-fri.
</lang>

{{out}}
<pre>
2016-01-29
2016-02-26
2016-03-25
2016-04-29
2016-05-27
2016-06-24
2016-07-29
2016-08-26
2016-09-30
2016-10-28
2016-11-25
2016-12-30
</pre>


=={{header|CoffeeScript}}==
=={{header|CoffeeScript}}==