Last Friday of each month: Difference between revisions

Content added Content deleted
Line 2,905: Line 2,905:
=={{header|Pascal}}==
=={{header|Pascal}}==
{{works with|Free Pascal}}
{{works with|Free Pascal}}
Using the DateUtils library included with Free Pascal would simplify the coding (see the Delphi example) but for older Pascal implementations the needed routines are the programmer's responsibility!
Using Free Pascal's DateUtils library would dramatically simplify the coding (see the Delphi example) but for older Pascal implementations the needed routines are the programmer's responsibility.
<lang Pascal>
<lang Pascal>
program LastFriday;
program LastFriday;
Line 2,973: Line 2,973:
d := DaysInMonth(m, y);
d := DaysInMonth(m, y);
w := DayOfWeek(m, d, y);
w := DayOfWeek(m, d, y);
{ find immediately prior occurance of weekday k }
{ back up as needed to desired weekday }
if w >= k then
if w >= k then
d := d - (ord(w) - ord(k))
LastWeekday := d - (ord(w) - ord(k))
else
else
d := d - (7 - ord(k)) - ord(w);
LastWeekday := d - (7 - ord(k)) - ord(w);
LastWeekday := d;
end;
end;