Day of the week: Difference between revisions

Added MiniScript
(UNIX Shell and UnixPipes: date -d seems to be a GNU extension. Add alternate solution with cal.)
(Added MiniScript)
 
(403 intermediate revisions by more than 100 users not shown)
Line 1:
{{task|Date and time}}
{{omit from|GUISS|We could open a calendar, but the operator would have to read it}}
{{omit from|ML/I}}
{{omit from|PARI/GP|No standard date handling library}}
 
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January).
 
;Task:
'''In what years between 2008 and 2121 will the 25th of December be a Sunday?'''
 
Using any standard date handling libraries of your programming language; compare the dates calculated with the output of other languages to discover any anomalies in the handling of dates which may be due to, for example, overflow in types used to represent dates/times similar to [[wp:Y2k#See_also|y2k]] type problems.
compare the dates calculated with the output of other languages to discover any anomalies in the handling of dates which may be due to, for example, overflow in types used to represent dates/times similar to   [[wp:Y2k#See_also|y2k]]   type problems.
<br><br>
 
=={{header|11l}}==
<syntaxhighlight lang="11l">print((2008..2121).filter(y -> Time(y, 12, 25).strftime(‘%w’) == ‘0’))</syntaxhighlight>
{{out}}
<pre>
[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]
</pre>
 
=={{header|360 Assembly}}==
{{trans|REXX}}
The program uses two ASSIST macro (XDECO,XPRNT) to keep the code as short as possible.
<syntaxhighlight lang="360asm">* Day of the week 06/07/2016
DOW CSECT
USING DOW,R15 base register
LA R6,2008 year=2008
LOOP C R6,=F'2121' do year=2008 to 2121
BH ELOOP .
LR R7,R6 y=year
LA R8,12 m=12
LA R9,25 d=25
C R8,=F'3' if m<3
BNL MGE3 then
LA R8,12(R8) m=m+12
BCTR R7,0 y=y-1
MGE3 LR R10,R7 y
SRDA R10,32 .
D R10,=F'100' r=y//100 ; l=y/100
LR R3,R8 m
LA R3,1(R3) m+1
M R2,=F'26' *26
D R2,=F'10' /10
AR R3,R9 +d
AR R3,R10 +r
LR R2,R10 r
SRA R2,2 /4
AR R2,R3 (d+(m+1)*26/10+r+r/4
LR R3,R11 l
SRA R3,2 /4
AR R2,R3 (d+(m+1)*26/10+r+r/4+l/4
LA R5,5 5
MR R4,R11 *l
AR R2,R5 (d+(m+1)*26/10+r+r/4+l/4+5*l)
SRDA R2,32 .
D R2,=F'7' w=(d+(m+1)*26/10+r+r/4+l/4+5*l)//7
C R2,=F'1' if w=1 (sunday)
BNE WNE1 then
XDECO R6,PG edit year
XPRNT PG,12 print year
WNE1 LA R6,1(R6) year=year+1
B LOOP next year
ELOOP BR R14 exit
PG DS CL12 buffer
YREGS
END DOW</syntaxhighlight>
{{out}}
<pre style="height:16ex"> 2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
=={{header|ABAP}}==
<langsyntaxhighlight ABAPlang="abap">report zday_of_week
data: lv_start type i value 2007,
lv_n type i value 114,
Line 31 ⟶ 111:
endif.
enddo.
</syntaxhighlight>
</lang>
{{out}}
Output:
<pre style="height:30ex;overflow:scroll">
December 25 is a Sunday in:
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|Action!}}==
Action! does not have a standard library providing a day of week function, therefore an adaptation of [https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Sakamoto.27s_methods Sakamoto's method] to determine the day of week for a given date using integer arithmetic is used.
<syntaxhighlight lang="action!">
Byte FUNC DayOfWeek(BYTE day, month CARD year BYTE century)
CARD weekday
BYTE ARRAY index=[0 3 2 5 0 3 5 1 4 6 2 4]
IF year < 100 THEN
year = year + century * 100
FI
 
IF year < 1753 THEN RETURN(7) FI
 
IF month < 3 THEN
year==-1
FI
 
month = index(month-1)
weekday=year + year/4 - year/100 + year/400 + month + day
weekday = weekday MOD 7
RETURN (weekday)
 
PROC main()
CARD y
PrintE("December 25 is a Sunday in:")
FOR y = 2008 to 2121
DO
IF DayOfWeek(25, 12, y)=0 THEN
PrintCE(y)
FI
OD
RETURN
</syntaxhighlight>
{{out}}
<pre style="height:30ex;overflow:scroll">
December 25 is a Sunday in:
Line 55 ⟶ 190:
 
=={{header|Ada}}==
<langsyntaxhighlight lang="ada">with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Text_IO; use Ada.Text_IO;
procedure Yuletide is
begin
for Year in Ada2008.Calendar.Year_Number2121 loop -- 1901..2399
if Day_Of_Week (Time_Of (Year, 12, 25)) = Sunday then
Put_Line (Image (Time_Of (Year, 12, 25)));
end if;
end loop;
end Yuletide;</langsyntaxhighlight>
{{out}}
Sample output:
<pre style="height:30ex;overflow:scroll">
1904-12-25 00:00:00
1910-12-25 00:00:00
1921-12-25 00:00:00
1927-12-25 00:00:00
1932-12-25 00:00:00
1938-12-25 00:00:00
1949-12-25 00:00:00
1955-12-25 00:00:00
1960-12-25 00:00:00
1966-12-25 00:00:00
1977-12-25 00:00:00
1983-12-25 00:00:00
1988-12-25 00:00:00
1994-12-25 00:00:00
2005-12-25 00:00:00
2011-12-25 00:00:00
2016-12-25 00:00:00
Line 100 ⟶ 220:
2112-12-25 00:00:00
2118-12-25 00:00:00
2129-12-25 00:00:00
2135-12-25 00:00:00
2140-12-25 00:00:00
2146-12-25 00:00:00
2157-12-25 00:00:00
2163-12-25 00:00:00
2168-12-25 00:00:00
2174-12-25 00:00:00
2185-12-25 00:00:00
2191-12-25 00:00:00
2196-12-25 00:00:00
2203-12-25 00:00:00
2208-12-25 00:00:00
2214-12-25 00:00:00
2225-12-25 00:00:00
2231-12-25 00:00:00
2236-12-25 00:00:00
2242-12-25 00:00:00
2253-12-25 00:00:00
2259-12-25 00:00:00
2264-12-25 00:00:00
2270-12-25 00:00:00
2281-12-25 00:00:00
2287-12-25 00:00:00
2292-12-25 00:00:00
2298-12-25 00:00:00
2304-12-25 00:00:00
2310-12-25 00:00:00
2321-12-25 00:00:00
2327-12-25 00:00:00
2332-12-25 00:00:00
2338-12-25 00:00:00
2349-12-25 00:00:00
2355-12-25 00:00:00
2360-12-25 00:00:00
2366-12-25 00:00:00
2377-12-25 00:00:00
2383-12-25 00:00:00
2388-12-25 00:00:00
2394-12-25 00:00:00
</pre>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68|Revision 1 - no extensions to language used}}
Line 147 ⟶ 228:
 
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d]}}
<langsyntaxhighlight lang="algol68"># example from: http://www.xs4all.nl/~jmvdveer/algol.html - GPL #
INT sun=0 # , mon=1, tue=2, wed=3, thu=4, fri=5, sat=6 #;
 
Line 169 ⟶ 250:
new line(stand out)
)
</syntaxhighlight>
</lang>
{{out}}
Output:
<pre>
December 25th is a Sunday in: 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
=={{header|ALGOL W}}==
{{Trans|Fortran}}
<syntaxhighlight lang="algolw">begin % find years where Christmas day falls on a Sunday %
integer procedure Day_of_week ( integer value d, m, y );
begin
integer j, k, mm, yy;
mm := m;
yy := y;
if mm <= 2 then begin
mm := mm + 12;
yy := yy - 1;
end if_m_le_2;
j := yy div 100;
k := yy rem 100;
(d + ( ( mm + 1 ) * 26 ) div 10 + k + k div 4 + j div 4 + 5 * j ) rem 7
end Day_of_week;
write( "25th of December is a Sunday in" );
for year := 2008 until 2121 do begin
integer day;
day := Day_of_week( 25, 12, year );
if day = 1 then writeon( I_W := 5, S_W := 0, year );
end for_year
end.</syntaxhighlight>
{{out}}
<pre>
25th of December is a Sunday in 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
=={{header|ALGOL-M}}==
<syntaxhighlight lang="algol">
BEGIN
 
% CALCULATE P MOD Q %
INTEGER FUNCTION MOD(P, Q);
INTEGER P, Q;
BEGIN
MOD := P - Q * (P / Q);
END;
 
COMMENT
RETURN DAY OF WEEK (SUN=0, MON=1, ETC.) FOR A GIVEN
GREGORIAN CALENDAR DATE USING ZELLER'S CONGRUENCE;
INTEGER FUNCTION DAYOFWEEK(MO, DA, YR);
INTEGER MO, DA, YR;
BEGIN
INTEGER Y, C, Z;
IF MO < 3 THEN
BEGIN
MO := MO + 10;
YR := YR - 1;
END
ELSE MO := MO - 2;
Y := MOD(YR, 100);
C := YR / 100;
Z := (26 * MO - 2) / 10;
Z := Z + DA + Y + (Y / 4) + (C /4) - 2 * C + 777;
DAYOFWEEK := MOD(Z, 7);
END;
 
% MAIN PROGRAM STARTS HERE %
INTEGER YEAR, SUNDAY;
SUNDAY := 0;
WRITE("CHRISTMAS WILL FALL ON A SUNDAY IN THESE YEARS:");
FOR YEAR := 2008 STEP 1 UNTIL 2121 DO
BEGIN
IF DAYOFWEEK(12, 25, YEAR) = SUNDAY THEN
WRITE(YEAR);
END;
 
END
</syntaxhighlight>
{{out}}
<pre>
CHRISTMAS WILL FALL ON A SUNDAY IN THESE YEARS:
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
=={{header|APL}}==
<syntaxhighlight lang="apl">⍝ Based on the simplified calculation of Zeller's congruence, since Christmas is after March 1st, no adjustment is required.
⎕IO ← 0 ⍝ Indices are 0-based
y ← 2008 + ⍳114 ⍝ Years from 2008 to 2121
⍝ Simplified Zeller function operating on table of dates formatted as 114 rows and 3 columns of (day, month, year)
⍝ 0 = Saturday, 1 = Sunday, 2 = Monday, 3 = Tuesday, 4 = Wednesday, 5 = Thursday, 6 = Friday
zeller ← { 7 | +/ (((1↑⍴⍵),6)⍴1 1 1 1 ¯1 1) × ⌊(((⍴⍵)⍴1 13 1)×⍵+(⍴⍵)⍴0 1 0)[;0 1 2 2 2 2]÷((1↑⍴⍵),6)⍴1 5 1 4 100 400 }
result ← (1 = zeller 25,[1]12,[0.5]y) / y
</syntaxhighlight>
{{out}}
<pre>
result
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
=={{header|AppleScript}}==
<langsyntaxhighlight lang="applescript">set ChristmasSundays to {}
set Christmas to (current date)
set month of Christmas to December
set day of Christmas to 25
repeat with |year| from 2008 to 2121
set year of Christmas to |year|
if weekday of Christmas is Sunday then set end of ChristmasSundays to |year|
end repeat
ChristmasSundays</langsyntaxhighlight>
 
 
Or, composing generic functions:
<syntaxhighlight lang="applescript">
-- xmasIsSunday :: Int -> Bool
on xmasIsSunday(y)
tell (current date)
set {its year, its month, its day, its time} to {y, 12, 25, 0}
its weekday is Sunday
end tell
end xmasIsSunday
 
 
-------------------------- TEST ---------------------------
on run
filter(xmasIsSunday, enumFromTo(2008, 2121))
end run
 
 
-------------------- GENERIC FUNCTIONS --------------------
 
-- enumFromTo :: Int -> Int -> [Int]
on enumFromTo(m, n)
if m ≤ n then
set lst to {}
repeat with i from m to n
set end of lst to i
end repeat
lst
else
{}
end if
end enumFromTo
 
 
-- filter :: (a -> Bool) -> [a] -> [a]
on filter(f, xs)
tell mReturn(f)
set lst to {}
set lng to length of xs
repeat with i from 1 to lng
set v to item i of xs
if |λ|(v, i, xs) then set end of lst to v
end repeat
return lst
end tell
end filter
 
 
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
else
script
property |λ| : f
end script
end if
end mReturn</syntaxhighlight>
{{Out}}
<syntaxhighlight lang="applescript">{2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067,
2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118}</syntaxhighlight>
 
