Day of the week of Christmas and New Year: Difference between revisions
Day of the week of Christmas and New Year (view source)
Revision as of 16:31, 3 April 2024
, 1 month agono edit summary
(Added Chipmunk Basic, GW-BASIC and MSX Basic) |
No edit summary |
||
(10 intermediate revisions by 5 users not shown) | |||
Line 619:
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
func dayOfTheWeek year month day
# Based on Conway's doomsday algorithm
century = floor (year / 100)
if century mod 4 = 0
Line 632 ⟶ 631:
centuryDoomsday = 3
.
mainYear = year mod 100
yearDoomsday = (floor (mainYear / 12) + mainYear mod 12 + floor (mainYear mod 12 / 4) + centuryDoomsday) mod 7
if mainYear = 0
if century mod 4 = 0
Line 649 ⟶ 646:
.
.
if leap = 1
januaryOne = (yearDoomsday + 4) mod 7
Line 655 ⟶ 651:
januaryOne = (yearDoomsday + 5) mod 7
.
monthDays[] = [ 0 31 59 90 120 151 181 212 243 273 304 334 ]
nthDay = monthDays[month]
if month >
.
return (januaryOne + nthDay - 1) mod 7 + 1
.
days$[] = [ "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" ]
#
print "2021-12-25 is on " & days$[dayOfTheWeek 2021 12 25]
print "2022-1-1 is on " & days$[dayOfTheWeek 2022 1 1]
</syntaxhighlight>
{{out}}
Line 811 ⟶ 766:
Year 2245, New Years's Day: Wednesday, January 1, 2245 and Christmas: Thursday, December 25, 2245
Year 2393, New Years's Day: Friday, January 1, 2393 and Christmas: Saturday, December 25, 2393
</pre>
=={{header|Nim}}==
<syntaxhighlight lang="Nim">
import std/times
echo "25th of December 2021 is a ", getDayOfWeek(25, mDec, 2021)
echo "1st of January 2022 is a ", getDayOfWeek(1, mJan, 2022)
</syntaxhighlight>
{{out}}
<pre>25th of December 2021 is a Saturday
1st of January 2022 is a Saturday
</pre>
Line 826 ⟶ 794:
<pre>25.12.2021 is a Saturday
01.01.2022 is a Saturday<</pre>
=={{header|Pascal}}==
==={{header|Free Pascal}}===
<syntaxhighlight lang="pascal">
Program daysofweek;
Uses sysutils;
Const Years : array Of integer = (1578, 1590, 1642, 1957, 2020, 2021, 2022, 2242, 2245, 2393);
Var christmasday, newyearsday : tdatetime;
year : integer;
Begin
For year In years Do
Begin
christmasday := encodeDate(year,12,25);
newyearsday := encodeDate(year,1,1);
writeln('in ',year,' New Years day is on ',DefaultFormatSettings.LongDayNames[DayOfWeek(
newyearsday)],', and Christmas day on a ',DefaultFormatSettings.LongDayNames[DayOfWeek(
christmasday
)]);
End;
End.
</syntaxhighlight>
{{out}}
<pre>
in 1578 New Years day is on Sunday, and Christmas day on a Monday
in 1590 New Years day is on Monday, and Christmas day on a Tuesday
in 1642 New Years day is on Wednesday, and Christmas day on a Thursday
in 1957 New Years day is on Tuesday, and Christmas day on a Wednesday
in 2020 New Years day is on Wednesday, and Christmas day on a Friday
in 2021 New Years day is on Friday, and Christmas day on a Saturday
in 2022 New Years day is on Saturday, and Christmas day on a Sunday
in 2242 New Years day is on Saturday, and Christmas day on a Sunday
in 2245 New Years day is on Wednesday, and Christmas day on a Thursday
in 2393 New Years day is on Friday, and Christmas day on a Saturday
</pre>
=={{header|Perl}}==
Line 1,068 ⟶ 1,073:
The next New Year's day is on a Saturday.
done...</pre>
=={{header|RPL}}==
{{works with|HP|48}}
≪ 1000000 / 25.12 + 0
TSTR 1 3 SUB
"X-MAS: " OVER +
"NEW YEAR: " ROT +
≫ '<span style="color:blue">TASK</span>' STO
2021 <span style="color:blue">TASK</span>
{{out}}
<pre>
2: "X-MAS: SAT"
1: "NEW YEAR: SAT"
</pre>
=={{header|Ruby}}==
Line 1,097 ⟶ 1,117:
This uses the same years as the Raku example.
The above module uses the Gregorian Proleptic calendar and therefore gives the wrong days of the week for 1578 as the earliest year for the adoption of the Gregorian calendar was 1582 when 10 days (from 5th until 14th October inclusive) were omitted. To get the correct days for 1578 (and agree with the Ruby entry) we therefore need to add 10 days to the Gregorian date which the ''Date.fromJulian'' method does automatically.
<syntaxhighlight lang="
System.print("Days of week per Gregorian Proleptic calendar:")
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).")
}
System.print("\nActual days for 1578 (Julian calendar) were 10 days later:")
System.print(" New Year's day was on %(Date.fromJulian(1578, 1, 1).weekDay), and Christmas day on %(Date.fromJulian(1578, 12, 25).weekDay).")</syntaxhighlight>
{{out}}
<pre>
Days of week per Gregorian Proleptic calendar:
In
In
In
In
In
In
In
In
In
In 2393, New year's day is on a Friday, and Christmas day on Saturday.
Actual days for 1578 (Julian calendar) were 10 days later:
New Year's day was on Wednesday, and Christmas day on Thursday.
</pre>
|