Last Friday of each month: Difference between revisions

Add Seed7 example
(Add Seed7 example)
Line 1,044:
2012-Nov-30
2012-Dez-28</pre>
 
=={{header|Seed7}}==
Uses the libraries [http://seed7.sourceforge.net/libraries/time.htm time.s7i] and
[http://seed7.sourceforge.net/libraries/duration.htm duration.s7i].
Applicable to any day of the week, cf. [[http://rosettacode.org/wiki/Find_last_sunday_of_each_month#Seed7]].
 
<lang seed7>$ include "seed7_05.s7i";
include "time.s7i";
include "duration.s7i";
 
const proc: main is func
local
var integer: weekday is 1; # 1 for monday, 2 for tuesday, and so on up to 7 for sunday.
var integer: year is 0;
var integer: month is 1;
var time: aDate is time.value;
var time: selected is time.value;
begin
if length(argv(PROGRAM)) <> 2 then
writeln("usage: lastWeekdayInMonth weekday year");
writeln(" weekday: 1 for monday, 2 for tuesday, and so on up to 7 for sunday.");
else
weekday := integer parse (argv(PROGRAM)[1]);
year := integer parse (argv(PROGRAM)[2]);
for month range 1 to 12 do
aDate := date(year, month, 1);
while aDate.month = month do
if dayOfWeek(aDate) = weekday then
selected := aDate;
end if;
aDate +:= 1 . DAYS;
end while;
writeln(strDate(selected));
end for;
end if;
end func;</lang>
 
Output when called with <tt>s7 rosetta/lastWeekdayInMonth 5 2013</tt>:
<pre>
2013-01-25
2013-02-22
2013-03-29
2013-04-26
2013-05-31
2013-06-28
2013-07-26
2013-08-30
2013-09-27
2013-10-25
2013-11-29
2013-12-27
</pre>
 
=={{header|Tcl}}==