=={{header|Arc}}==
<syntaxhighlight lang="arc">
(= day-names '(Sunday Monday Tuesday Wednesday Thursday Friday Saturday))
(= get-weekday-num (fn (year month day)
(= helper '(0 3 2 5 0 3 5 1 4 6 2 4))
(if (< month 3) (= year (- year 1)))
(mod (+ year (helper (- month 1)) day
(apply + (map [trunc (/ year _)] '(4 -100 400))))
7)))
(= get-weekday-name (fn (weekday-num) (day-names weekday-num)))
</syntaxhighlight>
<b>test:</b>
<syntaxhighlight lang="arc">(up i 2008 2121
(when (is 0 (get-weekday-num i 12 25))
(prn i)))
 
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
 
</syntaxhighlight>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">print select 2008..2121 'year [
"Sunday" = get to :date.format:"dd-MM-YYYY" ~"25-12-|year|" 'Day
]</syntaxhighlight>
 
{{out}}
 
<pre>2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118 </pre>
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight lang="autohotkey">year = 2008
stop = 2121
 
Line 196 ⟶ 495:
year++
}
MsgBox,% out</langsyntaxhighlight>
 
=={{header|AutoIt}}==
<langsyntaxhighlight AutoItlang="autoit">#include <date.au3>
Const $iSunday = 1
For $iYear = 2008 To 2121 Step 1
Line 205 ⟶ 504:
ConsoleWrite(StringFormat($iYear & "\n"))
EndIf
Next</langsyntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
 
<lang AWK>
# syntax: GAWK -f DAY_OF_THE_WEEK.AWK
# runtime does not support years > 2037 on my 32-bit Windows XP O/S
Line 218 ⟶ 516:
}
}
</syntaxhighlight>
</lang>
 
=={{header|BBC BASIC}}==
==={{header|Applesoft BASIC}}===
{{trans|Commodore BASIC}}
<syntaxhighlight lang="gwbasic"> 1 DEF FN D7(N) = N - 7 * INT (N / 7)
2 DEF FN RD(Y) = 365 * Y + INT (Y / 4) - INT (Y / 100) + INT (Y / 400)
3 PRINT "YEARS WITH CHRISTMAS ON A SUNDAY" CHR$ (13)
4 FOR Y = 2008 TO 2121
5 IF NOT FN D7( FN RD(Y) - 6) THEN PRINT Y,
6 NEXT Y</syntaxhighlight>
==={{header|ASIC}}===
{{trans|GW-BASIC}}
<syntaxhighlight lang="basic">
REM Day of the week
Month = 12
Day = 25
FOR Year = 2007 TO 2122
GOSUB CalcDayOfWeek:
IF DayOfWeek = 0 THEN
PRINT Year;
ENDIF
NEXT Year
PRINT
END
 
CalcDayOfWeek:
REM Sunday = 0, Saturday = 6
IF Month < 3 THEN
Year = Year - 1
Month = Month + 12
ENDIF
DayOfWeek = Year
YearDiv = Year / 4
DayOfWeek = DayOfWeek + YearDiv
YearDiv = Year / 100
DayOfWeek = DayOfWeek - YearDiv
YearDiv = Year / 400
DayOfWeek = DayOfWeek + YearDiv
DayPlus = 153 * Month
DayPlus = DayPlus + 8
DayPlus = DayPlus / 5
DayOfWeek = DayOfWeek + Day
DayOfWeek = DayOfWeek + DayPlus
DayOfWeek = DayOfWeek MOD 7
RETURN
</syntaxhighlight>
{{out}}
<pre>
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
==={{header|Atari BASIC}}===
{{trans|Commodore BASIC}}
<syntaxhighlight lang="basic">100 REM FIND YEARS WITH SUNDAY CHRISTMAS
110 PRINT CHR$(125);"SUNDAY CHRISTMASES 2008-2121:":PRINT
120 FOR Y=2008 TO 2121
130 EOY=Y*365+INT(Y/4)-INT(Y/100)+INT(Y/400)
140 XMAS=EOY-6
150 DOW=XMAS-7*INT(XMAS/7)
160 IF DOW THEN 220
170 PRINT Y;
180 FOUND=FOUND+1
190 IF FOUND<3 THEN PRINT ,:GOTO 220
200 FOUND=0
210 PRINT
220 NEXT Y
230 IF FOUND THEN PRINT</syntaxhighlight>
 
{{Out}}
<pre> SUNDAY CHRISTMASES 2008-2121
 
2011 2016 2022
2033 2039 2044
2050 2061 2067
2072 2078 2089
2095 2101 2107
2112 2118</pre>
 
==={{header|BaCon}}===
<syntaxhighlight lang="freebasic">' Sunday Christmas
PRINT "Years with Christmas on a Sunday"
FOR y = 2008 TO 2121
tv = TIMEVALUE(y, 12, 25, 0, 0, 0)
IF WEEKDAY$(tv) = "Sunday" THEN PRINT y
NEXT</syntaxhighlight>
 
{{out}}
<pre>prompt$ ./sunday-christmas
Years with Christmas on a Sunday
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="freebasic">for yr = 2008 to 2121
if wd(12, 25, yr) = 0 then print "Dec 25 "; yr
next
end
 
function wd(m, d, y)
if m < 3 then # if m = 1 or m = 2 then
m += 12
y -= 1
end if
return (y + (y \ 4) - (y \ 100) + (y \ 400) + d + ((153 * m + 8) \ 5)) % 7
end function</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> INSTALL @lib$+"DATELIB"
FOR year% = 2008 TO 2121
Line 228 ⟶ 648:
PRINT "Christmas Day is a Sunday in "; year%
ENDIF
NEXT</langsyntaxhighlight>
 
==={{header|CChipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{trans|Applesoft BASIC}}
<syntaxhighlight lang="qbasic">10 CLS : REM 10 HOME for Applesoft BASIC
20 DEF fnd7(n) = n - 7 * INT (n / 7)
30 DEF fnrd(y) = 365 * y + INT (y / 4) - INT (y / 100) + INT (y / 400)
40 PRINT "YEARS WITH CHRISTMAS ON A SUNDAY" CHR$(13)
50 FOR y = 2008 TO 2121
60 IF NOT fn d7(fn rd(y)-6) THEN PRINT y,
70 NEXT y</syntaxhighlight>
{{out}}
<pre>YEARS WITH CHRISTMAS ON A SUNDAY
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118 </pre>
 
==={{header|Commodore BASIC}}===
<lang c>#include <stdio.h>
This takes advantage of the dynamic scope of arguments to DEF FN functions to nest definitions and ultimately turn the question "Does Christmas fall on a Sunday in year Y?" into a single Boolean function of the year number. It's easy to run afoul of stack limitations in Microsoft BASICs doing this, especially on older versions that just use the processor's 256-byte stack instead of giving BASIC its own, but this program runs fine even on an unexpanded VIC-20.
#include <time.h>
#include <string.h>
 
<syntaxhighlight lang="basic">100 REM FIND OUT WHAT YEARS HAVE CHRISTMAS ON A SUNDAY
int main()
110 REM MODULO FUNCTION (USES CALLER'S N AS DIVIDEND)
{
120 DEF FNNM(D) = N - D * INT(N/D)
struct tm mytime;
130 REM RATA DIE OF 31 DEC Y (CAN BE TAKEN MODULO 7 TO GET DAY OF WEEK)
int i;
140 DEF FNRD(Y) = 365 * Y + INT(Y/4) - INT(Y/100) + INT(Y/400)
time_t m;
150 REM TRUE IF THE GIVEN RD IS A SUNDAY
160 DEF forFND7(iN) =2008; i<0 =2121; i++FNNM(7)
170 REM TRUE IF CHRISTMAS FALLS ON A SUNDAY IN THE GIVEN YEAR
{
180 DEF FNXS(Y) = FND7(FNRD(Y) - 6):REM 6 DAYS BEFORE THE END OF THE YEAR
memset(&mytime, 0, sizeof(struct tm));
190 REM TRY OUR TARGET YEARS AND OUTPUT THE ONES THAT MATCH
mytime.tm_mday = 25;
200 Y1 = 2008: Y2 = 2121
mytime.tm_mon = 11;
210 PRINT CHR$(147);"CHRISTMASES ON SUNDAY";Y1;"-";Y2;CHR$(13)
mytime.tm_year = i-1900;
220 FOR Y=Y1 TO Y2
m = mktime(&mytime);
230 : IF FNXS(Y) THEN PRINT Y,:REM PRINT YEARS IN COLUMNS
if ( m < 0 ) {
240 NEXT Y
printf("%d is the last year we can specify\n", i-1);
250 PRINT</syntaxhighlight>
break;
}
if ( mytime.tm_wday == 0 )
{
printf("25 December %d is Sunday\n", i);
}
}
}</lang>
 
{{Out}}
The output of a run on a 32 bit machine is
<pre>CHRISTMASES ON SUNDAY 2008 - 2121:
 
2011 2016 2022 2033
2039 2044 2050 2061
2067 2072 2078 2089
2095 2101 2107 2112
2118</pre>
 
==={{header|FBSL}}===
<syntaxhighlight lang="qbasic">#APPTYPE CONSOLE
 
'In what years between 2008 and 2121 will the 25th of December be a Sunday?
dim date as integer, dayname as string
for dim year = 2008 to 2121
date = year * 10000 + 1225
dayname = dateconv(date,"dddd")
if dayname = "Sunday" then
print "Christmas Day is on a Sunday in ", year
end if
next
PAUSE
</syntaxhighlight>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">' version 17-06-2015
' compile with: fbc -s console
 
Function wd(m As Integer, d As Integer, y As Integer) As Integer
If m < 3 Then ' If m = 1 Or m = 2 Then
m += 12
y -= 1
End If
Return (y + (y \ 4) - (y \ 100) + (y \ 400) + d + ((153 * m + 8) \ 5)) Mod 7
End Function
 
' ------=< MAIN >=------
 
For yr As Integer = 2008 To 2121
If wd(12, 25, yr) = 0 Then
Print "Dec 25 "; yr
EndIf
Next
 
' empty keyboard buffer
While InKey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End</syntaxhighlight>
{{out}}
<pre>Dec 25 2011
Dec 25 2016
Dec 25 2022
Dec 25 2033
Dec 25 2039
Dec 25 2044
Dec 25 2050
Dec 25 2061
Dec 25 2067
Dec 25 2072
Dec 25 2078
Dec 25 2089
Dec 25 2095
Dec 25 2101
Dec 25 2107
Dec 25 2112
Dec 25 2118</pre>
<syntaxhighlight lang="basic">Declare Function modulo(x As Double, y As Double) As Double
Declare Function wd(m As Double, d As Double, y As Double) As Integer
 
Cls
Dim yr As Double
For yr = 2008 To 2121
If wd(12,25,yr) = 1 Then
Print "Dec " & 25 & ", " & yr
EndIf
Next
Sleep
 
Function modulo(x As Double, y As Double) As Double
If y = 0 Then
Return x
Else
Return x - y * Int(x / y)
End If
End Function
 
Function wd(m As Double, d As Double, y As Double) As Integer
If m = 1 Or m = 2 Then
m += 12
y-= 1
End If
Return modulo(365 * y + Fix(y / 4) - Fix(y / 100) + Fix(y / 400) + d + Fix((153 * m + 8) / 5), 7) + 1
End Function
</syntaxhighlight>
{{out}}
<pre>
Dec 25 December, 2011 is Sunday
Dec 25 December, 2016 is Sunday
Dec 25 December, 2022 is Sunday
Dec 25 December, 2033 is Sunday
Dec 25, 2039
2037 is the last year we can specify
Dec 25, 2044
Dec 25, 2050
Dec 25, 2061
Dec 25, 2067
Dec 25, 2072
Dec 25, 2078
Dec 25, 2089
Dec 25, 2095
Dec 25, 2101
Dec 25, 2107
Dec 25, 2112
Dec 25, 2118
</pre>
<syntaxhighlight lang="freebasic">' version 17-06-2015
' Weekday And DateSerial only works with #Include "vbcompat.bi"
' compile with: fbc -s console
 
#Include Once "vbcompat.bi"
=={{header|C++}}==
Dim As Double a
<lang cpp>#include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
 
For yr As Integer = 2008 To 2121
int main( ) {
a = DateSerial (yr, 12, 25)
using namespace boost::gregorian ;
If Weekday(a) = 1 Then Print Format(a, "dd-mm-yyyy") ' 1 = sunday, 2 = monday ...
Next
 
' empty keyboard buffer
std::cout
While InKey <> "" : Wend
<< "Yuletide holidays must be allowed in the following years:\n" ;
Print : Print "hit any key to end program"
for ( int i = 2008 ; i < 2121 ; i++ ) {
Sleep
greg_year gy = i ;
End</syntaxhighlight>
date d ( gy, Dec , 25 ) ;
{{out}}
if ( d.day_of_week( ) == Sunday ) {
<pre>25-12-2011
std::cout << i << std::endl ;
25-12-2016
}
25-12-2022
}
25-12-2033
std::cout << "\n" ;
25-12-2039
return 0 ;
25-12-2044
}</lang>
25-12-2050
This produces the following output:
25-12-2061
25-12-2067
25-12-2072
25-12-2078
25-12-2089
25-12-2095
25-12-2101
25-12-2107
25-12-2112
25-12-2118</pre>
 
==={{header|FutureBasic}}===
<syntaxhighlight lang="futurebasic">window 1
 
long y
CFDateRef dt
NSInteger day
CFCalendarRef cal
DateComponentsRef comps
 
cal = fn CalendarCurrent
 
comps = fn DateComponentsInit
DateComponentsSetMonth( comps, 12 )
DateComponentsSetDay( comps, 25 )
 
for y = 2008 to 2121
DateComponentsSetYear( comps, y )
dt = fn CalendarDateFromComponents( cal, comps )
day = fn CalendarComponentFromDate( cal, NSCalendarUnitWeekday, dt )
if ( day == 1 )
print y
end if
next
 
HandleEvents</syntaxhighlight>
 
==={{header|Gambas}}===
'''[https://gambas-playground.proko.eu/?gist=b9b4e9a871e96ea6f1db467fa23669fe Click this link to run this code]'''
<syntaxhighlight lang="gambas">Public Sub Main()
Dim siCount As Short
 
For siCount = 2008 To 2121
If WeekDay(Date(siCount, 12, 25)) = 0 Then Print Format(Date(siCount, 12, 25), "dddd dd mmmm yyyy") & " falls on a Sunday"
Next
 
End</syntaxhighlight>
Output:
<pre>
Sunday 25 December 2011 falls on a Sunday
Sunday 25 December 2016 falls on a Sunday
Sunday 25 December 2022 falls on a Sunday
Sunday 25 December 2033 falls on a Sunday
Sunday 25 December 2039 falls on a Sunday
Sunday 25 December 2044 falls on a Sunday
Sunday 25 December 2050 falls on a Sunday
Sunday 25 December 2061 falls on a Sunday
Sunday 25 December 2067 falls on a Sunday
Sunday 25 December 2072 falls on a Sunday
Sunday 25 December 2078 falls on a Sunday
Sunday 25 December 2089 falls on a Sunday
Sunday 25 December 2095 falls on a Sunday
Sunday 25 December 2101 falls on a Sunday
Sunday 25 December 2107 falls on a Sunday
Sunday 25 December 2112 falls on a Sunday
Sunday 25 December 2118 falls on a Sunday
</pre>
 
==={{header|GW-BASIC}}===
{{works with|BASICA}}
<syntaxhighlight lang="gwbasic">10 REM Day of the week
20 DEFINT D, M, Y-Z
30 M = 12: D = 25
40 FOR Y = 2007 TO 2122
50 GOSUB 200
60 IF Z = 0 THEN PRINT Y;
70 NEXT Y
80 PRINT
90 END
170 REM Calculate day of week Z given
180 REM year Y, month M, and day D
190 REM Sunday = 0, Saturday = 6
200 IF M < 3 THEN Y = Y - 1: M = M + 12
210 Z = Y + Y \ 4 - Y \ 100 + Y \ 400
220 Z = Z + D + (153 * M + 8) \ 5
230 Z = Z MOD 7
240 RETURN</syntaxhighlight>
{{out}}
<pre>
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 PROGRAM "Dayweek.bas"
110 PRINT "The years between 2008 and 2121 will the 25th of December be a Sunday:"
120 FOR Y=2008 TO 2121
130 IF DAYWEEK(Y,12,25)=0 THEN PRINT "Dec 25,";Y
140 NEXT
150 DEF DAYWEEK(Y,M,D)
160 LET A=INT((14-M)/12):LET Y=Y-A
170 LET W=D+INT((13*(M+12*A-2)-1)/5)+Y+INT(Y/4)-INT(Y/100)+INT(Y/400)
180 LET DAYWEEK=W-7*INT(W/7)
190 END DEF</syntaxhighlight>
 
==={{header|Liberty BASIC}}===
{{works with|Just BASIC}}
<syntaxhighlight lang="lb">count = 0
for year = 2008 to 2121
dateString$="12/25/";year
dayNumber=date$(dateString$)
if dayNumber mod 7 = 5 then
count = count + 1
print dateString$
end if
next year
print count; " years when Christmas Day falls on a Sunday"
end</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
{{works with|IS-BASIC}}
<syntaxhighlight lang="gwbasic">10 REM Find years with Sunday Christmas
20 LET F = 2008
30 LET T = 2121
40 PRINT "Sunday Christmases"; F; "-"; T
50 PRINT
60 FOR Y = F TO T
70 LET E = Y*365+INT(Y/4)-INT(Y/100)+INT(Y/400)
80 LET X = E-6
90 LET D = X-7*INT(X/7)
100 IF D <> 0 THEN 120
110 PRINT Y,
120 NEXT Y
130 PRINT
140 END</syntaxhighlight>
 
==={{header|MSX Basic}}===
{{works with|Chipmunk Basic}}
{{works with|QBasic}}
{{works with|Quite BASIC}}
<syntaxhighlight lang="qbasic">10 REM Find years with Sunday Christmas
11 CLS
20 LET F = 2008
30 LET T = 2121
40 PRINT "Sunday Christmases"; F; "-"; T
50 PRINT
60 FOR Y = F TO T
70 LET E = Y * 365 + INT(Y/4) - INT(Y/100) + INT(Y/400)
80 LET X = E - 6
90 LET D = X - 7 * INT(X/7)
100 IF D <> 0 THEN 120
110 PRINT Y; " ";
120 NEXT Y
130 PRINT
140 END</syntaxhighlight>
 
==={{header|Palo Alto Tiny BASIC}}===
{{trans|GW-BASIC}}
<syntaxhighlight lang="basic">10 REM DAY OF THE WEEK
20 LET M=12,D=25
30 FOR Y=2007 TO 2122
40 GOSUB 200
50 IF Z=0 PRINT Y," ",
60 NEXT Y
70 PRINT
80 STOP
170 REM CALCULATE DAY OF WEEK Z GIVEN
180 REM YEAR Y, MONTH M, AND DAY D
190 REM SUNDAY = 0, SATURDAY = 6
200 IF M<3 LET Y=Y-1,M=M+12
210 LET Z=Y+Y/4-Y/100+Y/400
220 LET Z=Z+D+(153*M+8)/5
230 LET Z=Z-(Z/7)*7
240 RETURN</syntaxhighlight>
{{out}}
<pre> 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</pre>
 
==={{header|PureBasic}}===
PureBasic's internal Date() is limited between 1970-01-01 00:00:00 and 2038-01-19 03:14:07
<syntaxhighlight lang="purebasic">For i=2008 To 2037
If DayOfWeek(Date(i,12,25,0,0,0))=0
PrintN(Str(i))
EndIf
Next</syntaxhighlight>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">FOR yr = 2008 TO 2121
IF wd(12, 25, yr) = 0 THEN PRINT "Dec 25 "; yr
NEXT yr
END
 
FUNCTION wd (m, d, y)
IF m < 3 THEN
LET m = m + 12
LET y = y - 1
END IF
wd = ((y + INT(y / 4) - INT(y / 100) + INT(y / 400) + d + INT((153 * m + 8) / 5)) MOD 7)
END FUNCTION</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|QL SuperBASIC}}===
<b>Works with:</b> [https://en.wikipedia.org/wiki/Sinclair_QL ''Sinclair QL''] <br>
...having a structured [https://en.wikipedia.org/wiki/SuperBASIC ''BASIC''] with MOD and quite unlike the ZX81's "first-generation"
BASIC that's rather like using a calculator (also without an integer type). Even so, it's worth the minor effort to optimise the
code for the task at hand, as done below - which if implemented for the ZX81's routine would make it finish in a fraction of a
second, even in SLOW mode, as multiplying by 13 with a division by 5 is slower than by 256 alone, as well as that two divisions by
multiples of 100 are much slower than one by 16 as at the link. N.B. by relying on strings to have 4-digit years, this routine is not y10k-compliant
<syntaxhighlight lang="qbasic">
AUTO 100,10
DEF PROC Iso(S,O)
REM passing starting & ending years via integers S & O
LOCal y$,m%,d%,i$,n%,w%
LET m%=12 : d%=25
REM m% & d% are constants, so avoid recalculating n% (=48) each iteration
LET i$=m%*256+ 19300 : n%=i$(2 TO 3)+ d%
FOR count=S TO O
LET y$=count : w%=(y$(1 TO 2)&"32"DIV 16+ count DIV 4+ count+ n%)MOD 7
REM otherwise w%=(y$(1 TO 2)&"16"DIV 16+ count DIV 4+ count)MOD 7
REM = further optimisation beyond skipping irrelevant years:
IF w%=0 THEN PRINT count : count = count+ 4
END FOR count
END DEF Iso
 
ctrl+space
</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
==={{header|Quite BASIC}}===
The [[#MSX Basic|MSX Basic]] solution works without any changes.
 
==={{header|Run BASIC}}===
<syntaxhighlight lang="runbasic">for year = 2008 to 2121
if val(date$("12-25-";year)) mod 7 = 5 then print "For ";year;"xmas is Sunday"
next year</syntaxhighlight><pre>
For 2011 xmas is Sunday
For 2016 xmas is Sunday
For 2022 xmas is Sunday
For 2033 xmas is Sunday
For 2039 xmas is Sunday
For 2044 xmas is Sunday
For 2050 xmas is Sunday
For 2061 xmas is Sunday
For 2067 xmas is Sunday
For 2072 xmas is Sunday
For 2078 xmas is Sunday
For 2089 xmas is Sunday
For 2095 xmas is Sunday
For 2101 xmas is Sunday
For 2107 xmas is Sunday
For 2112 xmas is Sunday
For 2118 xmas is Sunday
</pre>
 
==={{header|S-BASIC}}===
<syntaxhighlight lang="basic">
$constant SUNDAY = 0
 
rem - compute p mod q
function mod(p, q = integer) = integer
end = p - q * (p/q)
 
comment
return day of week (Sun = 0, Mon = 1, etc.) for a
given Gregorian calendar date using Zeller's congruence
end
function dayofweek (mo, da, yr = integer) = integer
var y, c, z = integer
if mo < 3 then
begin
mo = mo + 10
yr = yr - 1
end
else mo = mo - 2
y = mod(yr,100)
c = int(yr / 100)
z = int((26 * mo - 2) / 10)
z = z + da + y + int(y/4) + int(c/4) - 2 * c + 777
z = mod(z,7)
end = z
 
rem - main program
var year = integer
print "Christmas will fall on a Sunday in"
for year=2008 to 2121
if dayofweek(12,25,year) = SUNDAY then
print year
next year
end
</syntaxhighlight>
{{out}}
<pre>Christmas will fall on a Sunday in
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
==={{header|Sinclair ZX81 BASIC}}===
{{trans|C}}
Works with 1k of RAM. Follows the C code quite closely: the only factors that perhaps make it less readable are (a) the absence of a modulo operator and (b) the need for continual calls to <code>INT</code> because we don't have an integer type. The performance is pretty acceptable; seconds rather than minutes.
<syntaxhighlight lang="zxbasic"> 10 LET M=12
20 LET D=25
30 FOR Y=2008 TO 2121
40 GOSUB 80
50 IF W=0 THEN PRINT Y
60 NEXT Y
70 STOP
80 LET A=INT ((14-M)/12)
90 LET MM=M+12*A-2
100 LET YY=Y-A
110 LET W=D+INT ((13*MM-1)/5)+YY+INT (YY/4)-INT (YY/100)+INT (YY/400)
120 LET W=W-7*INT (W/7)
130 RETURN</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
==={{header|TI-83 BASIC}}===
{{Works with|TI-84+/SE}} only
<syntaxhighlight lang="ti83b">
:For(A,2008,2121
:If dayofWk(A,12,25)=1
:Disp A
:End
</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
Done</pre>
 
==={{header|Tiny BASIC}}===
{{works with|TinyBasic}}
<syntaxhighlight lang="basic">10 REM Day of the week
20 LET Y = 2007
30 LET M = 12
40 LET D = 25
50 IF Y = 2122 THEN END
60 LET Y = Y + 1
70 GOSUB 200
80 IF Z = 0 THEN PRINT Y
90 GOTO 50
170 REM Calculate day of week Z given
180 REM year Y, month M, and day D
190 REM Sunday = 0, Saturday = 6
200 IF M < 3 THEN LET Y = Y - 1
210 IF M < 3 THEN LET M = M + 12
220 LET Z = Y + Y / 4 - Y / 100 + Y / 400
230 LET Z = Z + D + (153 * M + 8) / 5
240 LET Z = Z - 7 * (Z / 7)
250 RETURN</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">FUNCTION wd (m, d, y)
IF m < 3 THEN
LET m = m + 12
LET y = y - 1
END IF
LET wd = REMAINDER ((y + INT(y / 4) - INT(y / 100) + INT(y / 400) + d + INT((153 * m + 8) / 5)), 7)
END FUNCTION
 
FOR yr = 2008 TO 2121
IF wd(12, 25, yr) = 0 THEN PRINT "Dec 25 "; yr
NEXT yr
END</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|VBA}}===
<syntaxhighlight lang="vb">Option Explicit
 
Sub MainDayOfTheWeek()
Debug.Print "Xmas will be a Sunday in : " & XmasSunday(2008, 2121)
End Sub
 
Private Function XmasSunday(firstYear As Integer, lastYear As Integer) As String
Dim i As Integer, temp$
For i = firstYear To lastYear
If Weekday(CDate("25/12/" & i)) = vbSunday Then temp = temp & ", " & i
Next
XmasSunday = Mid(temp, 2)
End Function</syntaxhighlight>
 
{{Out}}
<pre>Xmas will be a Sunday in : 2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118</pre>
 
==={{header|VBScript}}===
<syntaxhighlight lang="vb">For year = 2008 To 2121
If Weekday(DateSerial(year, 12, 25)) = 1 Then
WScript.Echo year
End If
Next</syntaxhighlight>
{{Out}}
<pre>
Yuletide holidays must be allowed in the following years:
2011
2016
Line 310 ⟶ 1,316:
2118
</pre>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="xbasic">PROGRAM "progname"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
DECLARE FUNCTION wd (m, d, y)
 
FUNCTION Entry ()
FOR yr = 2008 TO 2121
IF wd(12, 25, yr) = 0 THEN PRINT "Dec 25 "; yr
NEXT yr
 
END FUNCTION
 
FUNCTION wd (m, d, y)
IF m < 3 THEN
m = m + 12
DEC y
END IF
RETURN ((y + INT(y / 4) - INT(y / 100) + INT(y / 400) + d + INT((153 * m + 8) / 5)) MOD 7)
END FUNCTION
END PROGRAM</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="yabasic">sub wd(m, d, y)
If m < 3 Then // If m = 1 Or m = 2 Then
m = m + 12
y = y - 1
End If
Return mod((y + int(y / 4) - int(y / 100) + int(y / 400) + d + int((153 * m + 8) / 5)), 7)
End sub
// ------=< MAIN >=------
For yr = 2008 To 2121
If wd(12, 25, yr) = 0 Then
Print "Dec 25 ", yr
EndIf
Next</syntaxhighlight>
 
==={{header|ZX Spectrum Basic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="zxbasic">10 CLS
20 FOR y=2008 TO 2121
30 LET year=y: LET m=12: LET d=25: GO SUB 1000
40 IF wd=0 THEN PRINT d;" ";m;" ";y
50 NEXT y
60 STOP
1000 REM week day
1010 IF m=1 OR m=2 THEN LET m=m+12: LET year=year-1
1020 LET wd=FN m(year+INT (year/4)-INT (year/100)+INT (year/400)+d+INT ((153*m+8)/5),7)
1030 RETURN
1100 DEF FN m(a,b)=a-INT (a/b)*b</syntaxhighlight>
 
=={{header|Batch File}}==
<syntaxhighlight lang="dos">:: Day of the Week task from Rosetta Code
:: Batch File Implementation
:: Question: In what years between 2008 and 2121 will the 25th of December be a Sunday?
:: Method: Zeller's Rule
 
@echo off
rem set month code for December
set mon=33
rem set day number
set day=25
 
for /L %%y in (2008,1,2121) do (
setlocal enabledelayedexpansion
set /a "a=%%y/100"
set /a "b=%%y-(a*100)"
set /a "weekday=(day+mon+b+(b/4)+(a/4)+(5*a))%%7"
if "!weekday!"=="1" echo(Dec 25, %%y is a Sunday.
endlocal
)
pause
exit /b 0</syntaxhighlight>
{{out}}
<pre>Dec 25, 2011 is a Sunday.
Dec 25, 2016 is a Sunday.
Dec 25, 2022 is a Sunday.
Dec 25, 2033 is a Sunday.
Dec 25, 2039 is a Sunday.
Dec 25, 2044 is a Sunday.
Dec 25, 2050 is a Sunday.
Dec 25, 2061 is a Sunday.
Dec 25, 2067 is a Sunday.
Dec 25, 2072 is a Sunday.
Dec 25, 2078 is a Sunday.
Dec 25, 2089 is a Sunday.
Dec 25, 2095 is a Sunday.
Dec 25, 2101 is a Sunday.
Dec 25, 2107 is a Sunday.
Dec 25, 2112 is a Sunday.
Dec 25, 2118 is a Sunday.
Press any key to continue . . .</pre>
 
=={{header|bc}}==
Because ''bc'' has no date library, this program uses [http://mathforum.org/library/drmath/view/62324.html ''Zeller's rule''], also known as [http://www.merlyn.demon.co.uk/zel-like.htm ''Zeller's congruence''], to calculate day of week.
 
<syntaxhighlight lang="bc">scale = 0
 
/*
* Returns day of week (0 to 6) for year, month m, day d in proleptic
* Gregorian calendar. Sunday is 0. Assumes y >= 1, scale = 0.
*/
define w(y, m, d) {
auto a
 
/* Calculate Zeller's congruence. */
a = (14 - m) / 12
m += 12 * a
y -= a
return ((d + (13 * m + 8) / 5 + \
y + y / 4 - y / 100 + y / 400) % 7)
}
 
for (y = 2008; y <= 2121; y++) {
/* If December 25 is a Sunday, print year. */
if (w(y, 12, 25) == 0) y
}
quit</syntaxhighlight>
 
=={{header|BCPL}}==
<syntaxhighlight lang="bcpl">get "libhdr"
 
let weekday(y, m, d) =
m<3 -> wd((y-1)/100, (y-1) rem 100, m + 10, d),
wd(y/100, y rem 100, m - 2, d)
and wd(c, y, m, d) =
((26*m-2)/10 + d + y + y/4 + c/4 - 2 * c + 777) rem 7
 
let start() be
for year = 2008 to 2121
if weekday(year, 12, 25) = 0
do writef("%N*N", year)</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
=={{header|Befunge}}==
Befunge doesn't have any standard date-handling functionality, so we calculate the day of the week directly using a simple variation of the Zeller rule.
 
<syntaxhighlight lang="befunge">8 >:"2("*+::::4/+\"d"/-\45v
@_^#`"y": +1$<_v#%7+1+/*:*<
>:#,_>$:.55+,^ >0" ,52 ceD"</syntaxhighlight>
 
{{out}}
<pre>Dec 25, 2011
Dec 25, 2016
Dec 25, 2022
Dec 25, 2033
Dec 25, 2039
Dec 25, 2044
Dec 25, 2050
Dec 25, 2061
Dec 25, 2067
Dec 25, 2072
Dec 25, 2078
Dec 25, 2089
Dec 25, 2095
Dec 25, 2101
Dec 25, 2107
Dec 25, 2112
Dec 25, 2118</pre>
 
=={{header|Bracmat}}==
{{trans|C}}
<syntaxhighlight lang="bracmat">{ Calculate day of week in proleptic Gregorian calendar. Sunday == 0. }
( wday
= year month day adjustment mm yy
. !arg:(?year,?month,?day)
& div$(14+-1*!month,12):?adjustment
& !month+12*!adjustment+-2:?mm
& !year+-1*!adjustment:?yy
& mod
$ ( !day
+ div$(13*!mm+-1,5)
+ !yy
+ div$(!yy,4)
+ -1*div$(!yy,100)
+ div$(!yy,400)
, 7
)
)
& 2008:?y
& whl
' ( !y:~>2121
& ( wday$(!y,12,25):0
& put$(str$(!y "-12-25\n"))
|
)
& 1+!y:?y
)
& done;</syntaxhighlight>
{{out}}
<pre>2011-12-25
2016-12-25
2022-12-25
2033-12-25
2039-12-25
2044-12-25
2050-12-25
2061-12-25
2067-12-25
2072-12-25
2078-12-25
2089-12-25
2095-12-25
2101-12-25
2107-12-25
2112-12-25
2118-12-25</pre>
 
=={{header|C}}==
Because of problems with various C libraries (such as ''time_t'' overflowing during 2038, or strptime() or mktime() not filling in ''tm_wday''), this program uses [http://mathforum.org/library/drmath/view/62324.html Zeller's Rule] to calculate day of week.
 
<syntaxhighlight lang="c">#include <stdio.h>
 
/* Calculate day of week in proleptic Gregorian calendar. Sunday == 0. */
int wday(int year, int month, int day)
{
int adjustment, mm, yy;
 
adjustment = (14 - month) / 12;
mm = month + 12 * adjustment - 2;
yy = year - adjustment;
return (day + (13 * mm - 1) / 5 +
yy + yy / 4 - yy / 100 + yy / 400) % 7;
}
 
int main()
{
int y;
 
for (y = 2008; y <= 2121; y++) {
if (wday(y, 12, 25) == 0) printf("%04d-12-25\n", y);
}
 
return 0;
}</syntaxhighlight>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
 
class Program
Line 321 ⟶ 1,587:
{
DateTime date = new DateTime(i, 12, 25);
 
if (date.DayOfWeek == DayOfWeek.Sunday)
{
Line 327 ⟶ 1,592:
}
}
 
}
}</langsyntaxhighlight>
 
Using LINQ:
<syntaxhighlight lang="csharp">using System;
 
<lang csharp>using System;
using System.Linq;
 
class Program
{
static void Main(string[] args)
{
string[] days = (from day in
(from year in Enumerable.Range(2008, 2121 - 2007)
select new DateTime(year, 12, 25))
where day.DayOfWeek == DayOfWeek.Sunday
select day.ToString("dd MMM yyyy")).ToArray();
 
foreach (string day in days) Console.WriteLine(day);
}
}</lang>
 
This looks better:
 
<lang csharp>using System;
using System.Linq;
 
Line 366 ⟶ 1,610:
foreach (string day in days) Console.WriteLine(day);
}
}</syntaxhighlight>Lambda expressions FTW:
}</lang>
<syntaxhighlight lang="csharp">using System;
 
Lambda expressions FTW:
 
<lang csharp>using System;
using System.Linq;
 
Line 382 ⟶ 1,623:
.ForEach(ent => Console.WriteLine(ent.ToString("dd MMM yyyy")));
}
}</langsyntaxhighlight>
{{out}}
 
<pre style="height:20ex;overflow:scroll">25 Dec 2011
25 Dec 2016
25 Dec 2022
Line 401 ⟶ 1,642:
25 Dec 2112
25 Dec 2118</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <chrono>
#include <ranges>
#include <iostream>
 
int main() {
std::cout << "Yuletide holidays must be allowed in the following years:\n";
for (int year : std::views::iota(2008, 2121)
| std::views::filter([](auto year) {
if (std::chrono::weekday{
std::chrono::year{year}/std::chrono::December/25}
== std::chrono::Sunday) {
return true;
}
return false;
})) {
std::cout << year << '\n';
}
}</syntaxhighlight>
{{out}}
<pre>
Yuletide holidays must be allowed in the following years:
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|Clojure}}==
Utilizing Java interop
 
