Day of the week: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: changed the version names. -- ~~~~)
Line 1,789: Line 1,789:


=={{header|REXX}}==
=={{header|REXX}}==
===version 1===
===using DATE weekday===
<lang rexx>do year = 2008 to 2121
<lang rexx>do year = 2008 to 2121
if date('w', year'1225', 's') = 'Sunday' then say year
if date('w', year'1225', 's') = 'Sunday' then say year
end</lang>
end</lang>
===version 2===
===using DATE base===
Alternative:
<lang rexx>do year = 2008 to 2121
<lang rexx>do year = 2008 to 2121
if date('b', year'1225', 's') // 7 = 6 then say year
if date('b', year'1225', 's') // 7 = 6 then say year
end</lang>
end</lang>
'''output''' from either

Output from either:
<pre>2011
<pre>2011
2016
2016
Line 1,818: Line 1,816:
2118</pre>
2118</pre>


===version 3===
===DATE iso===
The extended DATE parameters (arguments 2 and 3) are only supported by the
The extended DATE parameters (arguments 2 and 3) are only supported by the newer REXX interpreters.
<br>newer REXX interpreters.
<br><br>
<br><br>
Language note: the DATE built-in function always returns the day-of-week in English,
Language note: the DATE built-in function always returns the day-of-week in English, no matter what the native language is in effect.
<lang rexx>/*REXX program displays which years December 25th falls on a Sunday. */
<br>no matter what the native language is in effect.
<lang rexx>
/*REXX program displays which years December 25th falls on a Sunday. */

parse arg start finish . /*get the start and finish years.*/
parse arg start finish . /*get the start and finish years.*/
if start=='' then start=2008 /*None specified? Assume default*/
if start=='' then start=2008 /*None specified? Assume default*/
Line 1,838: Line 1,832:


say 'December 25th,' y "falls on a Sunday."
say 'December 25th,' y "falls on a Sunday."
end
end /*y*/</lang>
'''output''' when using the default input
</lang>
Output (using the defaults):
<pre style="height:15ex;overflow:scroll">
<pre style="height:15ex;overflow:scroll">
December 25th, 2011 falls on a Sunday.
December 25th, 2011 falls on a Sunday.
Line 1,861: Line 1,854:
</pre>
</pre>


===version 4===
===old school DOW ===
This version will work with any version of a REXX interpreter.
This DOW (day-of-week) version will work with any version of a REXX interpreter.
<lang rexx>/*REXX program (old school) displays which years 12/25 falls on a Sunday*//
<lang rexx>
/*REXX program (old school) displays which years 12/25 falls on a Sunday*//


parse arg start finish . /*get the start and finish years.*/
parse arg start finish . /*get the start and finish years.*/
Line 1,872: Line 1,864:
do y=start to finish /*process the years specified. */
do y=start to finish /*process the years specified. */
if dow(12,25,y)==1 then say 'December 25th,' y "falls on a Sunday."
if dow(12,25,y)==1 then say 'December 25th,' y "falls on a Sunday."
end
end /*y*/

exit
exit

/*─────────────────────────────────────DOW (day of week) subroutine─────*/
/*─────────────────────────────────────DOW (day of week) subroutine─────*/
dow: procedure; arg m,d,y; if m<3 then do; m=m+12; y=y-1; end
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
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*/
if w==0 then w=7; return w /*Sunday=1, Monday=2, ... Saturday=7*/</lang>
'''output''' using the default input
</lang>
Output (using the defaults):
<pre style="height:15ex;overflow:scroll">
<pre style="height:15ex;overflow:scroll">
December 25th, 2011 falls on a Sunday.
December 25th, 2011 falls on a Sunday.