Last Friday of each month: Difference between revisions
Content added Content deleted
(→{{header|Wren}}: Oops, wrong import.) |
(Changed algorithm to work with version 1.4 of Nim.) |
||
Line 2,502: | Line 2,502: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
<lang nim>import |
<lang nim>import os, strutils, times |
||
const |
|||
var timeinfo = getLocalTime getTime() |
|||
DaysInMonth: array[Month, int] = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] |
|||
⚫ | |||
DayDiffs: array[WeekDay, int] = [3, 4, 5, 6, 0, 1, 2] |
|||
⚫ | |||
timeinfo.month = month |
|||
⚫ | |||
for day in countdown(31, 1): |
|||
timeinfo.monthday = day |
|||
⚫ | |||
let t = getLocalTime(timeInfoToTime timeinfo) |
|||
var lastDay = DaysInMonth[month] |
|||
if t.month == month and t.weekday == dFri: |
|||
if month == mFeb and year.isLeapYear: lastDay = 29 |
|||
⚫ | |||
var date = initDateTime(lastDay, month, year, 0, 0, 0) |
|||
break</lang> |
|||
date = date - days(DayDiffs[date.weekday]) |
|||
⚫ | |||
⚫ | |||
<pre>./lastfriday 2012 |
|||
{{out}} |
|||
⚫ | |||
<pre> |
|||
2012-01-27 |
2012-01-27 |
||
2012-02-24 |
2012-02-24 |