<syntaxhighlight lang="clojure">(import '[java.util GregorianCalendar])
<lang clojure>
(import '(java.util GregorianCalendar))
(defn yuletide [start end]
(->> (range start (inc end))
(filter #(= (. (new GregorianCalendar %
(filter #(= GregorianCalendar/SUNDAY
(. GregorianCalendar DECEMBER) 25) get (. GregorianCalendar DAY_OF_WEEK))
(.get (GregorianCalendar. % GregorianCalendar/DECEMBER 25)
(. GregorianCalendar SUNDAY)) (range start (inc end))))
GregorianCalendar/DAY_OF_WEEK)))))
 
(println (yuletide 2008 2121))
</syntaxhighlight>
 
{{out}}
(yuletide 2008 2121)
</lang>
<pre>(2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118)</pre>
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">weekday = proc (d: date) returns (int)
y: int := d.year
m: int := d.month
if m<3
then y, m := y-1, m+10
else m := m-2
end
c: int := y/100
y := y//100
z: int := (26*m-2)/10 + d.day + y + y/4 + c/4 - 2*c + 777
return(z//7)
end weekday
 
start_up = proc ()
po: stream := stream$primary_output()
for year: int in int$from_to(2008, 2121) do
if weekday(date$create(25, 12, year, 0, 0, 0))=0 then
stream$putl(po, int$unparse(year))
end
end
end start_up</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
=={{header|COBOL}}==
Using Date Intrinsic Functions
<syntaxhighlight lang="cobol">
program-id. dec25.
data division.
working-storage section.
1 work-date.
2 yr pic 9(4) value 2008.
2 mo-da pic 9(4) value 1225. *> Dec 25
1 wk-date redefines work-date pic 9(8).
1 binary.
2 int-date pic 9(8).
2 dow pic 9(4).
procedure division.
perform varying yr from 2008 by 1
until yr > 2121
compute int-date = function integer-of-date (wk-date)
compute dow = function mod ((int-date - 1) 7) + 1
if dow = 7 *> Sunday = 7 per ISO 8601 and ISO 1989
display yr
end-if
end-perform
stop run
.
end program dec25.
</syntaxhighlight>
{{out}}
<pre style="height:20ex;overflow:scroll">
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
Without Date Intrinsic Functions
 
<syntaxhighlight lang="cobol">
identification division.
program-id. dowtest.
data division.
working-storage section.
01 ws-inp-date pic x(08).
01 filler redefines ws-inp-date.
03 ws-inp-year pic 9(04).
01 ws-dow pic 9(05).
procedure division.
move '00001225' to ws-inp-date
perform test before
varying ws-inp-year from 2008 by +1
until ws-inp-year > 2121
call "todow" using
by reference ws-inp-date
by reference ws-dow
if ws-dow = 1 then
display 'year=' ws-inp-year
end-if
end-perform
stop run.
end program dowtest.
identification division.
program-id. todow.
environment division.
input-output section.
file-control.
data division.
file section.
working-storage section.
01 tally pic 9(05).
01 wms-work-area.
03 wms-year pic 9(04).
03 wms-month pic 9(02).
03 wms-csys pic 9(01) value 1.
03 wms-sum pic 9(05).
linkage section.
01 lkip-date.
03 lkip-date-year pic 9(04).
03 lkip-date-month pic 9(02).
03 lkip-date-day pic 9(02).
01 lkop-dow pic 9(05).
88 lkop-sunday value 1.
procedure division using
by reference lkip-date
by reference lkop-dow
.
if lkip-date-month < 3
compute wms-month = lkip-date-month + 12
compute wms-year = lkip-date-year - 1
else
compute wms-month = lkip-date-month
compute wms-year = lkip-date-year
end-if
compute wms-sum =
( lkip-date-day + 2 * wms-month + wms-year
+ function integer (6 * (wms-month + 1) / 10)
+ function integer ( wms-year / 4 )
- function integer ( wms-year / 100 )
+ function integer ( wms-year / 400 )
+ wms-csys )
compute lkop-dow = function mod (wms-sum, 7) + 1
.
end program todow.
</syntaxhighlight>
{{out}}
<pre style="height:20ex;overflow:scroll">
year=2011
year=2016
year=2022
year=2033
year=2039
year=2044
year=2050
year=2061
year=2067
year=2072
year=2078
year=2089
year=2095
year=2101
year=2107
year=2112
year=2118
</pre>
 
=={{header|CoffeeScript}}==
<syntaxhighlight lang="coffeescript">december = 11 # gotta love Date APIs :)
sunday = 0
for year in [2008..2121]
xmas = new Date year, december, 25
console.log year if xmas.getDay() is sunday</syntaxhighlight>one-liner:<syntaxhighlight lang="coffeescript">console.log year for year in [2008...2121] when new Date(year, 11, 25).getDay() is 0</syntaxhighlight>
{{out}}
<pre style="height:20ex;overflow:scroll">
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|ColdFusion}}==
<syntaxhighlight lang="coldfusion">
<lang ColdFusion>
<cfloop from = "2008" to = "2121" index = "i">
<cfset myDate = createDate(i, 12, 25) />
Line 425 ⟶ 1,916:
</cfif>
</cfloop>
</syntaxhighlight>
</lang>
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(loop for year from 2008 upto 2121
when (= 6 (multiple-value-bind
(second minute hour date month year day-of-week dst-p tz)
(decode-universal-time (encode-universal-time 0 0 0 25 12 year))
(declare (ignore second minute hour date month year dst-p tz))
day-of-week))
collect year)</langsyntaxhighlight>
 
<syntaxhighlight lang="lisp">(loop for year from 2008 upto 2121
for xmas = (encode-universal-time 0 0 0 25 12 year)
for day = (nth-value 6 (decode-universal-time xmas))
when (= day 6) collect year)</syntaxhighlight>
 
=={{header|Component Pascal}}==
{{Works with|BlackBox Component Builder}}
<syntaxhighlight lang="oberon2">
MODULE DayOfWeek;
IMPORT DevCommanders, TextMappers, Dates, StdLog;
 
PROCEDURE XmastOnSun(s,e: INTEGER);
VAR
i: INTEGER;
d: Dates.Date;
BEGIN
i := s;d.day := 25;d.month := 12;
WHILE i < e DO
d.year := i;
IF Dates.DayOfWeek(d) = Dates.sunday THEN
StdLog.Int(i);StdLog.Ln
END;
INC(i)
END
END XmastOnSun;
 
PROCEDURE Do*;
VAR
s: TextMappers.Scanner;
r: ARRAY 2 OF INTEGER;
i: INTEGER;
BEGIN
s.ConnectTo(DevCommanders.par.text);
s.SetPos(DevCommanders.par.beg);
s.Scan;i := 0;
WHILE ~s.rider.eot DO
IF s.type = TextMappers.int THEN
r[i] := s.int; INC(i)
END;
s.Scan
END;
XmastOnSun(r[0],r[1]);
END Do;
 
END DayOfWeek.
</syntaxhighlight>
Execute: ^Q DayOfWeek.Do 2008 2121~
{{out}}
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|Cowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub weekday(year: uint16, month: uint8, day: uint8): (wd: uint8) is
if month < 3 then
month := month + 10;
year := year - 1;
else
month := month - 2;
end if;
var c := year / 100;
var y := year % 100;
var z := (26 * month as uint16 - 2) / 10;
z := z + day as uint16 + y + (y / 4) + (c / 4) - 2 * c + 777;
wd := (z % 7) as uint8;
end sub;
 
var year: uint16 := 2008;
while year <= 2121 loop
if weekday(year, 12, 25) == 0 then
print_i16(year);
print_nl();
end if;
year := year + 1;
end loop;</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
 
=={{header|D}}==
<syntaxhighlight lang="d">void main() {
{{works with|D|2}}
<lang d> import std.stdio, std.datetimerange, std.convalgorithm, std.datetime;
 
writeln("Christmas comes on a Sunday in the years:\n",
void main() {
foreach (year; 2008 .. iota(2008, 2122)
if .filter!(0y ==> Date.fromSimpleString(to!string(year)y, ~12, "-Dec-25").dayOfWeek( == DayOfWeek.sun)) {;
}</syntaxhighlight>
writefln("Christmas comes on a sunday in %d", year);
{{out}}
}
<pre>Christmas comes on a Sunday in the years:
}</lang>
[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]</pre>
 
=={{header|Delphi}}==
{{libheader|sysutils}} always in uses clause in Delphi
<lang delphi>procedure IsXmasSunday(fromyear, toyear: integer);
<syntaxhighlight lang="delphi">procedure IsXmasSunday(fromyear, toyear: integer);
var
i: integer;
Line 462 ⟶ 2,069:
end;
end;
//CONSOLE
//writeln(outputyears);
//GUI
form1.label1.caption := outputyears;
end;</langsyntaxhighlight>
 
Procedure called with year range to test and outputs a space-delimited array of years to a label. There is no error check that fromyear < toyear, but this is easily added.
 
{{out}}
output:
<pre>
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc nonrec weekday(word y, m, d) byte:
word c;
if m<3 then
m := m+10;
y := y+1
else
m := m-2
fi;
c := y/100;
y := y%100;
((26 * m - 2)/10 + d + y + y/4 + c/4 - 2*c + 777) % 7
corp
 
proc nonrec main() void:
word year;
for year from 2008 upto 2121 do
if weekday(year, 12, 25)=0 then
writeln(year)
fi
od
corp</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
func dayOfTheWeek year month day .
# Based on Conway's doomsday algorithm
# 1. Calculate the doomsday for the century
century = floor (year / 100)
if century mod 4 = 0
centuryDoomsday = 2
elif century mod 4 = 1
centuryDoomsday = 0
elif century mod 4 = 2
centuryDoomsday = 5
elif century mod 4 = 3
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
leap = 1
else
leap = 0
.
else
if mainYear mod 4 = 0
leap = 1
else
leap = 0
.
.
# 4. Calculate the DOTW of January 1
if leap = 1
januaryOne = (yearDoomsday + 4) mod 7
else
januaryOne = (yearDoomsday + 5) mod 7
.
# 5. Determine the nth day of the year
if month = 1
NthDay = 0
elif month = 2
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
return (januaryOne + NthDay - 1) mod 7
.
for i = 2008 to 2121
if dayOfTheWeek i 12 25 = 0
print "Christmas in " & i & " is on Sunday"
.
.
</syntaxhighlight>
{{out}}
<pre>
Christmas in 2011 is on Sunday
Christmas in 2016 is on Sunday
Christmas in 2022 is on Sunday
Christmas in 2033 is on Sunday
Christmas in 2039 is on Sunday
Christmas in 2044 is on Sunday
Christmas in 2050 is on Sunday
Christmas in 2061 is on Sunday
Christmas in 2067 is on Sunday
Christmas in 2072 is on Sunday
Christmas in 2078 is on Sunday
Christmas in 2089 is on Sunday
Christmas in 2095 is on Sunday
Christmas in 2101 is on Sunday
Christmas in 2107 is on Sunday
Christmas in 2112 is on Sunday
Christmas in 2118 is on Sunday
</pre>
 
=={{header|ECL}}==
<syntaxhighlight lang="ecl">//In what years between 2008 and 2121 will the 25th of December be a Sunday?
 
IMPORT STD;
BaseYear := 2008;
EndYear := 2121;
 
ChristmasDay := RECORD
UNSIGNED1 DayofWeek;
UNSIGNED2 Year;
END;
 
ChristmasDay FindDate(INTEGER Ctr) := TRANSFORM
SELF.DayofWeek := (STD.Date.FromGregorianYMD((BaseYear-1) + Ctr,12,25)) % 7; //0=Sunday
SELF.Year := (BaseYear-1) + Ctr;
END;
 
YearDS := DATASET(EndYear-BaseYear,FindDate(COUNTER));
OUTPUT(YearDS(DayofWeek=0),{Year});
 
/* Outputs:
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
*/
</syntaxhighlight>
This code solves a specific task, but can easily be modified as a generic function to return the DayOfWeek for any day after 1 AD.
 
=={{header|EDSAC order code}}==
Uses a version of Zeller's congruence that finds the day of the week for any Gregorian date up to 28 Feb 43699.
<syntaxhighlight lang="edsac">
[Day of week for Rosetta Code.]
[EDSAC program, Initial Orders 2.]
 
[Library subroutine M3 - prints header and is then overwritten.]
[Here, the last character sets the teleprinter to figures.]
PF GK IF AF RD LF UF OF E@ A6F G@ E8F EZ PF
*CHRISTMAS!DAY!ON!SUNDAY@&#
..PZ [blank tape, then resync]
 
[Subroutine to find day of week in Gregorian calendar, by Zeller's method.]
[This EDSAC implementation is valid up to and including 28 Feb 43699.]
[Input: 4F = year, 5F = month, 6F = day of month (all preserved).]
[Output: 7F = day of week: 0 = Saturday, 1 = Sunday, ..., 6 = Friday.]
[Workspace: 0F]
T128K GK
A3F T41@ [plant return link as usual]
[January and February are taken as months 13 and 14 of the previous year]
A5F [load month]
S43@ [subtract 3 to test for Jan or Feb]
E9@ [jump if not Jan or Feb]
A45@ [add 16 to make month + 1]
T7F [to 7F]
S42@ [acc := -1]
G11@ [join common code]
[9] A44@ [not Jan, Feb; make month + 1]
T7F [to 7F; acc := 0]
[11] A4F [here with acc = 0 or -1; add year]
TF [adjusted year to 0F]
H46@ [mult reg := 13/20 (near enough)]
V7F [times (month + 1)]
L1F [shift 2 left]
T7F [7F := 13*(month + 1) div 5]
AF [year]
R1F [shift 2 right]
AF [year + (year div 4)]
A7F [add into 7F]
T7F
H47@ [mult reg := 64/100 (approx, OK for dates as above)]
VF [times year]
R16F [shift 6 right]
UF [0F := year div 100]
R1F [shift 2 more right]
SF [(year div 400) - (year div 100)]
A6F [add day of month]
A7F [add into 7F]
T7F
[Finally take 7F modulo 7. Suppose 7F = 7*q + r (0 <= r < 7)]
H48@ [mult reg := 4/7 (near enough)]
V7F [acc := 4*q + (4/7)*r]
R1F [shift 2 right: acc := q + r/7]
TF [0F := acc high word = q]
H49@ [mult reg := 7/8 (exact)]
A7F [acc := 7*q + r]
R2F [shift 3 right, acc := (7*q + r)/8]
NF [subtract (7/8)*q, acc := r/8]
L2F [shift 3 left, acc := r as required]
T7F [return result r in 7F]
[41] ZF [(planted) jump back to caller]
[Constants]
[42] PD [1]
[43] P1D [3]
[44] P2F [4]
[45] P8F [16]
[46] J819D [0.A667 hex, approx 13/20]
[47] J492F [0.A3D8 hex, approx 64/100]
[48] O293F [0.924A hex, approx 4/7]
[49] KF [0.1110 hex = 7/8]
 
[Subroutine to print non-negative 17-bit integer.]
[Parameters: 0F = integer to be printed (not preserved)
1F = character for leading zero (preserved)]
[Workspace: 4F..7F, 38 locations]
T64K
GK A3F T34@ A1F T7F S35@ T6F T4#F AF T4F H36@ V4F RD A4#F R1024F H37@ E23@ O7F A2F
T6F T5F V4#F YF L8F T4#F A5F L1024F UF A6F G16@ OF TF T7F A6F G17@ ZF P4F Z219D TF
 
[Main routine]
T400K GK
[Constants]
[0] P1004F [2008]
[1] P1060D [2121]
[2] P6F [12 (December)]
[3] P12D [25]
[4] PD [1]
[5] @F [carriage return]
[6] &F [line feed]
[7] K4096F [null char]
[Variable]
[8] PF [year]
[Enter with acc = 0]
[9] A7@ T1F [1F := null for print subroutine]
A@ [load first year]
[12] U8@ T4F [save year, and pass to Zeller subroutine]
A2@ T5F [pass month 12 to Zeller subroutine]
A3@ T6F [pass day 25 to Zeller subroutine]
A18@ G128F [call Zeller subroutine]
A7F S4@ [load day of week, subtract 1]
G32@ [jump if day = 0]
S4@ E32@ [subtract 1, jump if day >= 2]
TF [here if day = 1 (Sunday); clear acc]
A4F TF [pass year to print subroutine]
A28@ G64F [call print subroutine (overwrites 4F)]
O5@ O6@ [print CR, LF]
[32] TF [common code; clear acc]
A8@ S1@ [test for end]
E39@ [jump to exit if so]
A1@ [restore acc after test]
A4@ E12@ [inc year and loop back]
[39] O7@ [done; print null]
ZF [halt the machine]
 
E9Z [define entry point]
PF [acc = 0 on entry]
[end]
</syntaxhighlight>
{{out}}
<pre>
CHRISTMAS DAY ON SUNDAY
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|Elixir}}==
{{works with|Elixir|1.4}}
<syntaxhighlight lang="elixir">Enum.each(2008..2121, fn year ->
wday = Date.from_erl!({year, 12, 25}) |> Date.day_of_week
if wday==7, do: IO.puts "25 December #{year} is sunday"
end)</syntaxhighlight>
 
{{out}}
<pre>
25 December 2011 is sunday
25 December 2016 is sunday
25 December 2022 is sunday
25 December 2033 is sunday
25 December 2039 is sunday
25 December 2044 is sunday
25 December 2050 is sunday
25 December 2061 is sunday
25 December 2067 is sunday
25 December 2072 is sunday
25 December 2078 is sunday
25 December 2089 is sunday
25 December 2095 is sunday
25 December 2101 is sunday
25 December 2107 is sunday
25 December 2112 is sunday
25 December 2118 is sunday
</pre>
 
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">(require 'calendar)
 
(defun sunday-p (y)
"Is Dec 25th a Sunday in this year?"
(= (calendar-day-of-week (list 12 25 y)) 0))
 
(defun xmas-sunday (a b)
"In which years in the range a, b is Dec 25th a Sunday?"
(seq-filter #'sunday-p (number-sequence a b)))
 
(print (xmas-sunday 2008 2121))</syntaxhighlight>
{{output}}
<pre>(2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118)</pre>
 
=={{header|Erlang}}==
 
<syntaxhighlight lang="erlang">% Implemented by bengt kleberg
-module(yuletide).
-export([main/0, sunday_years/2]).
 
main() ->
[io:fwrite("25 December ~p is Sunday~n", [X]) || X <- sunday_years(2008, 2121)].
 
sunday_years( Start, Stop ) ->
[X || X <- lists:seq(Start, Stop), is_sunday(calendar:day_of_the_week({X, 12, 25}))].
 
is_sunday( 7 ) -> true;
is_sunday( _ ) -> false.</syntaxhighlight>
{{out}}
<pre>
25 December 2011 is Sunday
25 December 2016 is Sunday
25 December 2022 is Sunday
25 December 2033 is Sunday
25 December 2039 is Sunday
25 December 2044 is Sunday
25 December 2050 is Sunday
25 December 2061 is Sunday
25 December 2067 is Sunday
25 December 2072 is Sunday
25 December 2078 is Sunday
25 December 2089 is Sunday
25 December 2095 is Sunday
25 December 2101 is Sunday
25 December 2107 is Sunday
25 December 2112 is Sunday
25 December 2118 is Sunday
</pre>
 
=={{header|ERRE}}==
<syntaxhighlight lang="erre">
PROGRAM DAY_OF_THE_WEEK
 
PROCEDURE MODULO(X,Y->RES)
IF Y=0 THEN
RES=X
ELSE
RES=X-Y*INT(X/Y)
END IF
END PROCEDURE
 
PROCEDURE WD(M,D,Y->RES%)
IF M=1 OR M=2 THEN
M+=12
Y-=1
END IF
MODULO(365*Y+INT(Y/4)-INT(Y/100)+INT(Y/400)+D+INT((153*M+8)/5),7->RES)
RES%=RES+1.0
END PROCEDURE
 
BEGIN
PRINT(CHR$(12);) ! CLS
FOR YR=2008 TO 2121 DO
WD(12,25,YR->RES%)
IF RES%=1 THEN ! day 1 is Sunday......
PRINT("Dec";25;",";YR)
END IF
END FOR
GET(K$)
END PROGRAM
</syntaxhighlight>
{{out}}
<pre>Dec 25, 2011
Dec 25, 2016
Dec 25, 2022
Dec 25, 2033
Dec 25, 2039
Dec 25, 2044
Dec 25, 2050
Dec 25, 2061
Dec 25, 2067
Dec 25, 2072
Dec 25, 2078
Dec 25, 2089
Dec 25, 2095
Dec 25, 2101
Dec 25, 2107
Dec 25, 2112
Dec 25, 2118
</pre>
 
=={{header|Euphoria}}==
<syntaxhighlight lang="euphoria">
--Day of the week task from Rosetta Code wiki
--User:Lnettnay
--In what years between 2008 and 2121 will the 25th of December be a Sunday
 
include std/datetime.e
 
datetime dt
 
for year = 2008 to 2121 do
dt = new(year, 12, 25)
if weeks_day(dt) = 1 then -- Sunday = 1
? year
end if
end for
</syntaxhighlight>
{{out}}
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">open System
 
[ 2008 .. 2121 ]
|> List.choose (fun y -> if DateTime(y,12,25).DayOfWeek = DayOfWeek.Sunday then Some(y) else None)
|> printfn "%A"</syntaxhighlight>
{{out}}
<pre>[2011; 2016; 2022; 2033; 2039; 2044; 2050; 2061; 2067; 2072; 2078; 2089; 2095;
2101; 2107; 2112; 2118]</pre>
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: calendar math.ranges prettyprint sequences ;
<lang factor>2008 2121 [a,b] [ 12 25 <date> sunday? ] filter .</lang>
2008 2121 [a,b] [ 12 25 <date> sunday? ] filter .</syntaxhighlight>
 
=={{header|Forth}}==
Forth has only TIME&DATE, which does not give day of week. Many public Forth Julian date calculators had year-2100 problems, but this algorithm works well.
<syntaxhighlight lang ="forth">\ Zeller's Congruence
\ Zeller's Congruence
: zeller ( m -- days since March 1 )
: weekday 9( +d 12m mody 1-- wd) \ 26 10 */ 31 +mon..7 ;sun
over 3 < if 1- swap 12 + swap then
 
100 /mod
: weekday ( d m y -- 0..6 ) \ Monday..Sunday
overdup 34 </ ifswap 1-2* then-
swap dup 4 / + +
overswap 1001+ 13 5 */ -+ +
( in zeller 0=sat, so -2 to 0= mon, then mod, then 1+ for 1=mon)
over 400 / + +
swap2- zeller7 +mod 1+ ;
1+ 7 mod ;
 
: yuletide
." December 25 is Sunday in "
2122 2008 do
25 12 i weekday
67 = if i . then
loop cr ;
</syntaxhighlight>
 
<syntaxhighlight lang="forth">
cr yuletide
December 25 is Sunday in 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
ok
</syntaxhighlight>
 
cr yuletide
December 25 is Sunday in 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</lang>
 
To show year-2100 problems with SwiftForth's provided Modified Julian Day support:
 
<langsyntaxhighlight lang="forth">: yuletide
." December 25 is Sunday in "
2122 2008 do
Line 507 ⟶ 2,622:
 
cr yuletide
December 25 is Sunday in 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2100 2106 2117</langsyntaxhighlight>
 
In [[4tH]] a library is available which provides the right answer:
 
<syntaxhighlight lang="forth">include lib/time.4th
 
: yuletide
." December 25 is Sunday in "
2122 2008 do
25 12 i weekday
6 = if i . then
loop cr ;
 
cr yuletide</syntaxhighlight>
 
The code is derived from "Collected Algorithms from ACM", Volume 1 Algorithms 1-220.
 
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
Based on Forth example
<langsyntaxhighlight lang="fortran">PROGRAM YULETIDE
IMPLICIT NONE
Line 527 ⟶ 2,657:
FUNCTION Day_of_week(d, m, y)
INTEGER :: Day_of_week, j, k, mm, yy
INTEGER, INTENT(IN) :: d, m, y
j mm= y / 100m
k yy= MOD(y, 100)
IF(mm.le.2) THEN
Day_of_week = MOD(d + (m+1)*26/10 + k + k/4 + j/4 + 5*j, 7)
mm=mm+12
yy=yy-1
END IF
j = yy / 100
k = MOD(yy, 100)
Day_of_week = MOD(d + ((mm+1)*26)/10 + k + k/4 + j/4 + 5*j, 7)
END FUNCTION Day_of_week
END PROGRAM YULETIDE</langsyntaxhighlight>
{{out}}
Output
<pre>
25th of December is a Sunday in 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
=={{header|GAP}}==
<lang gap>xmas := function(a, b)
local y, v;
v := [ ];
for y in [a .. b] do
if WeekDay([25, 12, y]) = "Sun" then
Add(v, y);
fi;
od;
return v;
end;
 
=={{header|Fōrmulæ}}==
xmas(2008, 2121);
# [ 2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118 ]</lang>
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Day_of_the_week}}
=={{header|Go}}==
<lang go>package main
import "fmt"
import "time"
 
'''Solution'''
func main() {
for year := int64(2008); year <= 2121; year++ {
mytime := &time.Time{ Year:year, Month:12, Day:25 }
seconds := mytime.Seconds()
mytime = time.SecondsToUTC(seconds)
if mytime.Weekday == time.Sunday {
fmt.Printf("25 December %d is Sunday\n", year)
}
}
}</lang>
 
[[File:Fōrmulæ - Day of the week 01.png]]
=={{header|Groovy}}==
 
[[File:Fōrmulæ - Day of the week 02.png]]
Solution:
<lang groovy>def yuletide = { start, stop -> (start..stop).findAll { Date.parse("yyyy-MM-dd", "${it}-12-25").format("EEE") == "Sun" } }</lang>
 
=={{header|Frink}}==
Test program:
<syntaxhighlight lang="frink">for y = 2008 to 2121
<lang groovy>println yuletide(2008, 2121)</lang>
if (parseDate["$y-12-25"] -> ### u ###) == "7"
println[y]</syntaxhighlight>
 
{{out}}
Output:
<pre>
<pre>[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]</pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|HaskellGAP}}==
<syntaxhighlight lang="gap">Filtered([2008 .. 2121], y -> WeekDay([25, 12, y]) = "Sun");
Using the time library:
# [ 2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118 ]
<lang haskell>import Data.Time
import Data.Time.Calendar.WeekDate
 
