Day of the week: Difference between revisions
Content deleted Content added
adding GAP |
|||
Line 1,138: | Line 1,138: | ||
2112 |
2112 |
||
2118</pre> |
2118</pre> |
||
===version 1=== |
|||
The extended DATE parameters (arguments 2 and 3) are only supported by the |
|||
<br>newer REXX interpreters. |
|||
<lang rexx> |
|||
/*REXX program displays which years December 25th falls on a Sunday. */ |
|||
parse arg start finish . /*get the start and finish years.*/ |
|||
if start=='' then start=2008 /*None specified? Assume default*/ |
|||
if finish=='' then finish=2121 /*None specified? Assume default*/ |
|||
do y=start to finish /*process 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 |
|||
</lang> |
|||
Output (using the defaults): |
|||
<pre style="height:30ex;overflow:scroll"> |
|||
December 25th, 2011 falls on a Sunday. |
|||
December 25th, 2016 falls on a Sunday. |
|||
December 25th, 2022 falls on a Sunday. |
|||
December 25th, 2033 falls on a Sunday. |
|||
December 25th, 2039 falls on a Sunday. |
|||
December 25th, 2044 falls on a Sunday. |
|||
December 25th, 2050 falls on a Sunday. |
|||
December 25th, 2061 falls on a Sunday. |
|||
December 25th, 2067 falls on a Sunday. |
|||
December 25th, 2072 falls on a Sunday. |
|||
December 25th, 2078 falls on a Sunday. |
|||
December 25th, 2089 falls on a Sunday. |
|||
December 25th, 2095 falls on a Sunday. |
|||
December 25th, 2101 falls on a Sunday. |
|||
December 25th, 2107 falls on a Sunday. |
|||
December 25th, 2112 falls on a Sunday. |
|||
December 25th, 2118 falls on a Sunday. |
|||
</pre> |
|||
===version 2=== |
|||
This 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*// |
|||
parse arg start finish . /*get the start and finish years.*/ |
|||
if start=='' then start=2008 /*None specified? Assume default*/ |
|||
if finish=='' then finish=2121 /*None specified? Assume default*/ |
|||
do y=start to finish /*process the years specified. */ |
|||
if dow(12,25,y)==1 then say 'December 25th,' y "falls on a Sunday." |
|||
end |
|||
exit |
|||
/*─────────────────────────────────────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:30ex;overflow:scroll"> |
|||
December 25th, 2011 falls on a Sunday. |
|||
December 25th, 2016 falls on a Sunday. |
|||
December 25th, 2022 falls on a Sunday. |
|||
December 25th, 2033 falls on a Sunday. |
|||
December 25th, 2039 falls on a Sunday. |
|||
December 25th, 2044 falls on a Sunday. |
|||
December 25th, 2050 falls on a Sunday. |
|||
December 25th, 2061 falls on a Sunday. |
|||
December 25th, 2067 falls on a Sunday. |
|||
December 25th, 2072 falls on a Sunday. |
|||
December 25th, 2078 falls on a Sunday. |
|||
December 25th, 2089 falls on a Sunday. |
|||
December 25th, 2095 falls on a Sunday. |
|||
December 25th, 2101 falls on a Sunday. |
|||
December 25th, 2107 falls on a Sunday. |
|||
December 25th, 2112 falls on a Sunday. |
|||
December 25th, 2118 falls on a Sunday. |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |