Long year: Difference between revisions

Content added Content deleted
(Add Cowgol)
(→‎{{header|REXX}}: refurbished)
Line 2,405: Line 2,405:


=={{header|REXX}}==
=={{header|REXX}}==
<syntaxhighlight lang="rexx">/*REXX program determines if a (calendar) year is a SHORT or LONG year (52 or 53 weeks).*/
<syntaxhighlight lang="rexx">/*REXX program determines If a (calendar) year is a short or long year */
parse arg LO HI . /*obtain optional args. */
/* (52 or 53 weeks). */
Parse Arg lo hi . /* obtain optional args. */
if LO=='' | LO=="," | LO=='*' then LO= left( date('S'), 4) /*Not given? Use default.*/
current=left(date('S'),4)
if HI=='' | HI=="," then HI= LO /* " " " " */
If lo=='' | lo=="," | lo=='*' Then lo=current /*Not given? Use default.*/
if HI=='*' then HI= left( date('S'), 4) /*an asterisk current yr*/
If hi=='' | hi=="," Then hi=lo /* " " " " */
If hi=='*' Then hi=current /*an asterisk: current yr*/


do j=LO to HI /*process single yr or range of years.*/
Do yr=lo To hi /* process single yr or range of */
say ' year ' j " is a " right( word('short long', weeks(j)-51),5) " year"
Say ' year ' yr ' is a ',
right(word('short long',is_long(yr)+1),5) ' year'
end /*j*/
End
exit 0 /*stick a fork in it, we're all done. */
Exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*----------------------------------------------------------------------*/
pWeek: parse arg #; return (# + # % 4 - # % 100 + # % 400) // 7
wd_1231:
weeks: parse arg y; if pWeek(y)==4 | pWeek(y-1)==3 then return 53; return 52</syntaxhighlight>
/*************************************************************************
* returns the day of the week of 31 December year
*************************************************************************/
Parse Arg year
Return (year+year%4-year%100+year%400)//7

is_long:
Parse Arg year
Return wd_1231(year)==4 |, /* year ends in a Thursday */
wd_1231(year-1)==3 /* or previous year ends in a Wednesday */</syntaxhighlight>
{{out|output|text=&nbsp; when using the inputs of: &nbsp; &nbsp; <tt> 1990 &nbsp; 2030 </tt>}}
{{out|output|text=&nbsp; when using the inputs of: &nbsp; &nbsp; <tt> 1990 &nbsp; 2030 </tt>}}