Anonymous user
Last Friday of each month: Difference between revisions
→{{header|Ruby}}: Use d -= (d.wday - 5) % 7
m (→{{header|C}}: remove leftover) |
(→{{header|Ruby}}: Use d -= (d.wday - 5) % 7) |
||
Line 331:
def last_friday(year, month)
# Find end of month = beginning of month + 1 month - 1 day.
d -= (d.wday - 5) % 7 # Subtract days after Friday.
end
year = Integer(ARGV.shift)
(1..12).each {|month| puts last_friday(year, month)}</lang>
Friday is <code>d.wday == 5</code>; the expression <code>(d.wday - 5) % 7</code> counts days after Friday.
{{libheader|ActiveSupport}}
|