Day of the week of Christmas and New Year: Difference between revisions

no edit summary
(Added EasyLang implementation)
No edit summary
 
(14 intermediate revisions by 8 users not shown)
Line 55:
2021-12-25 00:00:00 is a SATURDAY.
2022-01-01 00:00:00 is a SATURDAY.
</pre>
 
=={{header|ALGOL 68}}==
{{Trans|ALGOL W}}
<syntaxhighlight lang="algol68">
BEGIN # find the day of the week 25/12/2021 and 01/01/2022 fall on #
[]STRING day name =
[]STRING( "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" )[ AT 0 ];
PROC day of week = ( INT d, m, y )INT:
BEGIN
INT mm := m;
INT yy := y;
IF mm <= 2 THEN
mm +:= 12;
yy -:= 1
FI;
INT j = yy OVER 100;
INT k = yy MOD 100;
( d + ( ( mm + 1 ) * 26 ) OVER 10 + k + k OVER 4 + j OVER 4 + 5 * j ) MOD 7
END # day of week # ;
print( ( "25th of December 2021 is a ", day name[ day of week( 25, 12, 2021 ) ], newline ) );
print( ( " 1st of January 2022 is a ", day name[ day of week( 1, 1, 2022 ) ], newline ) )
END
</syntaxhighlight>
{{out}}
<pre>
25th of December 2021 is a Saturday
1st of January 2022 is a Saturday
</pre>
 
Line 136 ⟶ 164:
<pre>12/25/2021 is a Saturday
1/ 1/2022 is a Saturday</pre>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="freebasic">print "Christmas Day 2021 is on a "; diasemana$(2021, 12, 25)
print "New Year's Day 2022 is on a "; diasemana$(2022, 1, 1)
end
 
function diasemana$(anno, mes, dia)
dim nombre$(6)
nombre$ = {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}
if mes <= 2 then
mes += 12
anno -= 1
end if
dia = (dia-1 + ((mes+1)*26)\10 + anno + anno\4 + anno\400 + anno*6\100) mod 7
return nombre$[dia]
end function</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{works with|QBasic}}
{{trans|QBasic}}
<syntaxhighlight lang="qbasic">100 REM Day of the week of Christmas and New Year
110 CLS
120 DIM d$(6)
130 FOR i = 0 TO 6 : READ d$(i) : NEXT i
140 FOR i = 1 TO 2
150 READ y,m,d
160 PRINT m;"/";d;"/";y;" is a ";
170 IF m <= 2 THEN LET m = m+12 : LET y = y-1
180 LET j = INT(y/100)
190 LET k = y-INT(y/100)*100
200 LET t = (d+INT((m+1)*26)/10+k+k/4+j/4+5*j)
210 LET d = t-INT(t/7)*7
211 rem LET d = INT(d + ((m + 1) * 26) / 10 + K + K / 4 + J \ 4 + 5 * J) MOD 7
220 PRINT d$(d)
230 NEXT i
240 DATA "Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"
250 DATA 2021,12,25
260 DATA 2022,1,1
270 END</syntaxhighlight>
 
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{works with|MSX BASIC}}
{{works with|QBasic}}
{{trans|QBasic}}
<syntaxhighlight lang="qbasic">100 REM Day of the week of Christmas and New Year
110 CLS
120 DIM d$(6)
130 FOR i = 0 TO 6: READ d$(i): NEXT i
140 FOR i = 1 TO 2
150 READ y, m, d
160 PRINT USING "##/##/#### is a "; m; d; y;
170 IF m <= 2 THEN m = m + 12: y = y - 1
180 j = y \ 100
190 k = y MOD 100
200 d = (d + ((m + 1) * 26) \ 10 + k + k \ 4 + j \ 4 + 5 * j) MOD 7
210 PRINT d$(d)
220 NEXT i
230 DATA Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday
240 DATA 2021, 12, 25
250 DATA 2022, 1, 1
260 END</syntaxhighlight>
 
