Jump to content

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

m
syntax highlighting fixup automation
(J)
m (syntax highlighting fixup automation)
Line 8:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V weekDays = [‘Sunday’, ‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’]
V thisXMas = Time(2021, 12, 25)
V thisXMasDay = Int(thisXMas.strftime(‘%w’))
Line 17:
V nextNewYearDay = Int(nextNewYear.strftime(‘%w’))
V nextNewYearDayAsString = weekDays[nextNewYearDay]
print(‘Next new year is on a ’nextNewYearDayAsString)</langsyntaxhighlight>
 
{{out}}
Line 26:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_Io;
with Ada.Calendar.Formatting;
 
Line 50:
Info (Christmas_Day);
Info (New_Years_Day);
end Weekdays;</langsyntaxhighlight>
{{out}}
<pre>
Line 59:
=={{header|ALGOL W}}==
Re-using code from the [[Day of the week]] task.
<langsyntaxhighlight lang="algolw">begin % find the day of the week 25/12/2021 and 01/01/2022 fall on %
string(10) array dayName( 0 :: 6 );
integer procedure Day_of_week ( integer value d, m, y );
Line 79:
write( "25th of December 2021 is a ", dayName( Day_of_week( 25, 12, 2021 ) ) );
write( " 1st of January 2022 is a ", dayName( Day_of_week( 1, 1, 2022 ) ) )
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 87:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">FormatTime, xmas , 20211225, dddd
FormatTime, newYear , 20220101, dddd
MsgBox % result := "Christmas Day, 2021 : " xmas "`nNew Year's Day, 2022 : " newYear</langsyntaxhighlight>
{{out}}
<pre>Christmas Day, 2021 : Saturday
Line 95:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f WHAT_WEEKDAYS_WILL_CHRISTMAS_AND_NEW_YEAR.AWK
BEGIN {
Line 107:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 118:
 
=={{header|BASIC}}==
<langsyntaxhighlight lang="gwbasic">10 DEFINT A-Z
20 DIM D$(6)
30 FOR I=0 TO 6: READ D$(I): NEXT
Line 132:
130 DATA Saturday,Sunday,Monday,Tuesday,Wednesday,Thursday,Friday
140 DATA 2021,12,25
150 DATA 2022,1,1</langsyntaxhighlight>
{{out}}
<pre>12/25/2021 is a Saturday
Line 138:
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
let dayofweek(y,m,d) = valof
Line 166:
$( show(2021,12,25)
show(2022,1,1)
$)</langsyntaxhighlight>
{{out}}
<pre>12/25/2021 is a Saturday
Line 172:
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#define _XOPEN_SOURCE
#include <stdio.h>
#include <time.h>
Line 186:
}
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>2021-12-25 is a Saturday
Line 192:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">day_of_week = proc (d: date) returns (string)
own days: array[string] := array[string]$
[0:"Saturday", "Sunday", "Monday", "Tuesday",
Line 218:
stream$putl(po, date$unparse_date(d) || " is a " || day_of_week(d))
end
end start_up</langsyntaxhighlight>
{{out}}
<pre>25 December 2021 is a Saturday
Line 224:
 
=={{header|COBOL}}==
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. XMASNY.
Line 298:
MULTIPLY 7 BY D7.
COMPUTE D = D - D7 + 1.
MOVE DAYS(D) TO DAY-NAME.</langsyntaxhighlight>
{{out}}
<pre>25/12/2021 is a Saturday
Line 304:
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
record Date is
Line 353:
print_nl();
i := i + 1;
end loop;</langsyntaxhighlight>
{{out}}
<pre>25/12/2021 is a Saturday
Line 359:
 
=={{header|Draco}}==
<langsyntaxhighlight lang="draco">type Date = struct {
word year;
byte month, day
Line 398:
writeln(" is a ", day_name(dates[i]))
od
corp</langsyntaxhighlight>
{{out}}
<pre>12/25/2021 is a Saturday
Line 404:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// Show day of week for Christmas Day, 2021 and New Year's Day, 2022. Nigel Galloway: December 1st., 2021
printfn $"Christmas Day 2021 is a %s{string(System.DateTime(2021,12,25).DayOfWeek)}. New Years Day 2022 is a %s{string(System.DateTime(2022,1,1).DayOfWeek)}."
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 415:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<langsyntaxhighlight lang="factor">USING: calendar calendar.english calendar.holidays.us formatting
kernel sequences ;
 
Line 427:
: .holidays ( seq -- ) [ dup holidays msg printf ] each ;
 
{ 1578 1590 1642 1957 2020 2021 2022 2242 2245 2393 } .holidays</langsyntaxhighlight>
{{out}}
<pre>
Line 443:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">#include "vbcompat.bi" 'contains functions for dealing with dates and times
#include "string.bi" 'contains functions for formatting text strings
 
Line 450:
 
print "Christmas Day 2021 is on a "; format(christmas,"dddd")
print "New Year's Day 2022 is on a "; format(newyears, "dddd")</langsyntaxhighlight>
{{out}}<pre>
Christmas Day 2021 is on a Saturday
Line 457:
 
=={{header|J}}==
<langsyntaxhighlight Jlang="j"> (weekday 2021 12 25){::;:'Sun Mon Tue Wed Thu Fri Sat'
Sat
(weekday 2022 01 01){::;:'Sun Mon Tue Wed Thu Fri Sat'
Sat</langsyntaxhighlight>
=={{header|jq}}==
{{works with|jq}}
Line 467:
Years, output format, and output are exactly as for [[#Wren|Wren]].
 
<langsyntaxhighlight lang="jq">def weekdaynames:
["Sunday", "Monday","Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
 
Line 475:
 
1578, 1590, 1642, 1957, 2020, 2021, 2022, 2242, 2245, 2393
| "In \(.), New year's day is on a \(weekday(.;1;1)), and Christmas day on \(weekday(.;12;25))."</langsyntaxhighlight>
{{out}}
As for [[#Wren]]
Line 481:
=={{header|Julia}}==
See also https://docs.julialang.org/en/v1/stdlib/Dates/#Dates.format-Tuple{TimeType,%20AbstractString}
<langsyntaxhighlight lang="julia">using Dates
 
for year in [1578, 1590, 1642, 1957, 2020, 2021, 2022, 2242, 2245, 2393]
Line 487:
" and Christmas: ", Dates.format(DateTime(year, 12, 25), "E, U d, Y"))
end
</langsyntaxhighlight>{{out}}
<pre>
Year 1578, New Years's Day: Sunday, January 1, 1578 and Christmas: Monday, December 25, 1578
Line 502:
 
=={{header|ooRexx}}==
<langsyntaxhighlight lang="oorexx">/* REXX */
Call wkd 2021,12,25
Call wkd 2022,01,01
Line 511:
dt=.DateTime~new(y,m,d)
say d'.'m'.'y 'is a' wd[dt~weekday]
Return</langsyntaxhighlight>{{out}}
<pre>25.12.2021 is a Saturday
01.01.2022 is a Saturday<</pre>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/What_weekdays_will_Christmas_and_New_Year
Line 529:
print "$_->[0] ", qw( Sunday Monday Tuesday Wednesday Thursday Fridat Saturday )
[(localtime timelocal(0, 0, 12, @{$_}[1..3]))[6]], "\n";
}</langsyntaxhighlight>
{{out}}
<pre>
Line 537:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 546:
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #7060A8;">papply</span><span style="color: #0000FF;">({</span><span style="color: #000000;">1578</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1590</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1642</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1957</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2020</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2021</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2022</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2242</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2245</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">2393</span><span style="color: #0000FF;">},</span><span style="color: #000000;">nyc</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
<small>Note the builtin timedate type does not officially support dates prior to ''1752''... the fact that the first three lines agree with other entries on this page is pure luck.</small>
{{out}}
Line 563:
 
=={{header|PL/I}}==
<langsyntaxhighlight lang="pli">xmas_and_newyear: procedure options(main);
day_name: procedure(year,month,day) returns(char(9) varying);
declare days(0:6) char(9) varying;
Line 598:
(F(2),A,F(2),A,F(4),A,A);
end;
end xmas_and_newyear;</langsyntaxhighlight>
{{out}}
<pre>12/25/2021 is a Saturday
Line 604:
 
=={{header|PL/M}}==
<langsyntaxhighlight lang="pli">100H:
BDOS: PROCEDURE(F,A); DECLARE F BYTE, A ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; GO TO 0; END EXIT;
Line 662:
END;
CALL EXIT;
EOF</langsyntaxhighlight>
{{out}}
<pre>12/25/2021 IS A SATURDAY
Line 668:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">
import datetime
 
Line 681:
nextNewYearDayAsString = weekDays[nextNewYearDay]
print("Next new year is on a {}".format(nextNewYearDayAsString))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 691:
<code>dayofweek</code> is defined at [[Day of the week#Quackery]].
 
<langsyntaxhighlight Quackerylang="quackery"> [ [ table
$ "Sun" $ "Mon"
$ "Tues" $ "Wednes"
Line 703:
 
2021 christmas day echo$ cr
2022 newyear's day echo$ cr</langsyntaxhighlight>
 
{{out}}
Line 712:
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>my @d-o-w = < Sunday Monday Tuesday Wednesday Thursday Friday Saturday >;
 
.say for (flat 2020..2022, (1500 .. 2500).roll(7)).sort.map: {
"In {$_}, New Years is on a { @d-o-w[Date.new($_, 1, 1).day-of-week % 7] }, " ~
"and Christmas on a { @d-o-w[Date.new($_, 12, 25).day-of-week % 7] }."
}</langsyntaxhighlight>
{{out|Sample output}}
<pre>In 1578, New Years is on a Sunday, and Christmas on a Monday.
Line 731:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">? "working..."
weekdays = ["Mon","Tues","Wednes","Thurs","Fri","Satur","Sun"]
dow = timelist()[15]
Line 750:
 
func nameof day
return weekdays[((day + today - 1) % 7) + 1] + "day"</langsyntaxhighlight>
{{out}}
<pre>working...
Line 759:
=={{header|Ruby}}==
This uses the same years as the Raku example. The Ruby Date class does however take the calendar reform (default 1582) into account, so the days for 1578 differ from all other languages so far.
<langsyntaxhighlight lang="ruby">require 'date'
 
years = [1578, 1590, 1642, 1957, 2020, 2021, 2022, 2242, 2245, 2393]
Line 767:
puts "In #{year}, New year's day is on a #{ny}, and Christmas day on #{xmas}."
end
</syntaxhighlight>
</lang>
{{out}}
<pre>In 1578, New year's day is on a Wednesday, and Christmas day on Thursday.
Line 786:
 
The actual days for 1578 may have been different as the Gregorian calendar didn't start until 1582.
<langsyntaxhighlight lang="ecmascript">import "./date" for Date
 
var years = [1578, 1590, 1642, 1957, 2020, 2021, 2022, 2242, 2245, 2393]
Line 793:
var xmas = Date.new(year, 12, 25).weekDay
System.print("In %(year), New year's day is on a %(newYear), and Christmas day on %(xmas).")
}</langsyntaxhighlight>
 
{{out}}
Line 810:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">func WeekDay(Year, Month, Day); \Return address of day of week
int Year, Month, Day; \Works for years 1583 onward
int DayOfWeek, Names;
Line 823:
Text(0, "This New Year's Day is on a ");
Text(0, WeekDay(2022, 1, 1)); CrLf(0);
]</langsyntaxhighlight>
 
{{out}}
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.