# A possible implementation of WeekDayAlt
isXmasSunday year = wday == 7
where (_,_,wday) = toWeekDate $ fromGregorian year 12 25
 
days := ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];;
main = mapM_ putStrLn ["25 December " ++ show year ++ " is Sunday"
 
| year <- [2008..2121], isXmasSunday year]</lang>
WeekDayAlt := function(args)
Output:
local d, m, y, k;
d := args[1];
m := args[2];
y := args[3];
if m < 3 then
m := m + 12;
y := y - 1;
fi;
k := 1 + RemInt(d + QuoInt((m + 1)*26, 10) + y + QuoInt(y, 4)
+ 6*QuoInt(y, 100) + QuoInt(y, 400) + 5, 7);
return days[k];
end;
 
Filtered([2008 .. 2121], y -> WeekDayAlt([25, 12, y]) = "Sun");
# [ 2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118 ]</syntaxhighlight>
 
=={{header|Go}}==
<syntaxhighlight lang="go">package main
 
import "fmt"
import "time"
 
func main() {
for year := 2008; year <= 2121; year++ {
if time.Date(year, 12, 25, 0, 0, 0, 0, time.UTC).Weekday() ==
time.Sunday {
fmt.Printf("25 December %d is Sunday\n", year)
}
}
}</syntaxhighlight>
{{out}}
<pre>
25 December 2011 is Sunday
Line 611 ⟶ 2,773:
</pre>
 
=={{header|Groovy}}==
The built-in System.Time module overflows at the Unix epoch in 2038:
<lang haskell>import System.Time
 
Solution:
<syntaxhighlight lang="groovy">def yuletide = { start, stop -> (start..stop).findAll { Date.parse("yyyy-MM-dd", "${it}-12-25").format("EEE") == "Sun" } }</syntaxhighlight>
 
Test program:
<syntaxhighlight lang="groovy">println yuletide(2008, 2121)</syntaxhighlight>
 
{{out}}
<pre>[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]</pre>
 
=={{header|Haskell}}==
Using the time library:
<syntaxhighlight lang="haskell">import Data.Time (fromGregorian)
import Data.Time.Calendar.WeekDate (toWeekDate)
 
--------------------- DAY OF THE WEEK --------------------
 
isXmasSunday :: Integer -> Bool
isXmasSunday year = 7 == weekDay
where
(_, _, weekDay) = toWeekDate $ fromGregorian year 12 25
 
 
--------------------------- TEST -------------------------
main :: IO ()
main =
mapM_
putStrLn
[ "Sunday 25 December " <> show year
| year <- [2008 .. 2121],
isXmasSunday year
]</syntaxhighlight>
{{out}}
<pre>Sunday 25 December 2011
Sunday 25 December 2016
Sunday 25 December 2022
Sunday 25 December 2033
Sunday 25 December 2039
Sunday 25 December 2044
Sunday 25 December 2050
Sunday 25 December 2061
Sunday 25 December 2067
Sunday 25 December 2072
Sunday 25 December 2078
Sunday 25 December 2089
Sunday 25 December 2095
Sunday 25 December 2101
Sunday 25 December 2107
Sunday 25 December 2112
Sunday 25 December 2118</pre>
 
The built-in System.Time module can overflow at the Unix epoch in 2038:
<syntaxhighlight lang="haskell">import System.Time
isXmasSunday :: Int -> Bool
isXmasSunday year = ctWDay cal == Sunday
where
where cal = toUTCTime $ toClockTime cal'
cal = toUTCTime $ toClockTime cal' = CalendarTime {
cal' =
ctYear = year,
CalendarTime
ctMonth = December,
{ ctDayctYear = 25,year
, ctHourctMonth = 0,December
, ctMinctDay = 0,25
, ctSecctHour = 0,
, ctPicosecctMin = 0,
, ctWDayctSec = Friday,0
, ctYDayctPicosec = 0,
, ctTZNamectWDay = "",Friday
, ctTZctYDay = 0,
, ctIsDSTctTZName = False""
, ctTZ = }0
, ctIsDST = False
}
 
main :: IO ()
main = mapM_ putStrLn ["25 December " ++ show year ++ " is Sunday"
main =
| year <- [2008..2121], isXmasSunday year]</lang>
mapM_
Output on 32-bit machine:
putStrLn
[ "25 December " ++ show year ++ " is Sunday"
| year <- [2008 .. 2121]
, isXmasSunday year ]</syntaxhighlight>
{{out}} on 32-bit machine:
<pre>
25 December 2011 is Sunday
Line 641 ⟶ 2,863:
*** Exception: user error (Time.toClockTime: invalid input)
</pre>
but with 64 bit systems, running current versions of GHC:
<pre>
25 December 2011 is Sunday
25 December 2016 is Sunday
25 December 2022 is Sunday
25 December 2033 is Sunday
25 December 2039 is Sunday
25 December 2044 is Sunday
25 December 2050 is Sunday
25 December 2061 is Sunday
25 December 2067 is Sunday
25 December 2072 is Sunday
25 December 2078 is Sunday
25 December 2089 is Sunday
25 December 2095 is Sunday
25 December 2101 is Sunday
25 December 2107 is Sunday
25 December 2112 is Sunday
25 December 2118 is Sunday</pre>
 
=={{header|HicEst}}==
<langsyntaxhighlight HicEstlang="hicest">DO year = 1, 1000000
TIME(Year=year, MOnth=12, Day=25, TO, WeekDay=weekday)
IF( weekday == 7) WRITE(StatusBar) year
ENDDO
 
END</langsyntaxhighlight>
<pre>No anomalies detected for the first million years :-)
Dec 25 = Sunday in
Line 655 ⟶ 2,896:
</pre>
 
== {{header|Icon}} and {{header|Unicon}} ==
 
<langsyntaxhighlight Iconlang="icon">link datetime
 
procedure main()
writes("December 25th is a Sunday in: ")
every writes((dayoweek(25,12,y := 2008 to 2122)=="Sunday",y)," ")
end</langsyntaxhighlight>
 
 
Line 668 ⟶ 2,909:
[http://www.cs.arizona.edu/icon/library/src/procs/datetime.icn datetime provides dayoweek]
 
<langsyntaxhighlight Iconlang="icon">procedure dayoweek(day, month, year) #: day of the week
static d_code, c_code, m_code, ml_code, y, C, M, Y
 
Line 710 ⟶ 2,951:
return d_code[(C + Y + M + day) % 7 + 1]
end</langsyntaxhighlight>
 
{{out}}
Sample Output:
<pre>December 25th is a Sunday in: 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</pre>
 
=={{header|J}}==
<langsyntaxhighlight lang="j"> load 'dates' NB. provides verb 'weekday'
SunDec25xmasSunday=: #~ 0& =@ [: weekday@:(|:@,: 12 25 ,~"1 0 ] NB. 12returns years where 25$~#,2:) Dec is a Sunday
xmasSunday 2008 + i.114 NB. check years from 2008 to 2121
SunDec25 2008 + i.114
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</langsyntaxhighlight>
 
=={{header|Java}}==
<syntaxhighlight lang="java">
<lang java>import java.util.Calendar;
import static java.util.Calendar.*;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
Line 728 ⟶ 2,971:
public class Yuletide{
public static void main(String[] args) {
Calendar calendar;
for(int i = 2008;i<=2121;i++){
int count = 1;
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
for (int year = 2008; year <= 2121; year++) {
25);
calendar = new GregorianCalendar(year, DECEMBER, 25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
if (calendar.get(DAY_OF_WEEK) == SUNDAY) {
System.out.println(cal.getTime());
if (count != 1)
}
System.out.print(", ");
}
System.out.printf("%d", calendar.get(YEAR));
count++;
}
}
}
}
}</lang>
</syntaxhighlight>
Output:
{{out}}
<pre>Sun Dec 25 00:00:00 CST 2011
<pre>
Sun Dec 25 00:00:00 CST 2016
2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118
Sun Dec 25 00:00:00 CST 2022
</pre>
Sun Dec 25 00:00:00 CST 2033
Sun Dec 25 00:00:00 CST 2039
Sun Dec 25 00:00:00 CST 2044
Sun Dec 25 00:00:00 CST 2050
Sun Dec 25 00:00:00 CST 2061
Sun Dec 25 00:00:00 CST 2067
Sun Dec 25 00:00:00 CST 2072
Sun Dec 25 00:00:00 CST 2078
Sun Dec 25 00:00:00 CST 2089
Sun Dec 25 00:00:00 CST 2095
Sun Dec 25 00:00:00 CST 2101
Sun Dec 25 00:00:00 CST 2107
Sun Dec 25 00:00:00 CST 2112
Sun Dec 25 00:00:00 CST 2118</pre>
 
=={{header|JavaScript}}==
<lang javascript>for (var year = 2008; year <= 2121; year++) {
var yule = new Date(year, 11, 25);
if (yule.getDay() == 0)
try {
WScript.Echo(yule); // WSH
} catch(err) {
print(yule); // Rhino
}
}</lang>
output:
<pre>Sun Dec 25 00:00:00 EST 2011
Sun Dec 25 00:00:00 EST 2016
Sun Dec 25 00:00:00 EST 2022
Sun Dec 25 00:00:00 EST 2033
Sun Dec 25 00:00:00 EST 2039
Sun Dec 25 00:00:00 EST 2044
Sun Dec 25 00:00:00 EST 2050
Sun Dec 25 00:00:00 EST 2061
Sun Dec 25 00:00:00 EST 2067
Sun Dec 25 00:00:00 EST 2072
Sun Dec 25 00:00:00 EST 2078
Sun Dec 25 00:00:00 EST 2089
Sun Dec 25 00:00:00 EST 2095
Sun Dec 25 00:00:00 EST 2101
Sun Dec 25 00:00:00 EST 2107
Sun Dec 25 00:00:00 EST 2112
Sun Dec 25 00:00:00 EST 2118</pre>
=={{header|Liberty BASIC}}==
<lang lb> count = 0
for year = 2008 to 2121
dateString$="12/25/";year
dayNumber=date$(dateString$)
 
===ES5===
if dayNumber mod 7 = 5 then
====Iteration====
count = count + 1
<syntaxhighlight lang="javascript">for (var year = 2008; year <= 2121; year++){
print dateString$
var xmas = new endDate(year, if11, 25)
if ( xmas.getDay() === 0 )
console.log(year)
}</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
====Functional composition====
next year
 
<syntaxhighlight lang="javascript">(function () {
print count; " years when Christmas Day falls on a Sunday"
end</lang>'use strict';
 
// isXmasSunday :: Integer -> Bool
function isXmasSunday(year) {
return (new Date(year, 11, 25))
.getDay() === 0;
}
 
// range :: Int -> Int -> [Int]
function range(m, n) {
return Array.apply(null, Array(n - m + 1))
.map(function (_, i) {
return m + i;
});
}
 
return range(2008, 2121)
.filter(isXmasSunday);
 
})();</syntaxhighlight>
 
{{Out}}
<pre>[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067,
2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]</pre>
 
===ES6===
<syntaxhighlight lang="javascript">(() => {
"use strict";
 
// main :: IO ()
const main = () => {
const
xs = enumFromTo(2008)(2121)
.filter(xmasIsSunday);
 
return (
console.log(xs),
xs
);
};
 
 
// xmasIsSunday :: Int -> Bool
const xmasIsSunday = year =>
(new Date(year, 11, 25))
.getDay() === 0;
 
 
// enumFromTo :: Int -> Int -> [Int]
const enumFromTo = m =>
n => Array.from({
length: 1 + n - m
}, (_, i) => m + i);
 
// MAIN ---
return main();
})();</syntaxhighlight>
{{Out}}
<syntaxhighlight lang="javascript">[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]</syntaxhighlight>
 
=={{header|jq}}==
<syntaxhighlight lang="jq"># Use Zeller's Congruence to determine the day of the week, given
# year, month and day as integers in the conventional way.
# If iso == "iso" or "ISO", then emit an integer in 1 -- 7 where
# 1 represents Monday, 2 Tuesday, etc;
# otherwise emit 0 for Saturday, 1 for Sunday, etc.
#
def day_of_week(year; month; day; iso):
if month == 1 or month == 2 then
[month + 12, year - 1]
else
[month, year]
end
| day + (13*(.[0] + 1)/5|floor)
+ (.[1]%100) + ((.[1]%100)/4|floor)
+ (.[1]/400|floor) - 2*(.[1]/100|floor)
| if iso == "iso" or iso == "ISO" then 1 + ((. + 5) % 7)
else . % 7
end;</syntaxhighlight>
'''The task''':
<syntaxhighlight lang="jq"># Give the results as an array so they can
# readily be presented on a single line:
[range(2008; 2122) | select( day_of_week(.;12;25;0) == 1 )]</syntaxhighlight>
{{out}}
$ jq -n -c -f zeller.jq
[2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118]
 
=={{header|Jsish}}==
Jsi does not yet implement the Javascript ''Date'' object. ''strftime' and ''strptime'' functions are used here instead.
 
<syntaxhighlight lang="javascript">/* Day of the week, December 25th on a Sunday */
for (var year = 2008; year <= 2121; year++) {
var xmas = strptime(year + '/12/25', '%Y/%m/%d');
var weekDay = strftime(xmas, '%w');
if (weekDay == 0) puts(year);
}
 
/*
=!EXPECTSTART!=
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
=!EXPECTEND!=
*/</syntaxhighlight>
 
{{out}}
<pre>prompt$ jsish -u dayOfTheWeek.jsi
[PASS] dayOfTheWeek.jsi</pre>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">using Dates
 
