Find the last Sunday of each month: Difference between revisions

Line 48:
 
 
<lang AppleScript>on run argv
-- Default range in absence of arguments: from two years ago, to two years ahead
-- Up to two optional command line arguments: [yearFrom], [yearTo]
-- ~ $ osascript ~/Desktop/lastSundays.scpt
--
-- ~ $ osascript ~/Desktop/lastSundays.scpt 2013
--
-- ~ $ osascript ~/Desktop/lastSundays.scpt 2013 2016
set intThisYear to year of (current date)
if class of argv is list then
set lngArgs to length of argv
if lngArgs > 0 then
if lngArgs > 1 then
set {intFrom, intTo} to argv
end lambdaCol else
set intYear to item 1 of argv
set {intFrom, intTo} to {intYear, intYear}
end lambdaRowif
else
set {intFrom, intTo} to {intThisYear - 2, intThisYear + 2}
end scriptif
else
set {intFrom, intTo} to {intThisYear - 2, intThisYear + 2}
end if
intercalate(linefeed, ¬
map(isoRow, ¬
transpose(map(lastSundaysOfYear, range(2012intFrom, 2016intTo)))))
end run
 
-- DERIVATION OF LAST SundaysSUNDAYS
 
-- lastSundaysOfYear :: Int -> [Date]
Line 91 ⟶ 119:
{31, iFeb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
end lastDaysOfMonths
 
 
-- GENERIC FUNCTIONS
Line 116 ⟶ 145:
-- Testing and tabulation
 
-- isoRowtranspose :: [Date[a]] -> String[[a]]
on isoRowtranspose(lstDatexss)
script mf
intercalate(tab, map(my isoDateString, lstDate))
on lambdaCol(_, iCol)
end isoRow
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
Line 129 ⟶ 168:
return strJoined
end intercalate
 
-- transposeisoRow :: [[a]Date] -> [[a]]String
on isoRow(lstDate)
intercalate(tab, map(my isoDateString, lstDate))
end isoRow
 
-- range :: Int -> Int -> [Int]
Line 140 ⟶ 184:
return lst
end range
 
-- 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
 
 
Line 169 ⟶ 198:
return lst
end map
 
 
 
-- Lift 2nd class handler function into 1st class script wrapper
Line 190 ⟶ 217:
 
{{Out}}
<pre>20122014-01-2926 20132015-01-2725 20142016-01-2631 20152017-01-2529 20162018-01-3128
20122014-02-2623 20132015-02-2422 20142016-02-2328 20152017-02-2226 20162018-02-2825
20122014-03-2530 20132015-03-3129 20142016-03-3027 20152017-03-2926 20162018-03-2725
20122014-04-2927 20132015-04-2826 20142016-04-2724 20152017-04-2630 20162018-04-2429
20122014-05-2725 20132015-05-2631 20142016-05-2529 20152017-05-3128 20162018-05-2927
20122014-06-2429 20132015-06-3028 20142016-06-2926 20152017-06-2825 20162018-06-2624
20122014-07-2927 20132015-07-2826 20142016-07-2731 20152017-07-2630 20162018-07-3129
20122014-08-2631 20132015-08-2530 20142016-08-3128 20152017-08-3027 20162018-08-2826
20122014-09-3028 20132015-09-2927 20142016-09-2825 20152017-09-2724 20162018-09-2530
20122014-10-2826 20132015-10-2725 20142016-10-2630 20152017-10-2529 20162018-10-3028
20122014-11-2530 20132015-11-2429 20142016-11-3027 20152017-11-2926 20162018-11-2725
20122014-12-3028 20132015-12-2927 20142016-12-2825 20152017-12-2731 20162018-12-2530</pre>
 
=={{header|AutoHotkey}}==
9,655

edits