Last Friday of each month: Difference between revisions

Content added Content deleted
Line 89: Line 89:
intercalate(linefeed, ¬
intercalate(linefeed, ¬
map(ISODate, ¬
map(isoRow, ¬
lastWeekDaysOfYear(2012, Friday as integer)))
transpose(map(lastFridaysOfYear, range(2012, 2016)))))
end run
end run

-- DERIVATION OF LAST FRIDAYS

-- lastFridaysOfYear :: Int -> [Date]
on lastFridaysOfYear(y)
lastWeekDaysOfYear(y, Friday as integer)
end lastFridaysOfYear




-- lastWeekDaysOfYear :: Int -> Int -> [Date]
-- lastWeekDaysOfYear :: Int -> Int -> [Date]
on lastWeekDaysOfYear(intYear, iWeekDay)
on lastWeekDaysOfYear(intYear, iWeekday)
map(mClosure(my lastWeekDay, ¬
map(mClosure(my lastWeekDay, ¬
{intYear:intYear, iWeekDay:iWeekDay}), my lastDaysOfMonths(intYear))
{intYear:intYear, iWeekday:iWeekday}), my lastDaysOfMonths(intYear))
end lastWeekDaysOfYear
end lastWeekDaysOfYear




-- lastWeekDay :: iLastDay, iMonth
-- lastWeekDay :: Int -> Int -> Date
on lastWeekDay(iLastDay, iMonth)
on lastWeekDay(iLastDay, iMonth)
set iYear to intYear of my closure
set iYear to intYear of my closure
Line 110: Line 115:
calendarDate(iYear, iMonth, iLastDay - ¬
calendarDate(iYear, iMonth, iLastDay - ¬
(((weekday of calendarDate(iYear, iMonth, iLastDay)) as integer) + ¬
(((weekday of calendarDate(iYear, iMonth, iLastDay)) as integer) + ¬
(7 - (iWeekDay of my closure))) mod 7)
(7 - (iWeekday of my closure))) mod 7)
end lastWeekDay
end lastWeekDay


Line 124: Line 129:
{31, iFeb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
{31, iFeb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
end lastDaysOfMonths
end lastDaysOfMonths





-- GENERIC FUNCTIONS
-- GENERIC FUNCTIONS

-- Dates and date strings


-- calendarDate :: Int -> Int -> Int -> Date
-- calendarDate :: Int -> Int -> Int -> Date
on calendarDate(intYear, intMonth, intDay)
on calendarDate(intYear, intMonth, intDay)
tell (current date)
tell (current date)
set {its year, its month, its day, its time} to {intYear, intMonth, intDay, 0}
set {its year, its month, its day, its time} to ¬
{intYear, intMonth, intDay, 0}
return it
return it
end tell
end tell
end calendarDate
end calendarDate


-- ISODate :: Date -> String
-- isoDateString :: Date -> String
on ISODate(dte)
on isoDateString(dte)
(((year of dte) as string) & ¬
(((year of dte) as string) & ¬
"-" & text items -2 thru -1 of ¬
"-" & text items -2 thru -1 of ¬
Line 144: Line 151:
"-" & text items -2 thru -1 of ¬
"-" & text items -2 thru -1 of ¬
("0" & day of dte)
("0" & day of dte)
end ISODate
end isoDateString

-- 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
-- intercalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
on intercalate(strText, lstText)
set {dlm, my text item delimiters} to {my text item delimiters, strText}
set {dlm, my text item delimiters} to ¬
{my text item delimiters, strText}
set strJoined to lstText as text
set strJoined to lstText as text
set my text item delimiters to dlm
set my text item delimiters to dlm
return strJoined
return strJoined
end intercalate
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: Line 204:
set lst to {}
set lst to {}
repeat with i from 1 to lng
repeat with i from 1 to lng
set end of lst to mf's lambda(item i of xs, i, xs)
set end of lst to lambda(item i of xs, i, xs) of mf
end repeat
end repeat
return lst
return lst
Line 188: Line 229:
{{Out}}
{{Out}}


<pre>2012-01-27
<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</pre>
2012-12-28 2013-12-27 2014-12-26 2015-12-25 2016-12-30</pre>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==