lo, hi = 2008, 2121
xmas = collect(Date(lo, 12, 25):Year(1):Date(hi, 12, 25))
filter!(xmas) do dt
dayofweek(dt) == Dates.Sunday
end
 
println("Years from $lo to $hi having Christmas on Sunday: ")
foreach(println, year.(xmas))</syntaxhighlight>
 
{{out}}
<pre>Years from 2008 to 2121 having Christmas on Sunday:
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
=={{header|K}}==
<syntaxhighlight lang="k"> wd:{(__jd x)!7} / Julian day count, Sun=6
y@&6={wd 1225+x*10000}'y:2008+!114
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</syntaxhighlight>
 
=={{header|Koka}}==
<syntaxhighlight lang="koka">
import std/time/date
import std/time/calendar
import std/time/instant
import std/time/utc
 
fun main()
for(2008, 2121) fn(year)
val i = instant(year, 12, 25, cal=cal-gregorian)
val dow = (i.days+6)%7 // plus 6 since 2000-01-01 epoch was a Saturday
match dow.weekday
Sun -> println(year.show)
_ -> ()
</syntaxhighlight>
 
{{out}}
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|Kotlin}}==
<syntaxhighlight lang="scala">// version 1.0.6
 
import java.util.*
 
fun main(args: Array<String>) {
println("Christmas day in the following years falls on a Sunday:\n")
val calendar = GregorianCalendar(2008, Calendar.DECEMBER, 25)
for (year in 2008..2121) {
if (Calendar.SUNDAY == calendar[Calendar.DAY_OF_WEEK]) println(year)
calendar.add(Calendar.YEAR, 1)
}
}</syntaxhighlight>
 
{{out}}
<pre>
Christmas day in the following years falls on a Sunday:
 
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|Lambdatalk}}==
{{trans|Javascript}}
<syntaxhighlight lang="javascript">
 
{xmasOnSunday 2008 2121}
->
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
 
{script
LAMBDATALK.DICT["xmasOnSunday"] = function() {
var args = arguments[0].trim().split(" "),
days = [];
 
for (var year = args[0]; year <= args[1]; year++) {
var xmas = new Date(year, 11, 25)
if ( xmas.getDay() === 0 )
days.push(year)
}
 
return days.join("\n")
};
}
 
 
</syntaxhighlight>
 
=={{header|Lasso}}==
<syntaxhighlight lang="lasso">loop(-From=2008, -to=2121) => {^
local(tDate = date('12/25/' + loop_count))
#tDate->dayOfWeek == 1 ? '\r' + #tDate->format('%D') + ' is a Sunday'
^}</syntaxhighlight>
 
{{out}}
<pre>12/25/2011 is a Sunday
12/25/2016 is a Sunday
12/25/2022 is a Sunday
12/25/2033 is a Sunday
12/25/2039 is a Sunday
12/25/2044 is a Sunday
12/25/2050 is a Sunday
12/25/2061 is a Sunday
12/25/2067 is a Sunday
12/25/2072 is a Sunday
12/25/2078 is a Sunday
12/25/2089 is a Sunday
12/25/2095 is a Sunday
12/25/2101 is a Sunday
12/25/2107 is a Sunday
12/25/2112 is a Sunday
12/25/2118 is a Sunday</pre>
 
=={{header|Lingo}}==
<syntaxhighlight lang="lingo">put "December 25 is a Sunday in:"
refDateObj = date(1905,1,2)
repeat with year = 2008 to 2121
dateObj = date(year, 12, 25)
dayOfWeek = ((dateObj - refDateObj) mod 7)+1 -- 1=Monday..7=Sunday
if dayOfWeek=7 then put year
end repeat</syntaxhighlight>
{{out}}
<pre>
-- "December 25 is a Sunday in:"
-- 2011
-- 2016
-- 2022
-- 2033
-- 2039
-- 2044
-- 2050
-- 2061
-- 2067
-- 2072
-- 2078
-- 2089
-- 2095
-- 2101
-- 2107
-- 2112
-- 2118
</pre>
 
=={{header|LiveCode}}==
<syntaxhighlight lang="livecode">function xmasSunday startDate endDate
convert the long date to dateitems
put it into xmasDay
put 12 into item 2 of xmasDay
put 25 into item 3 of xmasDay
repeat with i = startDate to endDate
put i into item 1 of xmasDay
convert xmasDay to dateItems
if item 7 of xmasDay is 1 then put i & comma after xmasYear
end repeat
if the last char of xmasYear is comma then delete the last char of xmasYear
return xmasYear
end xmasSunday</syntaxhighlight>Example<syntaxhighlight lang="livecode">put xmasSunday(2008,2121)</syntaxhighlight>Output<pre>2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118</pre>
 
=={{header|Logo}}==
<syntaxhighlight lang="logo">; Determine if a Gregorian calendar year is leap
to leap? :year
output (and
equal? 0 modulo :year 4
not member? modulo :year 400 [100 200 300]
)
end
 
; Convert Gregorian calendar date to a simple day count from
; day 1 = January 1, 1 CE
to day_number :year :month :day
local "elapsed make "elapsed difference :year 1
output (sum product 365 :elapsed
int quotient :elapsed 4
minus int quotient :elapsed 100
int quotient :elapsed 400
int quotient difference product 367 :month 362 12
ifelse lessequal? :month 2 0 ifelse leap? :year -1 -2
:day)
end
 
; Find the day of the week from a day number; 0 = Sunday through 6 = Saturday
to day_of_week :day_number
output modulo :day_number 7
end
 
; True if the given day is a Sunday
to sunday? :year :month :day
output equal? 0 day_of_week day_number :year :month :day
end
 
; Put it all together to answer the question posed in the problem
print filter [sunday? ? 12 25] iseq 2008 2121
bye</syntaxhighlight>
 
{{Out}}
<pre>2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</pre>
 
