Day of the week of Christmas and New Year: Difference between revisions
Line 38: | Line 38: | ||
<lang julia>using Dates |
<lang julia>using Dates |
||
println("Christmas 2021: ", Dates.format(DateTime(2021, 12, 25), ", U d, Y")) # "Saturday, December 25, 2021" |
println("Christmas 2021: ", Dates.format(DateTime(2021, 12, 25), "E, U d, Y")) # "Saturday, December 25, 2021" |
||
println("New Years Day 2022: ", Dates.format(DateTime(2022, 1, 1), ", U d, Y")) # "Saturday, January 1, 2022" |
println("New Years Day 2022: ", Dates.format(DateTime(2022, 1, 1), "E, U d, Y")) # "Saturday, January 1, 2022" |
||
</lang> |
</lang> |
||
Revision as of 18:44, 24 November 2021
- Task
Determine programatically and show on this page on what weekday Christmas Day, 2021 and New Year's Day, 2022 will fall or did fall.
Factor
<lang factor>USING: calendar calendar.english calendar.holidays.us formatting kernel sequences ;
CONSTANT: msg
"In %d, New Years is on a %s, and Christmas is on a %s.\n"
- day-name ( ts -- str ) day-of-week day-names nth ;
- christmas ( n -- str ) christmas-day day-name ;
- new-years ( n -- str ) new-years-day day-name ;
- holidays ( n -- ny ch ) [ new-years ] [ christmas ] bi ;
- .holidays ( seq -- ) [ dup holidays msg printf ] each ;
{ 1578 1590 1642 1957 2020 2021 2022 2242 2245 2393 } .holidays</lang>
- Output:
In 1578, New Years is on a Sunday, and Christmas is on a Monday. In 1590, New Years is on a Monday, and Christmas is on a Tuesday. In 1642, New Years is on a Wednesday, and Christmas is on a Thursday. In 1957, New Years is on a Tuesday, and Christmas is on a Wednesday. In 2020, New Years is on a Wednesday, and Christmas is on a Friday. In 2021, New Years is on a Friday, and Christmas is on a Saturday. In 2022, New Years is on a Saturday, and Christmas is on a Sunday. In 2242, New Years is on a Saturday, and Christmas is on a Sunday. In 2245, New Years is on a Wednesday, and Christmas is on a Thursday. In 2393, New Years is on a Friday, and Christmas is on a Saturday.
Julia
See also https://docs.julialang.org/en/v1/stdlib/Dates/#Dates.format-Tuple{TimeType,%20AbstractString} <lang julia>using Dates
println("Christmas 2021: ", Dates.format(DateTime(2021, 12, 25), "E, U d, Y")) # "Saturday, December 25, 2021" println("New Years Day 2022: ", Dates.format(DateTime(2022, 1, 1), "E, U d, Y")) # "Saturday, January 1, 2022" </lang>
Phix
with javascript_semantics include timedate.e procedure nyc(integer year) string ny = format_timedate({year,1,1,0,0,0},"Dddd"), cd = format_timedate({year,12,25,0,0,0},"Dddd") printf(1,"In %d, New year's day is on a %s, and Christmas day on a %s.\n",{year,ny,cd}) end procedure papply({1578, 1590, 1642, 1957, 2020, 2021, 2022, 2242, 2245, 2393},nyc)
Note the builtin timedate type does not officially support dates prior to 1752... the fact that the first three lines agree with other entries on this page is pure luck.
- Output:
In 1578, New year's day is on a Sunday, and Christmas day on a Monday. In 1590, New year's day is on a Monday, and Christmas day on a Tuesday. In 1642, New year's day is on a Wednesday, and Christmas day on a Thursday. In 1957, New year's day is on a Tuesday, and Christmas day on a Wednesday. In 2020, New year's day is on a Wednesday, and Christmas day on a Friday. In 2021, New year's day is on a Friday, and Christmas day on a Saturday. In 2022, New year's day is on a Saturday, and Christmas day on a Sunday. In 2242, New year's day is on a Saturday, and Christmas day on a Sunday. In 2245, New year's day is on a Wednesday, and Christmas day on a Thursday. In 2393, New year's day is on a Friday, and Christmas day on a Saturday.
Python
<lang python> iimport datetime
weekDays = ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday") thisXMas = datetime.date(2021,12,25) thisXMasDay = thisXMas.weekday() thisXMasDayAsString = weekDays[thisXMasDay] print("This year's Christmas is on a {}".format(thisXMasDayAsString))
nextNewYear = datetime.date(2022,1,1) nextNewYearDay = nextNewYear.weekday() nextNewYearDayAsString = weekDays[nextNewYearDay] print("Next new year is on a {}".format(nextNewYearDayAsString)) </lang>
- Output:
This year's Christmas is on a Saturday Next new year is on a Saturday
Raku
<lang perl6>my @d-o-w = < Sunday Monday Tuesday Wednesday Thursday Friday Saturday >;
.say for (flat 2020..2022, (1500 .. 2500).roll(7)).sort.map: {
"In {$_}, New Years is on a { @d-o-w[Date.new($_, 1, 1).day-of-week % 7] }, " ~ "and Christmas on a { @d-o-w[Date.new($_, 12, 25).day-of-week % 7] }."
}</lang>
- Sample output:
In 1578, New Years is on a Sunday, and Christmas on a Monday. In 1590, New Years is on a Monday, and Christmas on a Tuesday. In 1642, New Years is on a Wednesday, and Christmas on a Thursday. In 1957, New Years is on a Tuesday, and Christmas on a Wednesday. In 2020, New Years is on a Wednesday, and Christmas on a Friday. In 2021, New Years is on a Friday, and Christmas on a Saturday. In 2022, New Years is on a Saturday, and Christmas on a Sunday. In 2242, New Years is on a Saturday, and Christmas on a Sunday. In 2245, New Years is on a Wednesday, and Christmas on a Thursday. In 2393, New Years is on a Friday, and Christmas on a Saturday.
Wren
This uses the same years as the Raku example.
The actual days for 1578 may have been different as the Gregorian calendar didn't start until 1582. <lang ecmascript>import "./date" for Date
var years = [1578, 1590, 1642, 1957, 2020, 2021, 2022, 2242, 2245, 2393] for (year in years) {
var newYear = Date.new(year, 1, 1).weekDay var xmas = Date.new(year, 12, 25).weekDay System.print("In %(year), New year's day is on a %(newYear), and Christmas day on %(xmas).")
}</lang>
- Output:
In 1578, New year's day is on a Sunday, and Christmas day on Monday. In 1590, New year's day is on a Monday, and Christmas day on Tuesday. In 1642, New year's day is on a Wednesday, and Christmas day on Thursday. In 1957, New year's day is on a Tuesday, and Christmas day on Wednesday. In 2020, New year's day is on a Wednesday, and Christmas day on Friday. In 2021, New year's day is on a Friday, and Christmas day on Saturday. In 2022, New year's day is on a Saturday, and Christmas day on Sunday. In 2242, New year's day is on a Saturday, and Christmas day on Sunday. In 2245, New year's day is on a Wednesday, and Christmas day on Thursday. In 2393, New year's day is on a Friday, and Christmas day on Saturday.