Day of the week: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|Python}}: Added a datetime variant) |
||
Line 3,262: | Line 3,262: | ||
The function <code>calendar.weekday</code> accepts all dates between 1/1/1 and 9999/12/31, and uses the [https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar proleptic Gregorian calendar] before adoption of the [https://en.wikipedia.org/wiki/Gregorian_calendar Gregorian calendar] in 1582. There is no gap between 1582/10/4 and 1582/10/15, as can be seen with <code>print(calendar.calendar(1582))</code>. |
The function <code>calendar.weekday</code> accepts all dates between 1/1/1 and 9999/12/31, and uses the [https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar proleptic Gregorian calendar] before adoption of the [https://en.wikipedia.org/wiki/Gregorian_calendar Gregorian calendar] in 1582. There is no gap between 1582/10/4 and 1582/10/15, as can be seen with <code>print(calendar.calendar(1582))</code>. |
||
Or, in terms of datetime: |
|||
<lang python>import datetime |
|||
# xmasIsSunday :: Int -> Bool |
|||
def xmasIsSunday(y): |
|||
return 6 == datetime.date(y, 12, 25).weekday() |
|||
# main :: IO () |
|||
def main(): |
|||
print( |
|||
[y for y in enumFromTo(2008)(2121) if xmasIsSunday(y)] |
|||
) |
|||
# GENERIC ------------------------------------------------- |
|||
# enumFromTo :: Int -> Int -> [Int] |
|||
def enumFromTo(m): |
|||
return lambda n: list(range(m, 1 + n)) |
|||
# MAIN -- |
|||
main()</lang> |
|||
{{Out}} |
|||
<pre>[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]</pre> |
|||
=={{header|R}}== |
=={{header|R}}== |