=={{header|Lua}}==
'''Library:''' [http://luaforge.net/projects/date/ LuaDate]
 
<langsyntaxhighlight Lualang="lua">require("date")
 
for year=2008,2121 do
Line 809 ⟶ 3,416:
print(year)
end
end</langsyntaxhighlight>
 
{{out}}
Output:
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=== Without external modules ===
Same output as above
<syntaxhighlight lang="lua">local dTab = {day = 25, month = 12}
for year = 2008, 2121 do
dTab.year = year
if os.date("%A", os.time(dTab)) == "Sunday" then
print(year)
end
end</syntaxhighlight>
 
=={{header|M2000 Interpreter}}==
Str$( number, format$) use Visual Basic 6 format
<syntaxhighlight lang="m2000 interpreter">
Print "December 25 is a Sunday in:"
For Year=2008 to 2121 {
if Str$(Date("25/12/"+str$(Year,"")),"w")="1" Then {
Print Year
}
}
\\ is the same with this:
Print "December 25 is a Sunday in:"
For Year=2008 to 2121 {
if Str$(Date(str$(Year,"")+"-12-25"),"w")="1" Then {
Print Year
}
}
 
 
</syntaxhighlight>
{{out}}
<pre>
2011
Line 833 ⟶ 3,490:
 
=={{header|M4}}==
<langsyntaxhighlight M4lang="m4">divert(-1)
 
define(`for',
Line 851 ⟶ 3,508:
 
for(`yr',2008,2121,
`ifelse(eval(julianxmas(yr)%7==6),1,`yr ')')</langsyntaxhighlight>
 
{{out}}
Output:
<pre>
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112
Line 859 ⟶ 3,516:
</pre>
 
=={{header|MathematicaMaple}}==
<syntaxhighlight lang="maple">xmas:= proc()
<lang Mathematica>Reap[If[DateString[{#,12,25},"DayName"]=="Sunday",Sow[#]]&/@Range[2008,2121]][[2,1]]</lang>
local i, dt;
for i from 2008 to 2121 by 1 do
dt := Date(i, 12, 25);
if (Calendar:-DayOfWeek(dt) = 1) then
print(i);
end if;
end do;
end proc;
 
xmas();</syntaxhighlight>
 
{{Out|Output}}
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
Or simply:
 
<syntaxhighlight lang="maple">select(y->Calendar:-DayOfWeek(Date(y,12,25))=1,[$2008..2121]);</syntaxhighlight>
 
{{out}}
<pre>[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]</pre>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">Reap[If[DateString[{#,12,25},"DayName"]=="Sunday",Sow[#]]&/@Range[2008,2121]][[2,1]]</syntaxhighlight>
gives back:
<langsyntaxhighlight Mathematicalang="mathematica">{2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118}</langsyntaxhighlight>
 
=={{header|MATLAB}} / {{header|Octave}}==
 
<syntaxhighlight lang="matlab"> t = datenum([[2008:2121]',repmat([12,25,0,0,0], 2121-2007, 1)]);
t = t(strmatch('Sunday', datestr(t,'dddd')), :);
datestr(t,'yyyy')
</syntaxhighlight>
 
 
{{out}}
<pre> ans =
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">weekday(year, month, day) := block([m: month, y: year, k],
if m < 3 then (m: m + 12, y: y - 1),
k: 1 + remainder(day + quotient((m + 1)*26, 10) + y + quotient(y, 4)
+ 6*quotient(y, 100) + quotient(y, 400) + 5, 7),
['monday, 'tuesday, 'wednesday, 'thurdsday, 'friday, 'saturday, 'sunday][k]
)$
 
sublist(makelist(i, i, 2008, 2121),
lambda([y], weekday(y, 12, 25) = 'sunday));
/* [2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118] */</syntaxhighlight>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">import "dateTime"
 
print "Years between 2008 and 2121 when 25th December falls on Sunday:"
years = []
for year in range(2008, 2121)
date = year + "-12-25"
if dateTime.weekday(date) == 0 then years.push year
end for
print years.join(", ")</syntaxhighlight>
 
{{out}}
<pre>Years between 2008 and 2121 when 25th December falls on Sunday:
2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118
</pre>
 
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">П9 7 П7 1 П8 НОП ИП8 2 2 -
1 0 / [x] П6 ИП9 + 1 8 9
9 - 3 6 5 , 2 5 * [x]
ИП8 ИП6 1 2 * - 1 4 - 3
0 , 5 9 * [x] + 2 9 +
ИП7 + П4 ИП4 7 / [x] 7 * -
x=0 64 ИП9 С/П ИП9 1 + П9 БП 06</syntaxhighlight>
 
''Input:'' РX: starting year.
 
''Output:'' the year in which Christmas falls on a Sunday. For example, enter ''2008'', the first result: ''2018'' (''January 7, 2018'' is Sunday).
 
=={{header|Modula-3}}==
Line 870 ⟶ 3,638:
Consequently, it suffers from the same problem as C.
 
<langsyntaxhighlight lang="modula3">MODULE Yule EXPORTS Main;
 
IMPORT IO, Fmt, Date, Time;
Line 897 ⟶ 3,665:
END;
END;
END Yule.</langsyntaxhighlight>
 
{{out}}
Output:
<pre>
25th of December 2011 is Sunday
Line 910 ⟶ 3,678:
=={{header|MUMPS}}==
{{libheader|VA Kernel|22.0}}
<syntaxhighlight lang="mumps">
<lang MUMPS>
DOWHOLIDAY
;In what years between 2008 and 2121 will December 25 be a Sunday?
Line 930 ⟶ 3,698:
KILL BDT,EDT,CHECK,CHKFOR,LIST,I,X,Y
QUIT
</langsyntaxhighlight>Usage:<pre>USER>D ^DOW
The following years have Christmas on a Sunday: 2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118
</pre>
 
=={{header|Nanoquery}}==
<syntaxhighlight lang="nanoquery">import Nanoquery.Util
// loop through the years 2008 through 2121
for year in range(2008, 2121)
if (new(Date,"12/25/" + str(year)).getDayOfWeek() = "Sunday")
println "In " + year + ", December 25th is a Sunday."
end if
end for</syntaxhighlight>
 
=={{header|NetRexx}}==
<syntaxhighlight lang="netrexx">/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
 
yearRanges = [int 2008, 2121]
searchday = ''
cal = Calendar
 
loop year = yearRanges[0] to yearRanges[1]
cal = GregorianCalendar(year, Calendar.DECEMBER, 25)
dayIndex = cal.get(Calendar.DAY_OF_WEEK)
if dayIndex = Calendar.SUNDAY then searchday = searchday year
end year
 
say 'Between' yearRanges[0] 'and' yearRanges[1]', Christmas day falls on a Sunday on the following years:'
searchday = searchday.strip.changestr(' ', ',')
say ' 'searchday
 
return
</syntaxhighlight>
{{out}}
<pre>
Between 2008 and 2121, Christmas day falls on a Sunday on the following years:
2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118
</pre>
===Comparison of Some Common Day-of-Week Algorithms===
The following program exercises some common &quot;Day-0f-Week&quot; algorithms to confirm they all arrive at the same result.
<syntaxhighlight lang="netrexx">/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
 
days = 'Monday Tuesday Wednesday Thursday Friday Saturday Sunday'
yearRanges = [int 2008, 2121]
 
searchday = ''
searchday['index'] = days.wordpos('Sunday')
searchday[0] = 0
 
algorithmName = ['Java Calendar', 'Zeller[1]', 'Zeller[2]', 'Sakamoto', 'Gauss', 'Keith', 'Babwani']
 
loop alg = 0 to algorithmName.length - 1
sd = searchday[0] + 1
searchday[0] = sd
searchday['agorithm', sd] = algorithmName[alg]
loop year = yearRanges[0] to yearRanges[1]
select case alg
when 0 then dayIndex = getDaynumJavaLibrary(year, 12, 25)
when 1 then dayIndex = getDaynumZellersCongruenceMethod1(year, 12, 25)
when 2 then dayIndex = getDaynumZellersCongruenceMethod2(year, 12, 25)
when 3 then dayIndex = getDaynumSakamoto(year, 12, 25)
when 4 then dayIndex = getDaynumGauss(year, 12, 25)
when 5 then dayIndex = getDaynumKeith(year, 12, 25)
when 6 then dayIndex = getDaynumBabwani(year, 12, 25)
otherwise nop
end
if dayIndex = searchday['index'] then
searchday[sd] = searchday[sd] year
end year
end alg
 
-- display results
say 'Between' yearRanges[0] 'and' yearRanges[1]', Christmas day falls on a Sunday in the following years:'
loop r_ = 1 to searchday[0]
searchday[r_] = searchday[r_].strip.changestr(' ', ',')
say searchday['agorithm', r_].right(20)':' searchday[r_]
end r_
 
return
 
-- -----------------------------------------------------------------------------
method getDaynumJavaLibrary(Year = int, Month = int, Day = int, iso = Rexx 'Y') public static binary returns int
-- The day-of-week is an integer value where 1 is Sunday, 2 is Monday, ..., and 7 is Saturday
-- For an ISO week date Day-of-Week d (1 = Monday to 7 = Sunday), use d = ((h - 1 + 6) mod 7) + 1
 
cal = Calendar
jmNumber = [ -
Calendar.JANUARY, Calendar.FEBRUARY, Calendar.MARCH, Calendar.APRIL -
, Calendar.MAY, Calendar.JUNE, Calendar.JULY, Calendar.AUGUST -
, Calendar.SEPTEMBER, Calendar.OCTOBER, Calendar.NOVEMBER, Calendar.DECEMBER -
]
 
mon = jmNumber[Month - 1]
cal = GregorianCalendar(Year, mon, Day)
h = cal.get(Calendar.DAY_OF_WEEK)
 
if 'YES'.abbrev(iso.upper, 1) then w = ((h - 1 + 6) // 7) + 1
else w = h
 
return w
 
-- -----------------------------------------------------------------------------
method getDaynumZellersCongruenceMethod1(Year = int, Month = int, Day = int, iso = Rexx 'Y') public static returns int
-- DayNum results in an integer in the range 0-6 where 0 represents Monday etc.
-- For an ISO week date add 1
 
if Month = 1 | Month = 2 then do
Month = Month + 12
Year = Year - 1
end
 
MonthFactor = 2 * Month + 3 * (Month + 1) % 5
YearFactor = Year + Year % 4 - Year % 100 + Year % 400
DayNum = (Day + MonthFactor + YearFactor) // 7
 
if 'YES'.abbrev(iso.upper, 1) then d = DayNum + 1
else d = DayNum
 
return d
 
-- -----------------------------------------------------------------------------
method getDaynumZellersCongruenceMethod2(Year = int, Month = int, Day = int, iso = Rexx 'Y') public static binary returns int
-- h is the day of the week (0 = Saturday, 1 = Sunday, 2 = Monday, ...)
-- For an ISO week date Day-of-Week d (1 = Monday to 7 = Sunday), use d = ((h + 5) mod 7) + 1
 
if Month < 3 then do
Month = Month + 12
Year = Year - 1
end
q = Day
m = Month
Y = Year
 
h = (q + ((m + 1) * 26 % 10) + Y + (Y % 4) + 6 * (Y % 100) + (Y % 400)) // 7
 
if 'YES'.abbrev(iso.upper, 1) then d = ((h + 5) // 7) + 1
else d = h
 
return d
 
-- -----------------------------------------------------------------------------
method getDaynumSakamoto(y = int, m = int, d = int, iso = Rexx 'Y') public static binary returns int
-- h is the day of the week (0 = Sunday, 1 = Monday, 2 = Tuesday...)
-- For an ISO week date Day-of-Week d (1 = Monday to 7 = Sunday), use d = ((h + 6) mod 7) + 1
 
t = [int 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
y = y - (m < 3)
h = (y + y % 4 - y % 100 + y % 400 + t[m - 1] + d) // 7
 
if 'YES'.abbrev(iso.upper, 1) then d = ((h + 6) // 7) + 1
else d = h
 
return d
 
-- -----------------------------------------------------------------------------
method getDaynumGauss(Year = int, Month = int, Day = int, iso = Rexx 'Y') public static binary returns int
-- W is week day (0 = Sunday, ..., 6 = Saturday)
-- For an ISO week date Day-of-Week d (1 = Monday to 7 = Sunday), use d = ((h + 6) mod 7) + 1
 
Year = Year - (Month < 3)
k = double Day
C = double Year % 100
Y = double Year // 100
m = double ((Month + 9) // 12) + 1
 
W = modulo(int (k + Math.floor(2.6 * m - 0.2) + y + Math.floor(y / 4) + Math.floor(c / 4) - 2 * c), 7)
 
if 'YES'.abbrev(iso.upper, 1) then h = ((W + 6) // 7) + 1
else h = W
 
return h
 
-- -----------------------------------------------------------------------------
method getDaynumKeith(y = int, m = int, d = int, iso = Rexx 'Y') public constant binary returns int
-- W is week day (0 = Sunday, ..., 6 = Saturday)
-- For an ISO week date Day-of-Week d (1 = Monday to 7 = Sunday), use d = ((h + 6) mod 7) + 1
 
if m < 3 then do
d = d + y
y = y - 1
end
else do
d = d + y - 2
end
 
h = (23 * m % 9 + d + 4 + y % 4 - y % 100 + y % 400) // 7
 
if 'YES'.abbrev(iso.upper, 1) then W = ((h + 6) // 7) + 1
else W = h
 
return W
 
-- -----------------------------------------------------------------------------
method getDaynumBabwani(Year = int, Month = int, Day = int, iso = Rexx 'Y') public constant binary returns int
-- return dow = Day of week: 0 = Saturday, 1 = Sunday, ... 6 = Friday
-- For an ISO week date Day-of-Week W (1 = Monday to 7 = Sunday), use W = ((dow + 5) mod 7) + 1
 
y = Year
m = Month
d = Day
 
dow = int -- dow stands for day of week
dowfg = double
fmonth = int
leap = int
 
if ((y // 100 == 0) & (y // 400 \= 0)) then -- leap function 1 for leap & 0 for non-leap
leap = 0
else if (y // 4 == 0) then
leap = 1
else
leap = 0
 
fmonth = 3 + (2 - leap) * ((m + 2) % (2 * m)) + (5 * m + m % 9) % 2 -- f(m) formula
fmonth = fmonth // 7 -- f(m) is brought in range of 0 to 6
 
century = y % 100
lastdigits = y // 100
 
dowfg = 1.25 * lastdigits + fmonth + d - 2 * (century // 4) -- function of weekday for Gregorian
dow = int dowfg // 7 -- remainder on division by 7
 
if 'YES'.abbrev(iso.upper, 1) then W = ((dow + 5) // 7) + 1
else W = dow
 
return W
 
-- -----------------------------------------------------------------------------
method modulo(N = int, D = int) inheritable static binary returns int
return (D + (N // D)) // D
</syntaxhighlight>
{{out}}
<pre>
Between 2008 and 2121, Christmas day falls on a Sunday in the following years:
Java Calendar: 2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118
Zeller[1]: 2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118
Zeller[2]: 2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118
Sakamoto: 2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118
Gauss: 2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118
Keith: 2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118
Babwani: 2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118
</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">import times
 
for year in 2008..2121:
if getDayOfWeek(25, mDec, year) == dSun:
stdout.write year, ' '
echo ""</syntaxhighlight>
 
{{out}}
<pre>2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118 </pre>
 
=={{header|Oberon-2}}==
{{works with|oo2c version 2}}
<syntaxhighlight lang="oberon2">
MODULE DayOfWeek;
IMPORT NPCT:Dates, Out;
VAR
year: INTEGER;
date: Dates.Date;
BEGIN
FOR year := 2008 TO 2121 DO
date := Dates.NewDate(25,12,year);
IF date.DayOfWeek() = Dates.sunday THEN
Out.Int(date.year,4);Out.Ln
END
END
END DayOfWeek.
</syntaxhighlight>
{{out}}
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
{{works with|AOS}}
<syntaxhighlight lang="oberon2">
MODULE DaysOfWeek; (** AUTHOR ""; PURPOSE ""; *)
 
IMPORT
Out := KernelLog, Dates;
PROCEDURE Do*;
VAR
date: Dates.DateTime;
i,y,w,wd: LONGINT;
BEGIN
FOR i := 2008 TO 2121 DO
date.year := i;date.month :=12; date.day := 25;
date.hour := 0;date.minute := 0; date.second := 0;
Dates.WeekDate(date,y,w,wd);
IF wd = 7 THEN Out.Int(i,0);Out.Ln END
END
END Do;
 
END DaysOfWeek.
</syntaxhighlight>
{{out}}
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
Line 938 ⟶ 4,038:
 
{{works with|GNUstep}}
{{works with|Cocoa}}
 
<syntaxhighlight lang="objc">#import <Foundation/Foundation.h>
It should works also with Cocoa and OpenStep in general, but I can't test these.
 
<lang objc>#import <Foundation/Foundation.h>
 
int main()
{
@autoreleasepool {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for(NSUInteger i=2008; i<2121; i++)
{
NSCalendarDate *d = [[NSCalendarDate alloc]
for(i=2008; i<2121; i++)
initWithYear: i
{
month: 12
NSCalendarDate *d = [[NSCalendarDate alloc]
initWithYear day: i25
month hour: 0 minute: 0 second:0 12
day timeZone: [NSTimeZone timeZoneWithAbbreviation:@"CET"] 25];
if ( [d dayOfWeek] == hour: 0 minute: 0 second:0 )
{
timeZone: [NSTimeZone timeZoneWithAbbreviation:@"CET"] ];
if printf("25 [dDec dayOfWeek]%u ==is 0Sunday\n", i);
{ }
printf("25 Dec %u is Sunday\n", i);
}
[d release];
}
}
[pool release];
return 0;
}</langsyntaxhighlight>
 
Output:
 
{{out}}
<pre>
25 Dec 2011 is Sunday
Line 991 ⟶ 4,086:
=={{header|OCaml}}==
{{trans|C}}
<langsyntaxhighlight lang="ocaml">#load "unix.cma"
open Unix
 
Line 1,010 ⟶ 4,105:
raise e
done
with _ -> ()</langsyntaxhighlight>
 
The output of a run on a 32 bit machine is
 
{{out}} of a run on a 32 bit machine
<pre>
25 December 2011 is Sunday
Line 1,021 ⟶ 4,115:
2037 is the last year we can specify
</pre>
 
=== With a dedicated library ===
 
{{libheader|OCaml Calendar Library}}
 
Unlike the previous example which only uses the OCaml standard library, here with the OCaml Calendar Library we can go until the year 2121:
 
<syntaxhighlight lang="ocaml">open CalendarLib
 
let list_make_seq first last =
let rec aux i acc =
if i < first then acc
else aux (pred i) (i::acc)
in
aux last []
let print_date (year, month, day) =
Printf.printf "%d-%02d-%02d\n" year month day
let () =
let years = list_make_seq 2008 2121 in
let years = List.filter (fun year ->
Date.day_of_week (Date.make year 12 25) = Date.Sun) years in
print_endline "December 25 is a Sunday in:";
List.iter (Printf.printf "%d\n") years</syntaxhighlight>
 
{{out}}
<pre>$ ocaml unix.cma str.cma -I +calendar calendarLib.cma xmas_sundays.ml
December 25 is a Sunday in:
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
=={{header|Oforth}}==
 
<syntaxhighlight lang="oforth">import: date
seqFrom(2008, 2121) filter(#[ 12 25 Date newDate dayOfWeek Date.SUNDAY == ]) .</syntaxhighlight>
{{out}}
<pre>
[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]
</pre>
 
=={{header|ooRexx}}==
===Christmas===
<syntaxhighlight lang="oorexx">date = .datetime~new(2008, 12, 25)
lastdate = .datetime~new(2121, 12, 25)
 
resultList = .array~new -- our collector of years
 
-- date objects are directly comparable
loop while date <= lastdate
if date~weekday == 7 then resultList~append(date~year)
-- step to the next year
date = date~addYears(1)
end
 
say "Christmas falls on Sunday in the years" resultList~toString("Line", ", ")</syntaxhighlight>
{{out}}
<pre>Christmas falls on Sunday in the years 2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118</pre>
===Weekday===
<syntaxhighlight lang="oorexx">/* REXX */
Parse Arg yyyymmdd
If arg(1)='' |,
arg(1)='?' Then Do
Say 'rexx wd yyyymmdd will show which weekday that is'
Exit
End
Parse Var yyyymmdd y +4 m +2 d
wd=.Array~of('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday')
dt=.DateTime~new(y,m,d)
say yyyymmdd 'is a' wd[dt~weekday]</syntaxhighlight>
{{out}}
<pre>H:\>rexx wd ?
rexx wd yyyymmdd will show which weekday that is
 
H:\>rexx wd 20211206
20211206 is a Monday </pre>
 
=={{header|PARI/GP}}==
<syntaxhighlight lang="parigp">
njd(D) =
{
my (m, y);
 
if (D[2] > 2, y = D[1]; m = D[2]+1, y = D[1]-1; m = D[2]+13);
 
(1461*y)\4 + (306001*m)\10000 + D[3] - 694024 + if (100*(100*D[1]+D[2])+D[3] > 15821004, 2 - y\100 + y\400)
}
 
for (y = 2008, 2121, if (njd([y,12,25]) % 7 == 1, print(y)));
</syntaxhighlight>
 
Output:
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|Pascal}}==
{{libheader|sysutils}}{{works with|Free Pascal}}
See [[Day_of_the_week#Delphi | Delphi]]
 
=={{header|Peloton}}==
<syntaxhighlight lang="sgml"><@ SAI>
<@ ITEFORLI3>2121|2008|
<@ LETVARCAP>Christmas Day|25-Dec-<@ SAYVALFOR>...</@></@>
<@ TSTDOWVARLIT>Christmas Day|1</@>
<@ IFF>
<@ SAYCAP>Christmas Day <@ SAYVALFOR>...</@> is a Sunday</@><@ SAYKEY>__Newline</@>
</@>
</@>
</@></syntaxhighlight>
 
English dialect variable-length space-padded opcodes
<syntaxhighlight lang="html"><# suppressimplicitoutput>
<# iterate foriteration literalstring3>2121|2008|
<# let variable capture>Christmas Day|25-Dec-<# say value foriteration>...</#></#>
<# test dayofweek variable literal>Christmas Day|1</#>
<# if>
<# say capture>Christmas Day <# say value foriteration>...</#> is a Sunday</#><# say keyword>__Newline</#>
</#>
</#>
</#></syntaxhighlight>
 
{{out}}
<pre>Christmas Day 2011 is a Sunday
Christmas Day 2016 is a Sunday
Christmas Day 2022 is a Sunday
Christmas Day 2033 is a Sunday
Christmas Day 2039 is a Sunday
Christmas Day 2044 is a Sunday
Christmas Day 2050 is a Sunday
Christmas Day 2061 is a Sunday
Christmas Day 2067 is a Sunday
Christmas Day 2072 is a Sunday
Christmas Day 2078 is a Sunday
Christmas Day 2089 is a Sunday
Christmas Day 2095 is a Sunday
Christmas Day 2101 is a Sunday
Christmas Day 2107 is a Sunday
Christmas Day 2112 is a Sunday
Christmas Day 2118 is a Sunday</pre>
 
=={{header|Perl}}==
 
<langsyntaxhighlight lang="perl">#! /usr/bin/perl -w
 
use Time::Local;
Line 1,039 ⟶ 4,305:
}
 
exit 0;</langsyntaxhighlight>
 
Output:
 
{{out}}
<pre>
25 Dec 2011 is Sunday
Line 1,055 ⟶ 4,320:
 
Using the DateTime module from CPAN:
<langsyntaxhighlight lang="perl">#! /usr/bin/perl -w
 
use DateTime;
Line 1,072 ⟶ 4,337:
}
 
exit 0;</langsyntaxhighlight>
or shorter:
<langsyntaxhighlight lang="perl">#! /usr/bin/perl -w
 
use DateTime;
Line 1,084 ⟶ 4,349:
}
 
exit 0;</langsyntaxhighlight>
{{out}}
Output:
 
<pre>
25 Dec 2011 is Sunday
Line 1,108 ⟶ 4,372:
 
Alternatively in one line using grep (read from right to left):
<langsyntaxhighlight lang="perl">#! /usr/bin/perl -w
 
use DateTime;
Line 1,115 ⟶ 4,379:
print join " ", grep { DateTime->new(year => $_, month => 12, day => 25)->day_of_week == 7 } (2008 .. 2121);
 
0;</langsyntaxhighlight>
{{out}}
Output:
<pre>2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</pre>
 
=={{header|Perl 6Phix}}==
{{libheader|Phix/basics}}
 
<!--<syntaxhighlight lang="phix">-->
{{works with|Rakudo|2010.07}}
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Day_of_the_week.exw</span>
 
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{<span style="color: #0000FF;">}</span>
As Perl 5, except <code>DateTime</code> is built-in, so you don't need to download a module of that name:
<span style="color: #008080;">for</span> <span style="color: #000000;">y<span style="color: #0000FF;">=<span style="color: #000000;">2008</span> <span style="color: #008080;">to</span> <span style="color: #000000;">2121</span> <span style="color: #008080;">do</span>
 
<span style="color: #008080;">if</span> <span style="color: #7060A8;">day_of_week<span style="color: #0000FF;">(<span style="color: #000000;">y<span style="color: #0000FF;">,<span style="color: #000000;">12<span style="color: #0000FF;">,<span style="color: #000000;">25<span style="color: #0000FF;">,<span style="color: #004600;">true<span style="color: #0000FF;">)<span style="color: #0000FF;">=<span style="color: #008000;">"Sunday"</span> <span style="color: #008080;">then</span>
<lang perl6>say join ' ', grep { Date.new($_, 12, 25).day-of-week == 7 }, 2008 .. 2121;</lang>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append<span style="color: #0000FF;">(<span style="color: #000000;">res<span style="color: #0000FF;">,<span style="color: #000000;">y<span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #0000FF;">?<span style="color: #000000;">res
<!--</syntaxhighlight>-->
{{out}}
<pre>
{2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118}
</pre>
 
=={{header|PHP}}==
 
<langsyntaxhighlight lang="php"><?php
for($i=2008; $i<2121; $i++)
{
Line 1,138 ⟶ 4,411:
}
}
?></langsyntaxhighlight>
 
Output:
 
{{out}}
<pre>
25 Dec 2011 is Sunday
Line 1,161 ⟶ 4,433:
25 Dec 2118 is Sunday
</pre>
 
=={{header|Picat}}==
<syntaxhighlight lang="picat">go =>
L = [Year : Year in 2008..2121, dow(Year, 12, 25) == 0],
println(L),
println(len=L.length),
nl.
 
% Day of week, Sakamoto's method
dow(Y, M, D) = R =>
T = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4],
if M < 3 then
Y := Y - 1
end,
R = (Y + Y // 4 - Y // 100 + Y // 400 + T[M] + D) mod 7.
</syntaxhighlight>
 
{{out}}
<pre>[2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118]
len = 17</pre>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(for (Y 2008 (>= 2121 Y) (inc Y))
(when (= "Sunday" (day (date Y 12 25)))
(printsp Y) ) )</langsyntaxhighlight>
{{out}}
Output:
<pre>2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</pre>
 
=={{header|Pike}}==
<syntaxhighlight lang="pike">filter(Calendar.Year(2008)->range(Calendar.Year(2121))->years()->month(12)->day(25), lambda(object day){ return day->week_day()==7; })->year()->format_nice();</syntaxhighlight>
{{out}}
<pre>
Result: ({ /* 17 elements */
"2011",
"2016",
"2022",
"2033",
"2039",
"2044",
"2050",
"2061",
"2067",
"2072",
"2078",
"2089",
"2095",
"2101",
"2107",
"2112",
"2118"
})
</pre>
 
=={{header|PL/0}}==
{{trans|GW-BASIC}}
<syntaxhighlight lang="pascal">
var year, month, day, dayofweek;
 
procedure calcdayofweek;
begin
if month < 3 then
begin
year := year - 1;
month := month + 12
end;
dayofweek := year + year / 4 - year / 100 + year / 400;
dayofweek := dayofweek + day + (153 * month + 8) / 5;
dayofweek := dayofweek - (dayofweek / 7) * 7
end;
 
begin
month := 12; day := 25;
year := 2007;
while year <= 2122 do
begin
call calcdayofweek;
if dayofweek = 0 then ! year;
year := year + 1
end
end.
</syntaxhighlight>
{{out}}
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
<lang PL/I>
declare i picture '9999';
do i = 2008 to 2121;
Line 1,176 ⟶ 4,542:
put skip list ('Christmas day ' || i || ' is a Sunday');
end;
</syntaxhighlight>
</lang>
 
==={{header|PL/I-80}}===
<syntaxhighlight lang="pl/i">/* Test of PL/I-80 routine to determine day of the week */
 
sunday_christmas:
proc options (main);
%replace
sunday by 0;
dcl
(year, w) fixed bin(15);
put skip list ('Christmas will fall on Sunday in these years:');
do year = 2008 to 2121;
w = weekday((year),12,25);
if w = sunday then
put skip edit (year) (f(4));
end;
 
stop;
 
/*
* Return day of week (Sun=0, Mon=1, etc.) for a given
* yr, mo, da using Zeller's congruence
*/
weekday:
proc (yr, mo, da) returns (fixed bin(15));
dcl (yr, mo, da) fixed bin(15);
dcl (c, y, m, d, z) fixed bin(15);
y = yr; /* make local copies */
m = mo;
d = da;
if m < 3 then
do;
m = m + 10;
y = y - 1;
end;
else m = m - 2;
c = y / 100;
y = mod(y, 100);
z = (26 * m - 2) / 10;
z = z + d + y + (y/4) + (c/4) - 2 * c + 777;
return (mod(z, 7));
end weekday;
 
end sunday_christmas;
</syntaxhighlight>
{{out}}
<pre>Christmas will fall on Sunday in these years:
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|PL/M}}==
{{Trans|ALGOL W}}which is{{Trans|Fortran}}
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator)
<syntaxhighlight lang="plm">
100H: /* FIND YEARS WHERE CHRISTMAS DAY FALLS ON A SUNDAY */
 
/* CP/M BDOS SYSTEM CALL AND I/O ROUTINES */
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END;
PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
PR$NL: PROCEDURE; CALL PR$CHAR( 0DH ); CALL PR$CHAR( 0AH ); END;
PR$NUMBER: PROCEDURE( N ); /* PRINTS A NUMBER IN THE MINIMUN FIELD WIDTH */
DECLARE N ADDRESS;
DECLARE V ADDRESS, N$STR ( 6 )BYTE, W BYTE;
V = N;
W = LAST( N$STR );
N$STR( W ) = '$';
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
DO WHILE( ( V := V / 10 ) > 0 );
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
END;
CALL PR$STRING( .N$STR( W ) );
END PR$NUMBER;
 
/* TASK */
 
/* RETURNS THE DAY OF THE WEEK CORRESPONDING To D/M/Y */
DAY$OF$WEEK: PROCEDURE( D, M, Y )BYTE;
DECLARE ( D, M, Y ) ADDRESS;
DECLARE ( J, K, MM, YY ) ADDRESS;
MM = M;
YY = Y;
IF MM <= 2 THEN DO;
MM = MM + 12;
YY = YY - 1;
END;
J = YY / 100;
K = YY MOD 100;
RETURN ( D + ( ( MM + 1 ) * 26 ) / 10 + K + K / 4 + J / 4 + 5 * J )
MOD 7;
END DAY$OF$WEEK ;
 
DECLARE ( YEAR, MONTH, DAY, COUNT ) ADDRESS;
CALL PR$STRING( .'25TH OF DECEMBER IS A SUNDAY IN$' );CALL PR$NL;
COUNT = 0;
DO YEAR = 2008 TO 2121;
DAY = DAY$OF$WEEK( 25, 12, YEAR );
IF DAY = 1 THEN DO;
CALL PR$CHAR( ' ' );CALL PR$NUMBER( YEAR );
IF ( COUNT := COUNT + 1 ) MOD 10= 0 THEN CALL PR$NL;
END;
END;
 
EOF
</syntaxhighlight>
{{out}}
<pre>
25TH OF DECEMBER IS A SUNDAY IN
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072
2078 2089 2095 2101 2107 2112 2118
</pre>
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell">2008..2121 | Where-Object { (Get-Date $_-12-25).DayOfWeek -eq "Sunday" }</langsyntaxhighlight>
 
===Find Christmas holiday for any day and/or year===
=={{header|Protium}}==
<syntaxhighlight lang="powershell">
<lang html><@ SAI>
function Get-ChristmasHoliday
<@ ITEFORLI3>2121|2008|
{
<@ LETVARCAP>Christmas Day|25-Dec-<@ SAYVALFOR>...</@></@>
[CmdletBinding()]
<@ TSTDOWVARLIT>Christmas Day|1</@>
[OutputType([PSCustomObject])]
<@ IFF>
Param
<@ SAYCAP>Christmas Day <@ SAYVALFOR>...</@> is a Sunday</@><@ SAYKEY>__Newline</@>
(
</@>
[Parameter(Mandatory=$false,
</@>
ValueFromPipeline=$true,
</@></lang>
ValueFromPipelineByPropertyName=$true,
Position=0)]
[ValidateRange(1,9999)]
[int[]]
$Year = (Get-Date).Year
)
 
Process
English dialect variable-length space-padded opcodes
{
<lang html><# suppressimplicitoutput>
[datetime]$christmas = Get-Date $Year/12/25
<# iterate foriteration literalstring3>2121|2008|
<# let variable capture>Christmas Day|25-Dec-<# say value foriteration>...</#></#>
<# test dayofweek variable literal>Christmas Day|1</#>
<# if>
<# say capture>Christmas Day <# say value foriteration>...</#> is a Sunday</#><# say keyword>__Newline</#>
</#>
</#>
</#></lang>
 
switch ($christmas.DayOfWeek)
''Output''
{
<pre>Christmas Day 2011 is a Sunday
"Sunday" {[datetime[]]$dates = 1..5 | ForEach-Object {$christmas.AddDays($_)}}
Christmas Day 2016 is a Sunday
"Monday" {[datetime[]]$dates = $christmas, $christmas.AddDays(1)}
Christmas Day 2022 is a Sunday
"Saturday" {[datetime[]]$dates = $christmas.AddDays(-2), $christmas.AddDays(-1)}
Christmas Day 2033 is a Sunday
Default {[datetime[]]$dates = $christmas.AddDays(-1), $christmas}
Christmas Day 2039 is a Sunday
}
Christmas Day 2044 is a Sunday
Christmas Day 2050 is a Sunday
Christmas Day 2061 is a Sunday
Christmas Day 2067 is a Sunday
Christmas Day 2072 is a Sunday
Christmas Day 2078 is a Sunday
Christmas Day 2089 is a Sunday
Christmas Day 2095 is a Sunday
Christmas Day 2101 is a Sunday
Christmas Day 2107 is a Sunday
Christmas Day 2112 is a Sunday
Christmas Day 2118 is a Sunday</pre>
 
$dates | Group-Object -Property Year |
=={{header|PureBasic}}==
Select-Object -Property @{Name="Year" ; Expression={$_.Name}},
PureBasic's internal Date() is limited between 1970-01-01 00:00:00 and 2038-01-19 03:14:07
@{Name="DayOfWeek"; Expression={$christmas.DayOfWeek}},
<lang PureBasic>For i=2008 To 2037
@{Name="Christmas"; Expression={$christmas.ToString("MM/dd/yyyy")}},
If DayOfWeek(Date(i,12,25,0,0,0))=0
@{Name="DaysOff" ; Expression={$_.Group | ForEach-Object {$_.ToString("MM/dd/yyyy")}}}
PrintN(Str(i))
EndIf }
}
Next</lang>
</syntaxhighlight>
Satisfy the task requirement:
<syntaxhighlight lang="powershell">
2008..2121 | Get-ChristmasHoliday | where DayOfWeek -match Su
</syntaxhighlight>
{{Out}}
<pre>
Year DayOfWeek Christmas DaysOff
---- --------- --------- -------
2011 Sunday 12/25/2011 {12/26/2011, 12/27/2011, 12/28/2011, 12/29/2011...}
2016 Sunday 12/25/2016 {12/26/2016, 12/27/2016, 12/28/2016, 12/29/2016...}
2022 Sunday 12/25/2022 {12/26/2022, 12/27/2022, 12/28/2022, 12/29/2022...}
2033 Sunday 12/25/2033 {12/26/2033, 12/27/2033, 12/28/2033, 12/29/2033...}
2039 Sunday 12/25/2039 {12/26/2039, 12/27/2039, 12/28/2039, 12/29/2039...}
2044 Sunday 12/25/2044 {12/26/2044, 12/27/2044, 12/28/2044, 12/29/2044...}
2050 Sunday 12/25/2050 {12/26/2050, 12/27/2050, 12/28/2050, 12/29/2050...}
2061 Sunday 12/25/2061 {12/26/2061, 12/27/2061, 12/28/2061, 12/29/2061...}
2067 Sunday 12/25/2067 {12/26/2067, 12/27/2067, 12/28/2067, 12/29/2067...}
2072 Sunday 12/25/2072 {12/26/2072, 12/27/2072, 12/28/2072, 12/29/2072...}
2078 Sunday 12/25/2078 {12/26/2078, 12/27/2078, 12/28/2078, 12/29/2078...}
2089 Sunday 12/25/2089 {12/26/2089, 12/27/2089, 12/28/2089, 12/29/2089...}
2095 Sunday 12/25/2095 {12/26/2095, 12/27/2095, 12/28/2095, 12/29/2095...}
2101 Sunday 12/25/2101 {12/26/2101, 12/27/2101, 12/28/2101, 12/29/2101...}
2107 Sunday 12/25/2107 {12/26/2107, 12/27/2107, 12/28/2107, 12/29/2107...}
2112 Sunday 12/25/2112 {12/26/2112, 12/27/2112, 12/28/2112, 12/29/2112...}
2118 Sunday 12/25/2118 {12/26/2118, 12/27/2118, 12/28/2118, 12/29/2118...}
</pre>
Get days off for a random year:
<syntaxhighlight lang="powershell">
Get-ChristmasHoliday -Year (2008..2121 | Get-Random)
</syntaxhighlight>
{{Out}}
<pre>
Year DayOfWeek Christmas DaysOff
---- --------- --------- -------
2110 Thursday 12/25/2110 {12/24/2110, 12/25/2110}
</pre>
Get days off for the current year using the '''Year''' property returned by <code>Get-Date</code>:
<syntaxhighlight lang="powershell">
(Get-Date | Get-ChristmasHoliday).DaysOff
</syntaxhighlight>
{{Out}}
<pre>
12/26/2016
12/27/2016
12/28/2016
12/29/2016
12/30/2016
</pre>
Get days off for the current year as <code>[DateTime]</code> objects:
<syntaxhighlight lang="powershell">
(Get-Date | Get-ChristmasHoliday).DaysOff | Get-Date
</syntaxhighlight>
{{Out}}
<pre>
Monday, December 26, 2016 12:00:00 AM
Tuesday, December 27, 2016 12:00:00 AM
Wednesday, December 28, 2016 12:00:00 AM
Thursday, December 29, 2016 12:00:00 AM
Friday, December 30, 2016 12:00:00 AM
</pre>
 
=={{header|Prolog}}==
Works with SWI-Prolog;
<syntaxhighlight lang="prolog">main() :-
christmas_days_falling_on_sunday(2011, 2121, SundayList),
writeln(SundayList).
 
christmas_days_falling_on_sunday(StartYear, EndYear, SundayList) :-
numlist(StartYear, EndYear, YearRangeList),
include(is_christmas_day_a_sunday, YearRangeList, SundayList).
is_christmas_day_a_sunday(Year) :-
Date = date(Year, 12, 25),
day_of_the_week(Date, DayOfTheWeek),
DayOfTheWeek == 7.
</syntaxhighlight>
{{out}}
<pre>?- main.
[2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118]
true.</pre>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">from calendar import datetimeweekday, SUNDAY
 
[year for year in range(2008, 2122) if weekday(year, 12, 25) == SUNDAY]</syntaxhighlight>
def yuletide():
{{out}}
sunday = 6
<pre>[2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]</pre>
days = (day.strftime('%d %b %Y') for day in (datetime.date(year, 12, 25)
for year in range(2008,2122)) if day.weekday() == sunday)
print '\n'.join(days)
 
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>.
yuletide()</lang>Output:
<pre>25 Dec 2011
25 Dec 2016
25 Dec 2022
25 Dec 2033
25 Dec 2039
25 Dec 2044
25 Dec 2050
25 Dec 2061
25 Dec 2067
25 Dec 2072
25 Dec 2078
25 Dec 2089
25 Dec 2095
25 Dec 2101
25 Dec 2107
25 Dec 2112
25 Dec 2118</pre>
 
=={{header|R}}==
<lang R>years <- 2008:2121
xmas <- as.POSIXlt(paste(years, '/12/25', sep=""))
years[xmas$wday==0]</lang>
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
 
Or, in terms of datetime:
<lang R>
{{Works with|Python|3.7}}
Also:
<syntaxhighlight lang="python">'''Days of the week'''
 
from datetime import date
from itertools import islice
 
 
# xmasIsSunday :: Int -> Bool
def xmasIsSunday(y):
'''True if Dec 25 in the given year is a Sunday.'''
return 6 == date(y, 12, 25).weekday()
 
 
# main :: IO ()
def main():
'''Years between 2008 and 2121 with 25 Dec on a Sunday'''
 
xs = list(filter(
xmasIsSunday,
enumFromTo(2008)(2121)
))
total = len(xs)
print(
fTable(main.__doc__ + ':\n\n' + '(Total ' + str(total) + ')\n')(
lambda i: str(1 + i)
)(str)(index(xs))(
enumFromTo(0)(total - 1)
)
)
 
 
# GENERIC -------------------------------------------------
 
# enumFromTo :: (Int, Int) -> [Int]
def enumFromTo(m):
'''Integer enumeration from m to n.'''
return lambda n: list(range(m, 1 + n))
 
 
# index (!!) :: [a] -> Int -> a
def index(xs):
'''Item at given (zero-based) index.'''
return lambda n: None if 0 > n else (
xs[n] if (
hasattr(xs, "__getitem__")
) else next(islice(xs, n, None))
)
 
 
 
# FORMATTING ---------------------------------------------
# fTable :: String -> (a -> String) ->
# (b -> String) -> (a -> b) -> [a] -> String
def fTable(s):
'''Heading -> x display function -> fx display function ->
f -> xs -> tabular string.
'''
def go(xShow, fxShow, f, xs):
ys = [xShow(x) for x in xs]
w = max(map(len, ys))
return s + '\n' + '\n'.join(map(
lambda x, y: y.rjust(w, ' ') + ' -> ' + fxShow(f(x)),
xs, ys
))
return lambda xShow: lambda fxShow: lambda f: lambda xs: go(
xShow, fxShow, f, xs
)
 
 
# MAIN --
if __name__ == '__main__':
main()</syntaxhighlight>
{{Out}}
<pre>Years between 2008 and 2121 with 25 Dec on a Sunday:
 
(Total 17)
 
1 -> 2011
2 -> 2016
3 -> 2022
4 -> 2033
5 -> 2039
6 -> 2044
7 -> 2050
8 -> 2061
9 -> 2067
10 -> 2072
11 -> 2078
12 -> 2089
13 -> 2095
14 -> 2101
15 -> 2107
16 -> 2112
17 -> 2118</pre>
 
=={{header|Quackery}}==
 
Using Tomohiko Sakamoto's algorithm.
 
<syntaxhighlight lang="quackery"> [ over 3 < if [ 1 - ]
dup 4 / over +
over 100 / -
swap 400 / +
swap 1 -
[ table
0 3 2 5 0 3
5 1 4 6 2 4 ]
+ + 7 mod ] is dayofweek ( day month year --> weekday )
 
say "The 25th of December is a Sunday in: " cr
2121 1+ 2008 - times
[ 25 12 i^ 2008 + dayofweek
0 = if [ i^ 2008 + echo sp ] ] </syntaxhighlight>
 
{{out}}
 
<pre>The 25th of December is a Sunday in:
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118 </pre>
 
=={{header|R}}==
<syntaxhighlight lang="r">years <- 2008:2121
xmas <- as.POSIXlt(paste0(years, '/12/25'))
years[xmas$wday==0]
# 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
 
# Also:
xmas=seq(as.Date("2008/12/25"), as.Date("2121/12/25"), by="year")
as.numeric(format(xmas[weekdays(xmas)== 'Sunday'], "%Y"))
 
</lang>
# Still another solution, using ISOdate and weekdays
with(list(years=2008:2121), years[weekdays(ISOdate(years, 12, 25)) == "Sunday"])
 
# Or with "subset"
subset(data.frame(years=2008:2121), weekdays(ISOdate(years, 12, 25)) == "Sunday")$years
 
# Simply replace "Sunday" with whatever it's named in your country,
# or set locale first, with
Sys.setlocale(cat="LC_ALL", "en")
 
# Under MS Windows, write instead
Sys.setlocale("LC_ALL", "English")</syntaxhighlight>
 
=={{header|Racket}}==
 
<syntaxhighlight lang="racket">
#lang racket
 
(require racket/date)
 
(define (xmas-on-sunday? year)
(zero? (date-week-day (seconds->date (find-seconds 0 0 12 25 12 year)))))
 
(for ([y (in-range 2008 2121)] #:when (xmas-on-sunday? y))
(displayln y))
</syntaxhighlight>
 
=={{header|Raku}}==
(formerly Perl 6)
 
{{works with|Rakudo|2010.07}}
 
As Perl 5, except <code>DateTime</code> is built-in, so you don't need to download a module of that name:
 
<syntaxhighlight lang="raku" line>say join ' ', grep { Date.new($_, 12, 25).day-of-week == 7 }, 2008 .. 2121;</syntaxhighlight>
 
=={{header|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">REBOL [
Title: "Yuletide Holiday"
Author: oofoe
Date: 2009-12-07
URL: http://rosettacode.org/wiki/Yuletide_Holiday
]
Line 1,283 ⟶ 4,977:
d: to-date reduce [y 12 25]
if 7 = d/weekday [prin [y ""]]
]</langsyntaxhighlight>
 
Output:
 
{{out}}
<pre>2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</pre>
 
=={{header|REXXRed}}==
<syntaxhighlight lang="red">Red []
===version 1===
repeat yy 114 [
<lang rexx>do year = 2008 to 2121
d: if to-date('w', year'1225',reduce 's')[25 =12 'Sunday'(2007 then+ sayyy year)]
if 7 = d/weekday [ print d ] ;; 7 = sunday
end</lang>
]
===version 2===
;; or
Alternative:
print "version 2"
<lang rexx>do year = 2008 to 2121
if date('b', year'1225', 's') // 7 = 6 then say year
end</lang>
 
d: to-date [25 12 2008]
Output from either:
while [d <= 25/12/2121 ] [
<pre>2011
if 7 = d/weekday [
print rejoin [d/day '. d/month '. d/year ]
]
d/year: d/year + 1
]
</syntaxhighlight>
{{out}}<pre>25-Dec-2011
25-Dec-2016
25-Dec-2022
25-Dec-2033
25-Dec-2039
25-Dec-2044
25-Dec-2050
25-Dec-2061
25-Dec-2067
25-Dec-2072
25-Dec-2078
25-Dec-2089
25-Dec-2095
25-Dec-2101
25-Dec-2107
25-Dec-2112
25-Dec-2118
version 2
25.12.2011
25.12.2016
25.12.2022
25.12.2033
25.12.2039
25.12.2044
25.12.2050
25.12.2061
25.12.2067
25.12.2072
25.12.2078
25.12.2089
25.12.2095
25.12.2101
25.12.2107
25.12.2112
25.12.2118
>>
</pre>
 
=={{header|REXX}}==
===using DATE weekday===
The extended &nbsp; DATE &nbsp; parameters (arguments 2 and 3) are only supported by the newer REXX interpreters.
<syntaxhighlight lang="rexx"> do year=2008 to 2121
if date('w', year"1225", 's') == 'Sunday' then say year
end /*year*/</syntaxhighlight>
{{out|output}}
<pre>
2011
2016
2022
Line 1,317 ⟶ 5,061:
2107
2112
2118</pre>
</pre>
 
===versionusing 3DATE base===
The extended DATE parameters (arguments 2 and 3) are only supported by the newer REXX interpreters.
<syntaxhighlight lang="rexx"> do year=2008 to 2121
<br>newer REXX interpreters.
if date('b', year"1225", 's') // 7 == 6 then say year
<br><br>
end /*year*/</syntaxhighlight>
Language note: the DATE built-in function always returns the day-of-week in English,
{{out|output|text=&nbsp; is identical to the 1<sup>st</sup> REXX version.}} <br><br>
<br>no matter what the native language is in effect.
<lang rexx>
/*REXX program displays which years December 25th falls on a Sunday. */
 
===using DATE iso===
parse arg start finish . /*get the start and finish years.*/
Works with Regina REXX only.
if start=='' then start=2008 /*None specified? Assume default*/
if finish=='' then finish=2121 /*None specified? Assume default*/
 
The extended &nbsp; DATE &nbsp; parameters (arguments 2 and 3) are only supported by the newer REXX interpreters.
do y=start to finish /*process the years specified. */
 
Programming note: &nbsp; The &nbsp; '''ISO''' &nbsp; option of the &nbsp; '''date''' &nbsp; BIF is a Regina extension.
if date('Weekday',y"-12-25",'ISO')\=='Sunday' then iterate
/* if date('w' ,y"-12-25",'i' )\== ... (same as above). */
/* option yyyy-mm-dd fmt */
 
Language note: &nbsp; the DATE &nbsp; built-in function always returns the day-of-week in English, no matter what the native language is in effect.
say 'December 25th,' y "falls on a Sunday."
<syntaxhighlight lang="rexx">/*REXX program displays in which years 12/25 (December 25th) falls on a Sunday. */
end
parse arg start finish . /*get the START and FINISH years. */
</lang>
if start=='' | start=="," then start=2008 /*Not specified? Then use the default.*/
Output (using the defaults):
if finish=='' | finish=="," then finish=2121 /* " " " " " " */
<pre style="height:15ex;overflow:scroll">
 
do y=start to finish /*process all the years specified. */
 
if date('Weekday', y"-12-25", 'ISO')\=='Sunday' then iterate
 
/* if date('w' , y"-12-25", 'i' ) ··· (same as above). */
/* ↑↑↑↑↑↑ ↑↑↑↑↑↑↑↑↑↑ ↑↑↑ */
/* option yyyy-mm-dd fmt */
 
say 'December 25th,' y "falls on a Sunday."
end /*y*/
/*stick a fork in it, we're all done. */</syntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
December 25th, 2011 falls on a Sunday.
December 25th, 2016 falls on a Sunday.
Line 1,362 ⟶ 5,116:
</pre>
 
===versionold school DOW 4===
This &nbsp; DOW &nbsp; (day-of-week) &nbsp; version will work with any version of a REXX interpreter.
<syntaxhighlight lang="rexx">/*REXX program (old school) displays in which years 12/25 (Dec. 25th) falls on a Sunday.*/
<lang rexx>
parse arg start finish . /*get the START and FINISH years. */
/*REXX program (old school) displays which years 12/25 falls on a Sunday*//
if start=='' | start=="," then start=2008 /*Not specified? Then use the default.*/
if finish=='' | finish=="," then finish=2121 /* " " " " " " */
 
parse arg do y=start to finish . /*getprocess all the startyears specified. and finish years.*/
if dow(12,25,y)==1 then say 'December 25th,' y "falls on a Sunday."
if start=='' then start=2008 /*None specified? Assume default*/
end /*y*/
if finish=='' then finish=2121 /*None specified? Assume default*/
exit /*stick a fork in it, we're all done. */
 
/*──────────────────────────────────────────────────────────────────────────────────────*/
do y=start to finish /*process the years specified. */
dow: procedure; parse arg m,d,y; if m<3 then do; m= m+12; y= y-1; end
if dow(12,25,y)==1 then say 'December 25th,' y "falls on a Sunday."
yL= left(y, 2); yr= right(y, 2); w= (d + (m+1)*26%10 +yr +yr%4 +yL%4 +5*yL) //7
end
if w==0 then w= 7; return w /*Sunday=1, Monday=2, ··· Saturday=7*/</syntaxhighlight>
 
{{out|output|text=&nbsp; when using the default input:}}
exit
<pre>
 
/*─────────────────────────────────────DOW (day of week) subroutine─────*/
dow: procedure; arg m,d,y; if m<3 then do; m=m+12; y=y-1; end
yL=left(y,2); yr=right(y,2); w=(d+(m+1)*26%10+yr+yr%4+yL%4+5*yL)//7
if w==0 then w=7; return w /*Sunday=1, Monday=2, ... Saturday=7*/
</lang>
Output (using the defaults):
<pre style="height:15ex;overflow:scroll">
December 25th, 2011 falls on a Sunday.
December 25th, 2016 falls on a Sunday.
Line 1,403 ⟶ 5,152:
</pre>
 
=={{header|RubyRing}}==
<syntaxhighlight lang="ring">
<lang ruby>require 'date'
for n = 2008 to 2121
if n < 2100 leap = n - 1900 else leap = n - 1904 ok
m = (((n-1900)%7) + floor(leap/4) + 27) % 7
if m = 4 see "25 Dec " + n + nl ok
next
</syntaxhighlight>
 
=={{header|RPL}}==
SUNDAY = 0
Early RPL versions do not have any date library, so a specific instruction implement Zeller's congruence with a stack-oriented algorithm.
{{works with|HP|28}}
≪ '''IF''' OVER 2 ≤ '''THEN''' 1 - SWAP 12 + SWAP '''END'''
100 MOD LAST / FLOOR
DUP 4 / FLOOR SWAP DUP + - SWAP DUP 4 / FLOOR + +
SWAP 1 + 13 * 5 / FLOOR + +
7 MOD 5 + 7 MOD 1 +
≫ '<span style="color:blue">WKDAY</span>' STO
In 1990, RPL gained some basic functions for calculating the date, but nothing for directly obtaining the day of the week.
{{works with|HP|48}}
≪ { "MON" TUE" "WED" "THU" "FRI" "SAT" "SUN" }
SWAP 0 TSTR 1 3 SUB POS
≫ '<span style="color:blue">WKDAY</span>' STO <span style="color:grey">@ ( dd.mmyyyy → 1..7 )</span>
 
for year{ in} 2008.. 2121 '''FOR''' year
'''IF''' 25 12 year <span style="color:blue">WKDAY</span> 7 == '''THEN''' year + '''END NEXT'''
day = Date.new(year, 12, 25)
≫ EVAL
if day.wday == SUNDAY
{{out}}
puts '25 Dec %d' % year
<pre>
end
1: { 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118 }
end</lang>
</pre>
Output:
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">require 'date'
 
(2008..2121).each {|year| puts "25 Dec #{year}" if Date.new(year, 12, 25).sunday? }</syntaxhighlight>
{{out}}
<pre>
25 Dec 2011
Line 1,435 ⟶ 5,209:
</pre>
 
Or using the Time class
The Time class overflows at the Unix epoch in 2038:
<syntaxhighlight lang="ruby">(2008..2121).each {|year| puts "25 Dec #{year}" if Time.local(year, 12, 25).sunday?}</syntaxhighlight>
<lang ruby>SUNDAY = 0
{{output}}
 
for year in 2008..2121
begin
day = Time.local(year, 12, 25)
if day.wday == SUNDAY
puts '25 Dec %d' % year
end
rescue ArgumentError
puts '%d is the last year we can specify' % (year-1)
break
end
end</lang>
Output on 32-bit machine:
<pre>
25 Dec 2011
Line 1,455 ⟶ 5,217:
25 Dec 2022
25 Dec 2033
25 Dec 2039
2037 is the last year we can specify
25 Dec 2044
25 Dec 2050
25 Dec 2061
25 Dec 2067
25 Dec 2072
25 Dec 2078
25 Dec 2089
25 Dec 2095
25 Dec 2101
25 Dec 2107
25 Dec 2112
25 Dec 2118
</pre>
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">extern crate chrono;
 
use chrono::prelude::*;
 
fn main() {
let years = (2008..2121).filter(|&y| Local.ymd(y, 12, 25).weekday() == Weekday::Sun).collect::<Vec<i32>>();
println!("Years = {:?}", years);
}</syntaxhighlight>
 
Output:
<pre>Years = [2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]
</pre>
 
=={{header|SAS}}==
<syntaxhighlight lang="sas">data _null_;
do y=2008 to 2121;
a=mdy(12,25,y);
if weekday(a)=1 then put y;
end;
run;
 
/* 2011 2016 2022 2033 2039 2044 2050 2061 2067
2072 2078 2089 2095 2101 2107 2112 2118 */</syntaxhighlight>
 
=={{header|Scala}}==
{{libheader|Scala}}
===JDK (discouraged) ===
<syntaxhighlight lang="scala">import java.util.{ Calendar, GregorianCalendar }
import Calendar.{ DAY_OF_WEEK, DECEMBER, SUNDAY }
 
object DayOfTheWeek extends App {
<lang scala>
val years = 2008 to 2121
import java.util.{Calendar, GregorianCalendar}
import Calendar._
 
val yuletide =
object DayOfTheWeek {
years.filter(year => (new GregorianCalendar(year, DECEMBER, 25)).get(DAY_OF_WEEK) == SUNDAY)
 
// If you want a test: (optional)
def main(args:Array[String]) {
assert(yuletide ==
for (year <- 2008 to 2121;
Seq(2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061,
date <- Some(new GregorianCalendar(year, DECEMBER, 25));
2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118))
if date.get(DAY_OF_WEEK) == SUNDAY) {
 
println(year)
println(yuletide.mkString(
s"${yuletide.length} Years between ${years.head} and ${years.last}" +
" including where Christmas is observed on Sunday:\n", ", ", "."))
}</syntaxhighlight>
===JDK >= 8 (recommended)===
====Naive programming====
<syntaxhighlight lang="scala">import java.time.{ DayOfWeek, LocalDate }
 
object DayOfTheWeek1 extends App {
val years = 2008 to 2121
val yuletide = for {
year <- years
if LocalDate.of(year, 12, 25).getDayOfWeek() == DayOfWeek.SUNDAY
} yield year
 
println(yuletide.mkString(
s"${yuletide.count(p => true)} Years between ${years.head} and ${years.last}" +
" including where Christmas is observed on Sunday:\n", ", ", "."))
}</syntaxhighlight>
====Idiomatic programming====
<syntaxhighlight lang="scala">import java.time.{ DayOfWeek, LocalDate }
 
object DayOfTheWeek1 extends App {
val years = 2008 to 2121
val yuletide =
years.filter(year => (LocalDate.of(year, 12, 25).getDayOfWeek() == DayOfWeek.SUNDAY))
 
// If you want a test: (optional)
assert(yuletide ==
Seq(2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061,
2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118))
 
println(yuletide.mkString(
s"${yuletide.length} Years between ${years.head} and ${years.last}" +
" including where Christmas is observed on Sunday:\n", ", ", "."))
}</syntaxhighlight>
====Tail recursion====
<syntaxhighlight lang="scala">import java.time.{ DayOfWeek, LocalDate }
import scala.annotation.tailrec
 
object DayOfTheWeek3 extends App {
val years = 2008 to 2121
val yuletide = {
@tailrec
def inner(anni: List[Int], accu: List[Int]): List[Int] = {
if (anni == Nil) accu
else inner(anni.tail, accu ++
(if (LocalDate.of(anni.head, 12, 25).getDayOfWeek() == DayOfWeek.SUNDAY) List(anni.head)
else Nil))
}
inner(years.toList, Nil)
}
}
</lang>
 
// If you want a test: (optional)
Output:<pre>
assert(yuletide ==
2011
Seq(2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061,
2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118))
 
println(yuletide.mkString(
s"${yuletide.length} Years between ${years.head} and ${years.last}" +
" including where Christmas is observed on Sunday:\n", ", ", "."))
}</syntaxhighlight>
{{out | Output of all solutions }}
<pre>Years between 2008 and 2121 including when Christmas is observed on Sunday:
2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118.</pre>
 
=={{header|Scheme}}==
<syntaxhighlight lang="scheme">(define (day-of-week year month day)
(if (< month 3)
(begin (set! month (+ month 12)) (set! year (- year 1))))
(+ 1
(remainder (+ 5 day (quotient (* (+ 1 month) 13) 5)
year (quotient year 4) (* (quotient year 100) 6) (quotient year 400))
7)))
 
(define (task)
(let loop ((y 2121) (v '()))
(if (< y 2008)
v
(loop (- y 1)
(if (= 7 (day-of-week y 12 25))
(cons y v)
v)))))
 
(task)
; (2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118)</syntaxhighlight>
 
=={{header|Seed7}}==
The library [http://seed7.sourceforge.net/libraries/time.htm time.s7i] defines
the function [http://seed7.sourceforge.net/libraries/time.htm#dayOfWeek%28in_time%29 dayOfWeek],
which returns 1 for monday, 2 for tuesday, and so on up to 7 for sunday.
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "time.s7i";
 
const proc: main is func
local
var integer: year is 0;
begin
for year range 2008 to 2122 do
if dayOfWeek(date(year, 12, 25)) = 7 then
writeln("Christmas comes on a sunday in " <& year);
end if;
end for;
end func;</syntaxhighlight>
{{out}}
<pre>
Christmas comes on a sunday in 2011
Christmas comes on a sunday in 2016
Christmas comes on a sunday in 2022
Christmas comes on a sunday in 2033
Christmas comes on a sunday in 2039
Christmas comes on a sunday in 2044
Christmas comes on a sunday in 2050
Christmas comes on a sunday in 2061
Christmas comes on a sunday in 2067
Christmas comes on a sunday in 2072
Christmas comes on a sunday in 2078
Christmas comes on a sunday in 2089
Christmas comes on a sunday in 2095
Christmas comes on a sunday in 2101
Christmas comes on a sunday in 2107
Christmas comes on a sunday in 2112
Christmas comes on a sunday in 2118
</pre>
 
=={{header|SenseTalk}}==
<syntaxhighlight lang="sensetalk">// In what years between 2008 and 2121 will the 25th of December be a Sunday?
 
repeat with year = 2008 to 2121
set Christmas to "12/25/" & year
if the WeekDayName of Christmas is Sunday then
put "Christmas in " & year & " falls on a Sunday"
end if
end repeat</syntaxhighlight>
{{out}}
<pre>
Christmas in 2011 falls on a Sunday
Christmas in 2016 falls on a Sunday
Christmas in 2022 falls on a Sunday
Christmas in 2033 falls on a Sunday
Christmas in 2039 falls on a Sunday
Christmas in 2044 falls on a Sunday
Christmas in 2050 falls on a Sunday
Christmas in 2061 falls on a Sunday
Christmas in 2067 falls on a Sunday
Christmas in 2072 falls on a Sunday
Christmas in 2078 falls on a Sunday
Christmas in 2089 falls on a Sunday
Christmas in 2095 falls on a Sunday
Christmas in 2101 falls on a Sunday
Christmas in 2107 falls on a Sunday
Christmas in 2112 falls on a Sunday
Christmas in 2118 falls on a Sunday
</pre>
 
=={{header|Sidef}}==
{{trans|Perl}}
<syntaxhighlight lang="ruby">require('Time::Local')
 
for year in (2008 .. 2121) {
var time = %S<Time::Local>.timelocal(0,0,0,25,11,year)
var wd = Time(time).local.wday
if (wd == 0) {
say "25 Dec #{year} is Sunday"
}
}</syntaxhighlight>
{{out}}
<pre>
25 Dec 2011 is Sunday
25 Dec 2016 is Sunday
25 Dec 2022 is Sunday
25 Dec 2033 is Sunday
25 Dec 2039 is Sunday
25 Dec 2044 is Sunday
25 Dec 2050 is Sunday
25 Dec 2061 is Sunday
25 Dec 2067 is Sunday
25 Dec 2072 is Sunday
25 Dec 2078 is Sunday
25 Dec 2089 is Sunday
25 Dec 2095 is Sunday
25 Dec 2101 is Sunday
25 Dec 2107 is Sunday
25 Dec 2112 is Sunday
25 Dec 2118 is Sunday
</pre>
 
=={{header|Simula}}==
{{trans|Sinclair ZX81 BASIC}}
<syntaxhighlight lang="simula">BEGIN
INTEGER M,D,Y;
M := 12;
D := 25;
FOR Y := 2008 STEP 1 UNTIL 2121 DO BEGIN
INTEGER W,A,MM,YY;
A := (14 - M)//12;
MM := M + 12*A - 2;
YY := Y - A;
W := D + ((13*MM - 1)//5) + YY + (YY//4) - (YY//100) + (YY//400);
W := MOD(W,7);
IF W = 0 THEN
BEGIN OUTINT(Y,0);
OUTIMAGE;
END;
END;
END.</syntaxhighlight>
{{out}}
<pre>2011
2016
2022
Line 1,496 ⟶ 5,500:
 
=={{header|Smalltalk}}==
<langsyntaxhighlight lang="smalltalk">2008 to: 2121 do: [ :year | |date|
date := Date newDay: 25 monthIndex: 12 year: year.
date dayName = #Sunday
ifTrue: [ date displayNl ]
]</langsyntaxhighlight>
 
{{out}}
Output:
<pre>25-Dec-2011
25-Dec-2016
Line 1,520 ⟶ 5,524:
25-Dec-2112
25-Dec-2118</pre>
 
=={{header|SparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "yuletide" );
pragma annotate( description, "A company decides that whenever Xmas falls on a Sunday they will give their" );
pragma annotate( description, "workers all extra paid holidays so that, together with any public holidays," );
pragma annotate( description, "workers will not have to work the following week (between the 25th of" );
pragma annotate( description, "December and the first of January)." );
pragma annotate( description, "");
pragma annotate( description, "In what years between 2008 and 2121 will the 25th of December be a Sunday?" );
pragma annotate( description, "");
pragma annotate( description, "Using any standard date handling libraries of your programming language;" );
pragma annotate( description, "compare the dates calculated with the output of other languages to discover" );
pragma annotate( description, "any anomalies in the handling of dates which may be due to, for example," );
pragma annotate( description, "overflow in types used to represent dates/times similar to y2k type" );
pragma annotate( description, "problems. ");
pragma annotate( see_also, "http://rosettacode.org/wiki/Day_of_the_week" );
pragma annotate( author, "Ken O. Burtch ");
pragma license( unrestricted );
 
pragma restriction( no_external_commands );
 
procedure yuletide is
begin
for Year in 2008..2121 loop
if calendar.day_of_week ( calendar.time_of (Year, 12, 25, 0)) = 1 then
put_line( "Christmas " & strings.image( Year ) & " is on a Sunday" );
end if;
end loop;
end yuletide;</syntaxhighlight>
 
=={{header|SQL}}==
===Oracle===
SQL has good support for date functions; care must be taken with NLS settings (globalization support), in the code below the date format language is passed in as an argument to the relevant function. (Or, see a variation that does not depend on language settings, after the output shown below.)
 
<syntaxhighlight lang="sql">select extract(year from dt) as year_with_xmas_on_sunday
from (
select add_months(date '2008-12-25', 12 * (level - 1)) as dt
from dual
connect by level <= 2121 - 2008 + 1
)
where to_char(dt, 'Dy', 'nls_date_language=English') = 'Sun'
order by 1
;</syntaxhighlight>
 
 
{{out}}
<pre>
YEAR_WITH_XMAS_ON_SUNDAY
------------------------
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
 
17 rows selected.</pre>
 
Alternatively, the WHERE clause can be written in a way that avoids the complication of language settings. The (overloaded) TRUNC function, as applied to dates, takes a second argument indicating "to what" we must truncate. One option is 'iw' for "ISO week"; this truncates to the most recent Monday (the beginning of the ISO standard week, which is Monday through Sunday by definition). Like so (replace in the query above):
 
 
<syntaxhighlight lang="sql">where dt - trunc(dt, 'iw') = 6</syntaxhighlight>
 
===SQLite3===
<syntaxhighlight lang="sql">WITH RECURSIVE cte AS (
SELECT DATE('2008-12-25', '+'||(12*0)||' months') as dt, 1 AS level
UNION ALL
SELECT DATE('2008-12-25', '+'||(12*level)||' months') as dt, c.level + 1
FROM cte c
WHERE c.level <= 2121 - 2008 + 1
)
SELECT strftime('%Y', dt)
FROM cte
where strftime('%w', dt) = '0';
</syntaxhighlight>
 
===PostgreSQL===
<syntaxhighlight lang="sql"> WITH RECURSIVE cte AS (
SELECT date '2008-12-25' + interval '12 month' * 0 as dt, 1 AS level
UNION ALL
SELECT date '2008-12-25' + interval '12 month' * level as dt, c.level + 1
FROM cte c
WHERE c.level <= 2121 - 2008 + 1
)
SELECT dt
FROM cte
where to_char(dt, 'Dy') = 'Sun';
</syntaxhighlight>
 
=={{header|Standard ML}}==
<syntaxhighlight lang="sml">(* Call: yearsOfSundayXmas(2008, 2121) *)
fun yearsOfSundayXmas(fromYear, toYear) =
if fromYear>toYear then
()
else
let
val d = Date.date {year=fromYear, month=Date.Dec, day=25,
hour=0, minute=0, second=0,
offset=SOME Time.zeroTime}
val wd = Date.weekDay d
in
if wd=Date.Sun then
(
print(Int.toString fromYear ^ "\n");
yearsOfSundayXmas(fromYear+1, toYear)
)
else
yearsOfSundayXmas(fromYear+1, toYear)
end;</syntaxhighlight>
 
{{out}}
<pre>- yearsOfSundayXmas(2008, 2121);
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
=={{header|Stata}}==
 
The [https://www.stata.com/help.cgi?dow() <code>dow()</code>] function returns the day of week, where sunday is zero and saturday is 6.
<syntaxhighlight lang="stata">clear
sca n=2121-2008+1
set obs `=n'
gen year=2007+_n
list if dow(mdy(12,25,year))==0, noobs sep(0)
 
+------+
| year |
|------|
| 2011 |
| 2016 |
| 2022 |
| 2033 |
| 2039 |
| 2044 |
| 2050 |
| 2061 |
| 2067 |
| 2072 |
| 2078 |
| 2089 |
| 2095 |
| 2101 |
| 2107 |
| 2112 |
| 2118 |
+------+</syntaxhighlight>
 
=== Mata ===
 
<syntaxhighlight lang="mata">year=2008::2121
select(year,dow(mdy(12,25,year)):==0)</syntaxhighlight>
 
=={{header|Suneido}}==
<langsyntaxhighlight Suneidolang="suneido">year = 2008
while (year <= 2121)
{
Line 1,528 ⟶ 5,710:
Print(year)
++year
}</langsyntaxhighlight>
{{out}}
Output:
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118</pre>
 
=={{header|Swift}}==
<syntaxhighlight lang="swift">import Cocoa
 
var year=2008
let formatter=DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
 
let gregorian:NSCalendar! = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian)
while (year<2122){
var date:NSDate!=formatter.date(from: String(year)+"-12-25") as NSDate?
var components=gregorian.components(NSCalendar.Unit.weekday, from: date as Date)
var dayOfWeek:NSInteger=components.weekday!
if(dayOfWeek==1){
print(year)
}
year+=1
}
</syntaxhighlight>
{{out}}
<pre>2011
2016
Line 1,550 ⟶ 5,769:
=={{header|Tcl}}==
{{works with|Tcl|8.5}}
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
 
for {set y 2008} {$y <= 2121} {incr y} {
Line 1,556 ⟶ 5,775:
puts "xmas $y is a sunday"
}
}</langsyntaxhighlight>
{{out}}
outputs
<pre>xmas 2011 is a sunday
xmas 2016 is a sunday
Line 1,576 ⟶ 5,795:
xmas 2118 is a sunday</pre>
 
=={{header|TI-83 BASIC}}==
'''Works with''' TI-84+/SE only
<lang ti83b>
:For(A, 2008,2121
:dayofWk(A,12,25
:If Ans=1
:Disp A
:End
</lang>
outputs
<pre>2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
Done</pre>
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
PRINT "25th of December will be a Sunday in the following years: "
Line 1,612 ⟶ 5,803:
IF (dayofweek==7) PRINT year
ENDLOOP
</syntaxhighlight>
</lang>
{{out}}
Output:
<pre>
25th of December will be a Sunday in the following years:
Line 1,633 ⟶ 5,824:
2112
2118
</pre>
 
== {{header|TypeScript}} ==
{{trans|Minimal BASIC}}
<syntaxhighlight lang="javascript">
// Find years with Sunday Christmas
var f = 2008;
var t = 2121;
console.log(`Sunday Christmases ${f} - ${t}`);
for (y = f; y <= t; y++) {
var x = (y * 365) + Math.floor(y / 4) - Math.floor(y / 100) + Math.floor(y / 400) - 6;
if (x % 7 == 0)
process.stdout.write(`${y}\t`);
}
process.stdout.write("\n");
</syntaxhighlight>
{{out}}
<pre>
Sunday Christmases 2008 - 2121
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
=={{header|UNIX Shell}}==
Unix commands may use ''time_t'' to count seconds since the [[show the epoch|epoch]]. For systems with 32-bit time, the counter overflows during 19 January 2038. These scripts continue to 2121 and may need a system with 64-bit time, to prevent the overflow.
 
===With GNU date===
This solution uses date -d, which seems to be a [[GNU]] extension, so it only works with those systems.
 
{{works with|bash}}
<langsyntaxhighlight lang="bash">#! /bin/bash
 
for (( i=2008; i<=2121; ++i ))
Line 1,647 ⟶ 5,860:
done |grep Sun
 
exit 0</langsyntaxhighlight>
 
The first lines of output (from a 32bit GNU/Linux system with 32bit time_t, date version 6.9) are
 
<langsyntaxhighlight lang="bash">Sun Dec 25 00:00:00 CET 2011
Sun Dec 25 00:00:00 CET 2016
Sun Dec 25 00:00:00 CET 2022
Sun Dec 25 00:00:00 CET 2033
date: invalid date `2038-12-25'</langsyntaxhighlight>
 
I.e., starting from year 2038, the <tt>date</tt> command (which uses the glibc library, at least on GNU systems), is not able to recognise the date as a valid one!
 
''Different machine/OS version (64 bit time_t):''
This is the same command run on RedHat Linux.
<langsyntaxhighlight lang="bash">bash-3.00$ date --version
date (coreutils) 5.2.1
Written by David MacKenzie.
Line 1,688 ⟶ 5,901:
Sun Dec 25 00:00:00 GMT 2112
Sun Dec 25 00:00:00 GMT 2118
bash-3.00$</langsyntaxhighlight>
 
===With GNU date and GNU seq ({{header|UnixPipes}})===
Like the previous solution, this solution uses date -d, which seems to be a [[GNU]] extension. Output is same as previous solution.
 
<syntaxhighlight lang="bash">seq 2008 2121 | xargs -IYEAR -n 1 date +%c -d 'Dec 25 YEAR' | grep Sun</syntaxhighlight>
 
===With Unix cal===
Line 1,703 ⟶ 5,921:
</pre>
 
This format always puts Sunday in columns 1 and 2,. so thisThe solution canuses check''tail'' ifto "25"delete appearsthe infirst those2 columns.lines (Alsomonth, the year, isnames notof adays), problem''cut'' forto extract Sunday.'s Checkingcolumns, ifand 20''grep'' Decemberto 2011check is a Thursday? The yearif "201125" onappears thein firstthose line would have broken the check.) If your <code>cal</code> uses a different format, then you would need to edit the scriptcolumns.
 
{{works with|OpenBSD|4.8Bourne Shell}}
<langsyntaxhighlight shlang="bash">y=2008
while test $y -lt 2122; do
cal 12 $y | tail +3 | cut -c1-2 | grep -Fq 25 && echo 25 Dec $y
y=`expr $y + 1`
done</langsyntaxhighlight>
 
Running this script with [[OpenBSD]], the output is identical to the C# program. OpenBSD <code>''cal</code>'' acceptedaccepts allany yearsyear from 1 to 9999, so 2008 to 2122 wasis well within range. The output was identical to the C# program.
 
===With zsh===
=={{header|UnixPipes}}==
<syntaxhighlight lang="bash">zmodload zsh/datetime
This solution uses date -d, which seems to be a [[GNU]] extension, so it only works with those systems.
for (( year = 2010; year <= 2121; year++ ));
 
if [[ $(strftime '%A' $(strftime -r '%F' $year-12-25)) == Sunday ]] print $year</syntaxhighlight>
Thanks to UNIX Shell implementation
<lang bash>seq 2008 2121 | xargs -IYEAR -n 1 date +%c -d 'Dec 25 YEAR' | grep Sun</lang>
 
If the system has 32-bit time, this script will malfunction for years >= 2038; it will print no year from 2038 to 2121 (unless today is Sunday, then it prints every year from 2038 to 2121). This happens because ''strftime -r '%F' $year-12-25'' yields -1 for an out-of-range date, and ''strftime '%A' -1'' yields name of today.
(Output same as UNIX Shell)
 
=={{header|Ursala}}==
Line 1,735 ⟶ 5,952:
date with the weekday included. The output is then filtered for Sundays.
 
<langsyntaxhighlight Ursalalang="ursala">#import std
#import nat
#import stt
Line 1,743 ⟶ 5,960:
#show+
 
sunday_years = ~&zS sep` * =]'Sun'*~ christmases</langsyntaxhighlight>
{{out}}
output:
<pre>2011
2016
Line 1,764 ⟶ 5,981:
 
=={{header|Vedit macro language}}==
<langsyntaxhighlight lang="vedit">Buf_Switch(Buf_Free)
for (#3 = 2008; #3 < 2122; #3++) {
Reg_Set(10, "12/25/")
Line 1,771 ⟶ 5,988:
Num_Ins(#3, NOCR)
}
}</langsyntaxhighlight>
 
{{out}}
Output:
<pre>
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
=={{header|ZshVisual Objects}}==
<syntaxhighlight lang="visualfoxpro">
<lang zsh>zzmodload zsh/datetime
local i as dword
for (( year = 2010; year <= 2121; year++ ));
if [[ $(strftime '%A' $(strftime -r '%F' $year-12-25)) == Sunday ]] print $year</lang>
for i := 2008 upto 2121
if DOW(ConDate(i, 12, 25)) = 1
? AsString(i)
endif
next i
</syntaxhighlight>
 
{{out}}
{{omit from|PARI/GP|No standard date handling library}}
<pre>
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
=={{header|V (Vlang)}}==
[[Category:Date and time]]
Updated for Vlang version 0.2.2
<syntaxhighlight lang="go">import time
 
fn main() {
for year := 2008; year <= 2121; year++ {
date := time.parse('${year}-12-25 00:00:00') or { continue }
if date.long_weekday_str() == 'Sunday' {
println('December 25 ${year} is a ${date.long_weekday_str()}')
}
}
}</syntaxhighlight>
 
{{out}}
<pre>
December 25 2011 is a Sunday
December 25 2016 is a Sunday
December 25 2022 is a Sunday
December 25 2033 is a Sunday
December 25 2039 is a Sunday
December 25 2044 is a Sunday
December 25 2050 is a Sunday
December 25 2061 is a Sunday
December 25 2067 is a Sunday
December 25 2072 is a Sunday
December 25 2078 is a Sunday
December 25 2089 is a Sunday
December 25 2095 is a Sunday
December 25 2101 is a Sunday
December 25 2107 is a Sunday
December 25 2112 is a Sunday
December 25 2118 is a Sunday
</pre>
 
=={{header|VTL-2}}==
{{Trans|ALGOL W}}...which is {{Trans|Fortran}}
VTL-2 does not have operator precedence - all expressions are evaluated left-to-right, except for expressions nested in parenthesis, hence the expression at line 1090 differs from that in the Algol W sample.
<syntaxhighlight lang="vtl2">1000 #=2000
1010 R=!
1020 N=M
1030 X=Y
1040 #=N>3*1070
1050 N=N+12
1060 X=X-1
1070 J=X/100
1080 K=%
1090 W=N+1*26/10+D+K+(K/4)+(J/4)+(5*J)/7*0+%
1100 #=R
2000 ?="25th of December is a Sunday in";
2010 Y=2008
2020 M=12
2030 D=25
2040 #=1010
2050 #=W=1=0*2080
2060 $=32
2070 ?=Y
2080 Y=Y+1
2090 #=Y<2121*2040
2100 ?=""</syntaxhighlight>
{{out}}
<pre>
25th of December is a Sunday in 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</pre>
 
=={{header|Wortel}}==
<syntaxhighlight lang="wortel">!-&y = 0 `.getDay. @new Date[y 11 25] @range[2008 2121]</syntaxhighlight>
Returns: <pre>[2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118]</pre>
 
=={{header|Wren}}==
{{libheader|Wren-date}}
<syntaxhighlight lang="wren">import "./date" for Date
 
System.print("Years between 2008 and 2121 when 25th December falls on Sunday:")
for (year in 2008..2121) {
if (Date.new(year, 12, 25).dayOfWeek == 7) System.print(year)
}</syntaxhighlight>
 
{{out}}
<pre>
Years between 2008 and 2121 when 25th December falls on Sunday:
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|XPL0}}==
The original routine in the library only worked correctly between the years
1980 and 2099. It was upgraded with this new routine that handles all dates in
the Gregorian calendar, from 1583 onward. It's based on Zeller's Congruence.
 
<syntaxhighlight lang="xpl0">include c:\cxpl\codes; \intrinsic 'code' declarations
 
func WeekDay(Year, Month, Day); \Return day of week (0=Sat 1=Sun..6=Fri)
int Year, Month, Day;
[if Month<=2 then [Month:= Month+12; Year:= Year-1];
return rem((Day + (Month+1)*26/10 + Year + Year/4 + Year/100*6 + Year/400) / 7);
]; \WeekDay
 
 
int Year;
[for Year:= 2008 to 2121 do
if WeekDay(Year, 12, 25) = 1 then \25th of December is a Sunday
[IntOut(0, Year); CrLf(0)];
]</syntaxhighlight>
 
{{out}}
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|zkl}}==
ISO dates, monday is 1, sunday is 7
<syntaxhighlight lang="zkl">var [const] D=Time.Date;
foreach y in ([2008..2121]){
if (D.Sunday==D.weekDay(y,12,25)) println(y)
}</syntaxhighlight>
Or, in a more functional manner:
<syntaxhighlight lang="zkl">var [const] D=Time.Date;
[2008..2121].filter(fcn(y){ D.Sunday==D.weekDay(y,12,25) }).println()</syntaxhighlight>
{{out}}
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
 
=={{header|zonnon}}==
<syntaxhighlight lang="zonnon">
module Main;
(*Access to Mono System package *)
import System;
 
var
now: System.DateTime;
begin
now := System.DateTime.Now;
System.Console.Write(now.ToString("yyyy-MM-dd :"));
System.Console.WriteLine(now.DayOfWeek);
end Main.
</syntaxhighlight>
{{Out}}
<pre>
2017-12-05 :Tuesday
</pre>
9,476

edits