==={{header|MSX Basic}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">DIM d$(6)
FOR i = 0 TO 6: READ d$(i): NEXT i
FOR i = 1 TO 2
READ y, m, d
PRINT USING "##/##/#### is a "; m; d; y;
IF m <= 2 THEN m = m + 12: y = y - 1
J = y \ 100
K = y MOD 100
d = (d + ((m + 1) * 26) \ 10 + K + K \ 4 + J \ 4 + 5 * J) MOD 7
PRINT d$(d)
NEXT i
DATA Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday
DATA 2021, 12, 25
DATA 2022, 1, 1
END</syntaxhighlight>
 
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">OPTION BASE 0
DIM d$(6)
FOR i = 0 TO 6
READ d$(i)
NEXT i
FOR i = 1 TO 2
READ y, m, d
PRINT USING "##/##/#### is a ": m, d, y;
IF m <= 2 THEN
LET m = m+12
LET y = y-1
END IF
LET j = IP(round(y)/100)
LET k = REMAINDER(ROUND(y),100)
LET d = REMAINDER(ROUND((d+IP(ROUND(((m+1)*26))/10)+k+IP(ROUND(k)/4)+IP(ROUND(j)/4)+5*j)),7)
PRINT d$(d)
NEXT i
DATA Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday
DATA 2021, 12, 25
DATA 2022, 1, 1
END</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="xbasic">PROGRAM "progname"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
DIM d$[6]
d$[0] = "Saturday"
d$[1] = "Sunday"
d$[2] = "Monday"
d$[3] = "Tuesday"
d$[4] = "Wednesday"
d$[5] = "Thursday"
d$[6] = "Friday"
 
y = 2021: m = 12: d = 25
FOR i = 1 TO 2
PRINT d; " /"; m; " /"; y; " is a ";
IF m <= 2 THEN m = m + 12: y = y - 1
J = y \ 100
K = y MOD 100
d = (d + ((m + 1) * 26) \ 10 + K + K \ 4 + J \ 4 + 5 * J) MOD 7
PRINT d$[d]
y = 2022: m = 1: d = 1
NEXT i
END FUNCTION
END PROGRAM</syntaxhighlight>
 
==={{header|Yabasic}}===
<syntaxhighlight lang="yabasic">dim nombre$(6)
nombre$(0) = "Saturday"
nombre$(1) = "Sunday"
nombre$(2) = "Monday"
nombre$(3) = "Tuesday"
nombre$(4) = "Wednesday"
nombre$(5) = "Thursday"
nombre$(6) = "Friday"
 
print "Christmas Day 2021 is on a ", diasemana$(2021, 12, 25)
print "New Year's Day 2022 is on a ", diasemana$(2022, 1, 1)
end
 
sub diasemana$(anno, mes, dia)
if mes <= 2 then
mes = mes + 12
anno = anno - 1
fi
dia = mod((dia-1 + int(((mes+1)*26)/10) + anno + int(anno/4) + int(anno/400) + int(anno*6/100)), 7)
return nombre$(dia)
end sub</syntaxhighlight>
 
 
=={{header|BCPL}}==
Line 357 ⟶ 547:
<pre>25/12/2021 is a Saturday
1/1/2022 is a Saturday</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|Controls,SysUtils,StdCtrls}}
Delphi libraries make this easy.
 
<syntaxhighlight lang="Delphi">
 
procedure DoChristmasNewYear(Memo: TMemo);
var D: TDate;
begin
D:=EncodeDate(2021,12,25);
Memo.Lines.Add(FormatDateTime('"Christmas Day, 2021 is on: " dddd ', D));
D:=EncodeDate(2022,1,1);
Memo.Lines.Add(FormatDateTime('"New Years Day, 2022 is on: " dddd ', D));
end;
 
</syntaxhighlight>
{{out}}
<pre>
Christmas Day, 2021 is on: Saturday
New Years Day, 2022 is on: Saturday
 
