Doomsday rule: Difference between revisions
Content deleted Content added
Added AppleScript. |
|||
Line 245: | Line 245: | ||
weekday 2101 4 2 |
weekday 2101 4 2 |
||
Saturday</pre> |
Saturday</pre> |
||
=={{header|AppleScript}}== |
|||
<lang applescript>on dayOfWeek(yyyymmdd) |
|||
tell yyyymmdd to set {y, m, d} to {word 1 as integer, word 2 as integer, word 3 as integer} |
|||
set doomsdayForYear to (y + y div 4 - y div 100 + y div 400 + 2) -- (mod 7 further down anyway) |
|||
if ((m < 3) and ((y mod 4 = 0) and (y mod 100 > 0) or (y mod 400 = 0))) then set m to m + 12 |
|||
set doomsdayInMonth to item m of {3, 28, 7, 4, 2, 6, 4, 8, 5, 10, 7, 12, 4, 29} |
|||
return item ((doomsdayForYear + d - doomsdayInMonth + 28) mod 7 + 1) of ¬ |
|||
{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} |
|||
end dayOfWeek |
|||
on join(lst, delim) |
|||
set astid to AppleScript's text item delimiters |
|||
set AppleScript's text item delimiters to delim |
|||
set txt to lst as text |
|||
set AppleScript's text item delimiters to astid |
|||
return txt |
|||
end join |
|||
on task() |
|||
set dateStrings to {"1800-01-06", "1875-03-29", "1915-12-07", "1970-12-23", "2043-05-14", "2077-02-12", "2101-04-02"} |
|||
set output to {} |
|||
repeat with yyyymmdd in dateStrings |
|||
set end of output to yyyymmdd & " --> " & dayOfWeek(yyyymmdd) |
|||
end repeat |
|||
return join(output, linefeed) |
|||
end task |
|||
task()</lang> |
|||
{{output}} |
|||
<lang applescript>"1800-01-06 --> Monday |
|||
1875-03-29 --> Monday |
|||
1915-12-07 --> Tuesday |
|||
1970-12-23 --> Wednesday |
|||
2043-05-14 --> Thursday |
|||
2077-02-12 --> Friday |
|||
2101-04-02 --> Saturday"</lang> |
|||
=={{header|BASIC}}== |
=={{header|BASIC}}== |