Jump to content

Day of the week: Difference between revisions

m
Fixed lang tags.
No edit summary
m (Fixed lang tags.)
Line 7:
 
=={{header|Ada}}==
<lang ada>with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
<lang ada>
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
with Ada.Text_IO; use Ada.Text_IO;
Line 18 ⟶ 17:
end if;
end loop;
end Yuletide;</lang>
</lang>
Sample output:
<pre style="height:30ex;overflow:scroll">
Line 99 ⟶ 97:
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386}}
<lang algol68>main:(
<pre>
main:(
# 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 121 ⟶ 118:
OD;
new line(stand out)
)</lang ada>
)
</pre>
Output:
<lang algol68>December 25th is a Sunday in: 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</lang>
<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|AutoHotkey}}==
Line 181 ⟶ 175:
 
=={{header|C++}}==
<lang cpp>#include <boost/date_time/gregorian/gregorian.hpp>
<lang C++>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
 
Line 199 ⟶ 192:
std::cout << "\n" ;
return 0 ;
}</lang>
}
</lang>
This produces the following output:
<pre>
Line 300 ⟶ 292:
=={{header|D}}==
I'm sure this can be done better. If anyone wants to take the time, please improve it.
<lang d>import std.date;
import std.date;
import std.stdio;
void main() {
Line 307 ⟶ 298:
if (0 == WeekDay(parse("December 25, "~std.string.toString(year))))
writefln("Christmas comes on a sunday in %d",year);
}</lang C++>
}
</lang>
 
=={{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.
<lang forth>\ Zeller's Congruence
: zeller ( m -- days since March 1 )
9 + 12 mod 1- 26 10 */ 3 + ;
 
: weekday ( d m y -- 0..6 ) \ Monday..Sunday
over 3 < if 1- then
dup 4 /
over 100 / -
over 400 / + +
swap zeller + +
1+ 7 mod ;
 
: yuletide
." December 25 is Sunday in "
2122 2008 do
25 12 i weekday
6 = if i . then
loop cr ;
 
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>
 
=={{header|Fortran}}==
Line 438 ⟶ 428:
 
=={{header|J}}==
<lang j> load 'dates' NB. provides verb 'weekday'
SunDec25=: #~ 0&=@:weekday@:(|:@,: ,. 12 25$~#,2:)
SunDec25 2008 + i.114
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</lang>
 
=={{header|Java}}==
Line 508 ⟶ 498:
 
=={{header|M4}}==
<lang M4>divert(-1)
divert(-1)
 
define(`for',
Line 527 ⟶ 516:
 
for(`yr',2008,2121,
`ifelse(eval(julianxmas(yr)%7==6),1,`yr ')')</lang>
</lang>
 
Output:
Line 537 ⟶ 525:
 
=={{header|Mathematica}}==
<lang Mathematica>Reap[If[DateString[{#,12,25},"DayName"]=="Sunday",Sow[#]]&/@Range[2008,2121]][[2,1]]</lang>
<lang Mathematica>
Reap[If[DateString[{#,12,25},"DayName"]=="Sunday",Sow[#]]&/@Range[2008,2121]][[2,1]]
</lang>
gives back:
<lang Mathematica>{2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118}</lang>
<lang Mathematica>
{2011,2016,2022,2033,2039,2044,2050,2061,2067,2072,2078,2089,2095,2101,2107,2112,2118}
</lang>
 
=={{header|Modula-3}}==
Line 760 ⟶ 744:
}
}
?></lang>
</lang>
 
Output:
Line 817 ⟶ 800:
 
=={{header|R}}==
<lang R>years <- 2008:2121
years <- 2008:2121
xmas <- as.POSIXlt(paste(years, '/12/25', sep=""))
years[xmas$wday==0]</lang>
</lang>
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
 
Line 935 ⟶ 916:
=={{header|UNIX Shell}}==
{{works with|bash}}
<prelang bash>#! /bin/bash
 
for i in `seq 2008 2121`
Line 942 ⟶ 923:
done
 
exit 0</lang>
</pre>
 
The first lines of output (from a 32bit GNU/Linux system, date version 6.9) are
 
<lang bash>Sun Dec 25 00:00:00 CET 2011
<pre>
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'</lang>
</pre>
 
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!
Line 959 ⟶ 937:
===Different machine/OS version (64 bit)===
This is the same command run on RedHat Linux.
<prelang bash>bash-3.00$ date --version
date (coreutils) 5.2.1
Written by David MacKenzie.
Line 986 ⟶ 964:
Sun Dec 25 00:00:00 GMT 2112
Sun Dec 25 00:00:00 GMT 2118
bash-3.00$</prelang>
 
=={{header|UnixPipes}}==
Thanks to UNIX Shell implementation
<lang bash>seq 2008 2121 | xargs -IYEAR -n 1 date +%c -d 'Dec 25 YEAR' | grep Sun</lang>
 
(Output same as UNIX Shell)
 
=={{header|Vedit macro language}}==
<lang vedit>Buf_Switch(Buf_Free)
Buf_Switch(Buf_Free)
for (#3 = 2008; #3 < 2122; #3++) {
Reg_Set(10, "12/25/")
Line 1,003 ⟶ 980:
Num_Ins(#3, NOCR)
}
}</lang>
}
</lang>
 
Output:
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.