</pre>
 
=={{header|Draco}}==
Line 405 ⟶ 619:
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
func dayOfTheWeek year month day . result .
# Based on Conway's doomsday algorithm
# 1. Calculate the doomsday for the century
century = floor (year / 100)
if century mod 4 = 0
Line 418 ⟶ 631:
centuryDoomsday = 3
.
# 2. Find the doomsday of the year
mainYear = year mod 100
yearDoomsday = (floor (mainYear / 12) + mainYear mod 12 + floor (mainYear mod 12 / 4) + centuryDoomsday) mod 7
# 3. Check if the year is leap
if mainYear = 0
if century mod 4 = 0
Line 435 ⟶ 646:
.
.
# 4. Calculate the DOTW of January 1
if leap = 1
januaryOne = (yearDoomsday + 4) mod 7
Line 441 ⟶ 651:
januaryOne = (yearDoomsday + 5) mod 7
.
monthDays[] = [ 0 31 59 90 120 151 181 212 243 273 304 334 ]
# 5. Determine the nth day of the year
nthDay = monthDays[month]
if month = 1
if month > NthDay = 02
elif month nthDay += 2leap
NthDay = 31
elif month = 3
NthDay = 59 + leap
elif month = 4
NthDay = 90 + leap
elif month = 5
NthDay = 120 + leap
elif month = 6
NthDay = 151 + leap
elif month = 7
NthDay = 181 + leap
elif month = 8
NthDay = 212 + leap
elif month = 9
NthDay = 243 + leap
elif month = 10
NthDay = 273 + leap
elif month = 11
NthDay = 304 + leap
elif month = 12
NthDay = 334 + leap
.
NthDay += day
# 6. Finally, calculate the day of the week
result = (januaryOne + NthDay - 1) mod 7
.
func numberToDay n . day$ .
if n = 0
day$ = "Sunday"
elif n = 1
day$ = "Monday"
elif n = 2
day$ = "Tuesday"
elif n = 3
day$ = "Wednesday"
elif n = 4
day$ = "Thursday"
elif n = 5
day$ = "Friday"
elif n = 6
day$ = "Saturday"
.
nthDay += day
return (januaryOne + nthDay - 1) mod 7 + 1
.
days$[] = [ "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" ]
call dayOfTheWeek 2021 12 25 result
#
call numberToDay result day$
print "2021-12-25 is on " & daydays$[dayOfTheWeek 2021 12 25]
callprint "2022-1-1 is on " & days$[dayOfTheWeek 2022 1 1 result]
call numberToDay result day$
print "2022-1-1 is on " & day$
</syntaxhighlight>
{{out}}
Line 597 ⟶ 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 612 ⟶ 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 854 ⟶ 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 883 ⟶ 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.
The actual days for 1578 may have been different as the Gregorian calendar didn't start until 1582.
<syntaxhighlight lang="ecmascriptwren">import "./date" for Date
 
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).")
}
}</syntaxhighlight>
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 1578, New year's day is on a Sunday, and Christmas day on Monday.
In 15901578, New year's day is on a MondaySunday, and Christmas day on TuesdayMonday.
In 16421590, New year's day is on a WednesdayMonday, and Christmas day on ThursdayTuesday.
In 19571642, New year's day is on a TuesdayWednesday, and Christmas day on WednesdayThursday.
In 20201957, New year's day is on a WednesdayTuesday, and Christmas day on FridayWednesday.
In 20212020, New year's day is on a FridayWednesday, and Christmas day on SaturdayFriday.
In 20222021, New year's day is on a SaturdayFriday, and Christmas day on SundaySaturday.
In 22422022, New year's day is on a Saturday, and Christmas day on Sunday.
In 22452242, New year's day is on a WednesdaySaturday, and Christmas day on ThursdaySunday.
In 23932245, New year's day is on a FridayWednesday, and Christmas day on SaturdayThursday.
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>
 
43

edits