Anonymous user
Last Friday of each month: Difference between revisions
Changed algorithm to work with version 1.4 of Nim.
(→{{header|Wren}}: Oops, wrong import.) |
(Changed algorithm to work with version 1.4 of Nim.) |
||
Line 2,502:
=={{header|Nim}}==
<lang nim>import
const
DaysInMonth: array[Month, int] = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
timeinfo.year = paramStr(1).parseInt▼
DayDiffs: array[WeekDay, int] = [3, 4, 5, 6, 0, 1, 2]
for month in mJan .. mDec:▼
var lastDay = DaysInMonth[month]
if month == mFeb and year.isLeapYear: lastDay = 29
echo t.format "yyyy-MM-dd"▼
var date = initDateTime(lastDay, month, year, 0, 0, 0)
date = date - days(DayDiffs[date.weekday])
Sample usage:▼
{{out}}
▲Sample usage: ./lastfriday 2012
<pre>
2012-01-27
2012-02-24
|