Last Friday of each month: Difference between revisions

m
use day_of_week()
(Add entry for SenseTalk)
m (use day_of_week())
Line 2,686:
 
=={{header|Phix}}==
Requires 0.8.1+ (day_of_week() is now ISO 8601 compliant, plus this now uses a new routine: day_of_week()).
<lang Phix>includeprocedure timedate.elast_day_of_month(integer y, dow)
for im=1 to 1112 do
 
integer d = days_in_month(y,m),
constant FRIDAY=5
a = dow-day_of_week(y,m,d)
 
printf(1,"%4d-%02d-%02d\n",{yeary,monthm,dayd+a-7*(a>0)})
procedure showlast(integer dow, integer doy, timedate td)
td = adjust_timedate(td,timedelta(days:=doy-1))
integer {year,month,day} = td
while day_of_week(year,month,day)!=dow do day-=1 end while
printf(1,"%4d-%02d-%02d\n",{year,month,day})
end procedure
 
procedure last_day_of_month(integer year, integer dow)
integer doy
timedate first = {year,1,1,0,0,0,0,0}
-- start by finding the 1st of the next month, less 1
for i=1 to 11 do
doy = day_of_year(year,i+1,1)-1
showlast(dow,doy,first)
end for
-- do December separately, as 1st would be next year
doy = day_of_year(year,12,31)
showlast(dow,doy,first)
end procedure
constant FRIDAY=5
last_day_of_month(2012prompt_number("Year:",{1752,9999}),FRIDAY)</lang>
{{out}}
<pre>
Year:2012
2012-01-27
2012-02-24
7,794

edits