Last Friday of each month: Difference between revisions

Line 89:
intercalate(linefeed, ¬
map(ISODateisoRow, ¬
lastWeekDaysOfYeartranspose(2012map(lastFridaysOfYear, Friday asrange(2012, integer2016)))))
end run
 
-- DERIVATION OF LAST FRIDAYS
 
-- lastFridaysOfYear :: Int -> [Date]
on lastFridaysOfYear(y)
lastWeekDaysOfYear(y, Friday as integer)
end lastFridaysOfYear
 
 
-- lastWeekDaysOfYear :: Int -> Int -> [Date]
on lastWeekDaysOfYear(intYear, iWeekDayiWeekday)
map(mClosure(my lastWeekDay, ¬
{intYear:intYear, iWeekDayiWeekday:iWeekDayiWeekday}), my lastDaysOfMonths(intYear))
end lastWeekDaysOfYear
 
 
-- lastWeekDay :: iLastDay,Int iMonth-> Int -> Date
on lastWeekDay(iLastDay, iMonth)
set iYear to intYear of my closure
Line 110 ⟶ 115:
calendarDate(iYear, iMonth, iLastDay - ¬
(((weekday of calendarDate(iYear, iMonth, iLastDay)) as integer) + ¬
(7 - (iWeekDayiWeekday of my closure))) mod 7)
end lastWeekDay
 
Line 124 ⟶ 129:
{31, iFeb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
end lastDaysOfMonths
 
 
 
-- GENERIC FUNCTIONS
 
-- Dates and date strings
 
-- calendarDate :: Int -> Int -> Int -> Date
on calendarDate(intYear, intMonth, intDay)
tell (current date)
set {its year, its month, its day, its time} to {intYear, intMonth, intDay, 0}¬
{intYear, intMonth, intDay, 0}
return it
end tell
end calendarDate
 
-- ISODateisoDateString :: Date -> String
on ISODateisoDateString(dte)
(((year of dte) as string) & ¬
"-" & text items -2 thru -1 of ¬
Line 144 ⟶ 151:
"-" & text items -2 thru -1 of ¬
("0" & day of dte)
end ISODateisoDateString
 
-- Testing and tabulation
 
-- transpose :: [[a]] -> [[a]]
on transpose(xss)
script mf
on lambdaCol(_, iCol)
map(mClosure(my closure's mf's lambdaRow, ¬
{iCol:iCol}), my closure's xss)
end lambdaCol
on lambdaRow(row)
item (my closure's iCol) of row
end lambdaRow
end script
map(mClosure(mf's lambdaCol, {xss:xss, mf:mf}), item 1 of xss)
end transpose
 
-- intercalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
set {dlm, my text item delimiters} to {my text item delimiters, strText}¬
{my text item delimiters, strText}
set strJoined to lstText as text
set my text item delimiters to dlm
return strJoined
end intercalate
 
-- isoRow :: [Date] -> String
on isoRow(lstDate)
intercalate(tab, map(my isoDateString, lstDate))
end isoRow
 
-- range :: Int -> Int -> [Int]
on range(m, n)
set lng to (n - m) + 1
set base to m - 1
set lst to {}
repeat with i from 1 to lng
set end of lst to i + base
end repeat
return lst
end range
 
 
Line 163 ⟶ 204:
set lst to {}
repeat with i from 1 to lng
set end of lst to mf's lambda(item i of xs, i, xs) of mf
end repeat
return lst
Line 188 ⟶ 229:
{{Out}}
 
<pre>2012-01-27 2013-01-25 2014-01-31 2015-01-30 2016-01-29
2012-02-24 2013-02-22 2014-02-28 2015-02-27 2016-02-26
2012-02-24
2012-03-30 2013-03-29 2014-03-28 2015-03-27 2016-03-25
2012-03-30
2012-04-27 2013-04-26 2014-04-25 2015-04-24 2016-04-29
2012-04-27
2012-05-25 2013-05-31 2014-05-30 2015-05-29 2016-05-27
2012-05-25
2012-06-29 2013-06-28 2014-06-27 2015-06-26 2016-06-24
2012-06-29
2012-07-27 2013-07-26 2014-07-25 2015-07-31 2016-07-29
2012-07-27
2012-08-31 2013-08-30 2014-08-29 2015-08-28 2016-08-26
2012-08-31
2012-09-28 2013-09-27 2014-09-26 2015-09-25 2016-09-30
2012-09-28
2012-10-26 2013-10-25 2014-10-31 2015-10-30 2016-10-28
2012-10-26
2012-11-30 2013-11-29 2014-11-28 2015-11-27 2016-11-25
2012-11-30
2012-12-28 2013-12-27 2014-12-26 2015-12-25 2016-12-30</pre>
 
=={{header|AutoHotkey}}==
9,659

edits