Long year: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 10:
{{trans|C++}}
 
<langsyntaxhighlight lang="11l">F is_long_year(year)
F p(year)
R (year + (year I/ 4) - (year I/ 100) + (year I/ 400)) % 7
Line 17:
L(year) 2000..2100
I is_long_year(year)
print(year, end' ‘ ’)</langsyntaxhighlight>
 
{{out}}
Line 25:
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">BYTE FUNC P(CARD y)
RETURN ((y+(y/4)-(y/100)+(y/400)) MOD 7)
 
Line 50:
 
LMARGIN=oldLMARGIN ;restore left margin on the screen
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Long_year.png Screenshot from Atari 8-bit computer]
Line 64:
=={{header|Ada}}==
The Ada calendar package handles dates for years 1901 through 2399. This program outputs all the long years within that range.
<langsyntaxhighlight Adalang="ada">-------------------------------------------------------------
-- Calculate long years
-- Reference: https://en.wikipedia.org/wiki/ISO_week_date#Weeks_per_year
Line 98:
end loop;
end Main;
</syntaxhighlight>
</lang>
{{output}}
<pre>
Line 114:
=={{header|ALGOL 68}}==
{{Trans|ALGOL W}}
<langsyntaxhighlight lang="algol68">BEGIN # find "long years" - years which have 53 weeks this is equivalent to #
# finding years where 1st Jan or 31st Dec are Thursdays #
# returns the day of the week of the specified date (d/m/y), Sunday = 1 #
Line 137:
IF is long year( year ) THEN print( ( " ", whole( year, 0 ) ) ) FI
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 145:
=={{header|ALGOL-M}}==
 
<langsyntaxhighlight ALGOLlang="algol">BEGIN
 
COMMENT
Line 202:
 
END
</syntaxhighlight>
</lang>
{{output}}
<pre>
Line 211:
=={{header|ALGOL W}}==
Uses the Day_of_week procedure from the Day_of_the_week task.
<langsyntaxhighlight lang="algolw">begin % find "long years" - years which have 53 weeks %
% this is equivalent to finding years where %
% 1st Jan or 31st Dec are Thursdays %
Line 236:
if isLongYear( year ) then writeon( I_W := 5, S_W := 0, year )
end for_year
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 243:
 
=={{header|APL}}==
<langsyntaxhighlight lang="apl">dec31weekday ← {7|⍵+⌊(⍵÷4)+⌊(⍵÷400)-⌊⍵÷100}
isolongyear ← {(4 = dec31weekday ⍵) ∨ 3 = dec31weekday ⍵ - 1}</langsyntaxhighlight>
 
{{Out}}
Line 255:
=={{header|AppleScript}}==
 
<langsyntaxhighlight lang="applescript">on isLongYear(y)
-- ISO8601 weeks begin on Mondays and belong to the year in which they have the most days.
-- A year which begins on a Thursday, or which begins on a Wednesday and is a leap year,
Line 272:
end repeat
 
return longYears</langsyntaxhighlight>
 
{{output}}
Line 279:
On the other hand, since the cycle repeats every 400 years, it's possible to cheat with a precalculated look-up list:
 
<langsyntaxhighlight lang="applescript">on isLongYear(y)
return (y mod 400 is in {4, 9, 15, 20, 26, 32, 37, 43, 48, 54, 60, 65, 71, 76, 82, 88, 93, 99, 105, 111, 116, 122, 128, 133, 139, 144, 150, 156, 161, 167, 172, 178, 184, 189, 195, 201, 207, 212, 218, 224, 229, 235, 240, 246, 252, 257, 263, 268, 274, 280, 285, 291, 296, 303, 308, 314, 320, 325, 331, 336, 342, 348, 353, 359, 364, 370, 376, 381, 387, 392, 398})
end isLongYear
Line 288:
end repeat
 
return longYears</langsyntaxhighlight>
 
=={{header|Arturo}}==
Line 294:
{{trans|Nim}}
 
<langsyntaxhighlight lang="rebol">longYear?: function [year][
date: to :date .format: "dd/MM/yyyy" ~"01/01/|year|"
 
Line 303:
 
print "Years with 53 weeks between 2000 and 2100:"
print select 2000..2100 => longYear?</langsyntaxhighlight>
 
{{out}}
Line 311:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">Long_year(y) {
A := Mod(y + floor(y/4) - floor(y/100) + floor(y/400), 7)
y--, B := Mod(y + floor(y/4) - floor(y/100) + floor(y/400), 7)
return A=4 || B=3
}</langsyntaxhighlight>
Examples:<langsyntaxhighlight AutoHotkeylang="autohotkey">loop, 100{
y := 1999+A_Index
res .= Long_year(y) ? Y " ": ""
}
MsgBox % "Long Years 2000-2100 : " res
return</langsyntaxhighlight>
{{out}}
<pre>Long Years 2000-2100 : 2004 2009 2015 2020 2026 2032 2037 2043 2048 2054 2060 2065 2071 2076 2082 2088 2093 2099 </pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f LONG_YEAR.AWK
BEGIN {
Line 358:
return(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 373:
==={{header|Applesoft BASIC}}===
{{trans|Commodore BASIC}}
<langsyntaxhighlight lang="gwbasic"> 10 DEF FN M7(N) = N - 7 * INT (N / 7)
20 DEF FN WD(Y) = FN M7(Y + INT (Y / 4) - INT (Y / 100) + INT (Y / 400))
30 DEF FN LY(Y) = (4 = FN WD(Y)) OR (3 = FN WD(Y - 1))
Line 381:
70 PRINT : FOR Y = S TO E
80 IF FN LY(Y) THEN PRINT S$Y;:S$ = " "
90 NEXT Y</langsyntaxhighlight>
==={{header|ASIC}}===
{{trans|Commodore BASIC}}
<langsyntaxhighlight lang="basic">
REM Long year
CLS
Line 428:
WD = WD MOD 7
RETURN
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 439:
 
==={{header|BASIC256}}===
<langsyntaxhighlight BASIC256lang="basic256">function p(y)
return (y + int(y/4) - int(y/100) + int(y/400)) mod 7
end function
Line 450:
if isLongYear(y) then print y
next y
end</langsyntaxhighlight>
{{out}}
<pre>2004
Line 473:
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> INSTALL @lib$ + "DATELIB"
 
REM The function as per specification.
Line 492:
NEXT
PRINT
ENDPROC</langsyntaxhighlight>
{{out}}
<pre>
Line 501:
 
==={{header|Commodore BASIC}}===
<langsyntaxhighlight lang="basic">100 REM M7(N) = N MOD 7
110 DEF FNM7(N) = N - 7*INT(N / 7)
120 :
Line 518:
250 : IF FNLY(Y) THEN PRINT Y,
260 NEXT Y
270 PRINT</langsyntaxhighlight>
 
{{Out}}
Line 533:
 
==={{Header|FreeBASIC}}===
<langsyntaxhighlight lang="freebasic">function p(y as unsigned integer) as unsigned integer
return ( y + int(y/4) - int(y/100) + int(y/400) ) mod 7
end function
Line 545:
print islongyear(1998)
print islongyear(2020)
print islongyear(2021)</langsyntaxhighlight>
{{out}}
<pre>
Line 554:
 
==={{header|GW-BASIC}}===
<langsyntaxhighlight lang="gwbasic">10 INPUT "Enter a year: ", Y
20 X = Y
30 GOSUB 100
Line 565:
100 P = X + INT(X/4) - INT(X/100) + INT(X/400)
110 P = P MOD 7
120 RETURN</langsyntaxhighlight>
 
==={{header|IS-BASIC}}===
<langsyntaxhighlight ISlang="is-BASICbasic">100 PROGRAM "Longyear.bas"
110 DEF RD(Y)=Y*365+INT(Y/4)-INT(Y/100)+INT(Y/400)
120 DEF LONGYEAR(Y)=(4=MOD(RD(Y),7)) OR(4=MOD((RD(Y-1)+1),7))
Line 576:
160 IF LONGYEAR(Y) THEN PRINT Y,
170 NEXT
180 PRINT</langsyntaxhighlight>
 
==={{header|Nascom BASIC}}===
{{trans|Commodore BASIC}}
{{works with|Nascom ROM BASIC|4.7}}
<langsyntaxhighlight lang="basic">
10 REM Long year
20 REM FNM7(N)=MOD(N,7)
Line 602:
190 PRINT
200 END
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 614:
==={{header|PureBasic}}===
{{trans|BASIC256}}
<langsyntaxhighlight PureBasiclang="purebasic">Procedure.b p(y)
ProcedureReturn (y + Int(y/4) - Int(y/100) + Int(y/400)) % 7
EndProcedure
Line 631:
Print(""): Input()
CloseConsole()
EndIf</langsyntaxhighlight>
{{out}}
<pre>
Line 643:
{{Works with|VB-DOS|1.0}}
Translated from Delphi
<syntaxhighlight lang="vb">
<lang vb>
DEFINT A-Z
 
Line 675:
p% = (Yr + INT(Yr / 4) - INT(Yr / 100) + INT(Yr / 400)) MOD 7
END FUNCTION
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 689:
 
==={{header|S-Basic}}===
<syntaxhighlight lang="basic">
<lang BASIC>
$lines
 
Line 738:
next year
 
end</langsyntaxhighlight>
{{output}}
<pre>
Line 747:
 
==={{header|Tiny BASIC}}===
<langsyntaxhighlight lang="tiny basic"> PRINT "What year would you like?"
INPUT Y
LET X = Y
Line 762:
LET P = P - 7
GOTO 110
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 776:
==={{header|True BASIC}}===
{{trans|BASIC256}}
<langsyntaxhighlight lang="qbasic">FUNCTION p(y) = REMAINDER((y + INT(y/4) - INT(y/100) + INT(y/400)), 7)
 
FUNCTION isLongYear(y)
Line 791:
IF isLongYear(y) > 0 THEN PRINT y
NEXT y
END</langsyntaxhighlight>
{{out}}
<pre>
Line 799:
==={{header|Yabasic}}===
{{trans|BASIC256}}
<langsyntaxhighlight lang="yabasic">sub p(y)
return mod((y + int(y/4) - int(y/100) + int(y/400)), 7)
end sub
Line 810:
if isLongYear(y) then print y : fi
next y
end</langsyntaxhighlight>
{{out}}
<pre>
Line 817:
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
let p(y) = (y + y/4 - y/100 + y/400) rem 7
Line 824:
let start() be
for y = 2000 to 2100
if longyear(y) do writef("%N*N", y)</langsyntaxhighlight>
{{out}}
<pre>2004
Line 846:
 
=={{header|C sharp}}==
<langsyntaxhighlight lang="csharp">using static System.Console;
using System.Collections.Generic;
using System.Linq;
Line 863:
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 870:
 
=={{header|C}}==
<langsyntaxhighlight lang="cpp">#include <stdio.h>
#include <math.h>
 
Line 897:
printf("\n");
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 908:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">// Reference:
// https://en.wikipedia.org/wiki/ISO_week_date#Weeks_per_year
 
Line 937:
std::cout << '\n';
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 951:
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="clojure">(defn long-year? [year]
(-> (java.time.LocalDate/of year 12 28)
(.get (.weekOfYear (java.time.temporal.WeekFields/ISO)))
(= 53)))
 
(filter long-year? (range 2000 2100))</langsyntaxhighlight>
{{out}}
<pre>
Line 963:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">% We can't hide one procedure inside another, but
% we can hide the helper `p' in a cluster
 
Line 986:
end
end
end start_up</langsyntaxhighlight>
{{out}}
<pre>2004
Line 1,009:
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(defun december-31-weekday (year)
(mod (+ year (floor year 4) (- (floor year 100)) (floor year 400)) 7))
 
Line 1,016:
 
(format t "Long years between 1800 and 2100:~&~a~%"
(loop for y from 1800 to 2100 if (iso-long-year-p y) collect y))</langsyntaxhighlight>
 
{{Out}}
Line 1,028:
{{trans|Tcl}}
{{works with|GNU dc|1.3.95}}
<langsyntaxhighlight lang="dc">[0q]s0
[1q]s1
[1r- r 1r- * 1r-]sO # O = logical OR
Line 1,082:
[Long years between 1800 and 2100:]P AP
1800 2100 lDx
AP</langsyntaxhighlight>
 
{{out}}
Line 1,098:
Note: The Library '''System.DateUtils''' implement a '''WeeksInYear''',but not working, return 52 always.
{{Trans|C++}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Long_year;
 
Line 1,141:
Readln;
end.
</syntaxhighlight>
</lang>
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">defmodule ISO do
def long_year?(y) do
{:ok, jan1} = Date.new(y,1,1)
Line 1,152:
end
 
IO.inspect(Enum.filter(1990..2050, &ISO.long_year?/1))</langsyntaxhighlight>
 
{{Out}}
Line 1,159:
=={{header|Factor}}==
{{works with|Factor|0.99 2019-10-06}}
<langsyntaxhighlight lang="factor">USING: calendar formatting io kernel math.ranges sequences ;
 
: long-year? ( n -- ? ) 12 28 <date> week-number 53 = ;
 
"Year Long?\n-----------" print 1990 2021 [a,b]
[ dup long-year? "yes" "no" ? "%d %s\n" printf ] each</langsyntaxhighlight>
{{out}}
<pre style="height:45ex">
Line 1,204:
 
=={{header|Forth}}==
<langsyntaxhighlight lang="forth">: dec31wd ( year -- weekday ) dup dup 4 / swap dup 100 / swap 400 / swap - + + 7 mod ;
: long? ( year -- flag ) dup dec31wd 4 = if drop 1 else 1 - dec31wd 3 = if 1 else 0 then then ;
: demo ( startyear endyear -- ) cr swap do i long? if i . then loop cr ;</langsyntaxhighlight>
 
{{Out}}
Line 1,214:
 
=={{header|Fortran}}==
<langsyntaxhighlight lang="fortran">
program longyear
use iso_fortran_env, only: output_unit, input_unit
Line 1,252:
end function is_long_year
end program longyear
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,269:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,290:
fmt.Println(longYears)
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,305:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.Time.Calendar (fromGregorian)
import Data.Time.Calendar.WeekDate (toWeekDate)
 
Line 1,314:
 
main :: IO ()
main = mapM_ print $ filter longYear [2000 .. 2100]</langsyntaxhighlight>
{{Out}}
<pre>2004
Line 1,337:
=={{header|J}}==
{{trans|C}}
<langsyntaxhighlight lang="j"> p =: 1 4 _100 400&(7 | [: <. +/ @: %~)"1 0
ily =: (4=p) +. 3=p@:<:
ply =: (#~ ily)@:([ + 1+i.@:-~)</langsyntaxhighlight>
{{out}}
<pre>
Line 1,347:
=={{header|Java}}==
 
<langsyntaxhighlight lang="java">
import java.time.LocalDate;
import java.time.temporal.WeekFields;
Line 1,367:
 
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,376:
=={{header|JavaScript}}==
{{trans|TypeScript}}
<langsyntaxhighlight lang="javascript">const isLongYear = (year) => {
const jan1 = new Date(year, 0, 1);
const dec31 = new Date(year, 11, 31);
Line 1,386:
console.log(y)
}
}</langsyntaxhighlight>
 
{{Out}}
Line 1,404:
 
===Using Zeller's congruence===
<syntaxhighlight lang="jq">
<lang jq>
# Use Zeller's Congruence to determine the day of the week, given
# year, month and day as integers in the conventional way.
Line 1,429:
 
"Long years from 1900 to 2100 inclusive:",
([range(1900;2101) | select(has53weeks)] | nwise(10) | join(", "))</langsyntaxhighlight>
{{out}}
<pre>
Line 1,440:
 
===Using mktime and gmtime===
<langsyntaxhighlight lang="jq"># Use jq's mktime and gmtime to produce the day of week,
# with 0 for Sunday, 1 for Monday, etc
# $year $month $day are conventional
Line 1,455:
 
"Long years from 1900 to 2100 inclusive:",
([range(1900;2101) | select(has53weeks)] | nwise(10) | join(", "))</langsyntaxhighlight>
{{out}}
As above.
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Dates
 
has53weeks(year) = week(Date(year, 12, 28)) == 53
Line 1,468:
println(year, " ", has53weeks(year) ? "Yes" : "No")
end
</langsyntaxhighlight>{{out}}
<pre>
Year 53 weeks?
Line 1,507:
 
=={{header|Kotlin}}==
<syntaxhighlight lang="kotlin">
<lang Kotlin>
fun main() {
val has53Weeks = { year: Int -> LocalDate.of(year, 12, 28).get(WeekFields.ISO.weekOfYear()) == 53 }
Line 1,514:
.forEach { year -> print("$year ")}
}
</syntaxhighlight>
</lang>
{{out}}
<pre style="height35ex">
Line 1,525:
=={{header|Logo}}==
{{works with|UCB Logo}}
<langsyntaxhighlight lang="logo">to div :x :y
output int quotient :x :y
end
Line 1,537:
end
 
for [y 1995 2045 1] [if iso_long_year? :y [print :y]]</langsyntaxhighlight>
 
{{Out}}
Line 1,550:
2043</pre>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">firstyear = 2000;
lastyear = 2099;
years = Range[firstyear, lastyear];
Line 1,558:
If[firstday[[n]] == Thursday || lastday[[n]] == Thursday,
Style[years[[n]] " long year \n", Bold, Red] ,
years[[n]] " short \n"], "error \n"], {n, Length[years]}]</langsyntaxhighlight>
{{out}}
<pre style="height:35ex">{2000 short
Line 1,663:
 
=={{header|Modula-2}}==
<langsyntaxhighlight lang="modula2">MODULE LongYear;
FROM InOut IMPORT WriteCard, WriteLn;
 
Line 1,684:
END;
END;
END LongYear.</langsyntaxhighlight>
{{out}}
<pre>2004
Line 1,706:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import times
 
proc has53weeks(year: Positive): bool =
Line 1,716:
for year in 2000..2100:
if year.has53weeks:
echo year</langsyntaxhighlight>
 
{{out}}
Line 1,740:
 
=={{header|МК-61/52}}==
<langsyntaxhighlight lang="mk-61">П0 ИП0 4 / [x] + ИП0 1 ВП 2
/ [x] - ИП0 4 ВП 2 / [x] +
^ ^ 7 / [x] 7 * - П1 4
- x#0 40 ИП1 3 - x#0 40 0 С/П
1 С/П</langsyntaxhighlight>
{{out}}
<pre>
Line 1,750:
</pre>
=={{header|Pascal}}==
<langsyntaxhighlight lang="pascal">program long_year(input);
var
y: integer;
Line 1,784:
if long_year(y) then
writeln(y)
end.</langsyntaxhighlight>
{{Out}}
<pre>1993
Line 1,799:
==={{header|Free Pascal}}===
Using DateUtils and WeeksInYear to not reinvent this.
<langsyntaxhighlight lang="pascal">
program Long_year;
 
Line 1,832:
Readln;
{$ENDIF}
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 1,845:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use DateTime;
Line 1,854:
}
print "\n";
}</langsyntaxhighlight>
{{out}}
<pre>1903 1908 1914 1920 1925 1931 1936 1942 1948 1953 1959 1964 1970 1976 1981 1987 1992 1998
Line 1,861:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">week_number</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">y</span><span style="color: #0000FF;">,</span><span style="color: #000000;">m</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">)</span>
Line 1,880:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Long years in the %d%s century:%v\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">c</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">ord</span><span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">),</span><span style="color: #000000;">long_years</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,889:
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php">function isLongYear($year) {
return (53 == strftime('%V', gmmktime(0,0,0,12,28,$year)));
}
Line 1,897:
printf("%s\n", $y);
}
}</langsyntaxhighlight>
{{Out}}
<pre>1998
Line 1,910:
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell">Function Is-Long-Year {
param([Int]$year)
53 -eq (Get-Date -Year $year -Month 12 -Day 28 -UFormat %V)
Line 1,919:
Write-Host $y
}
}</langsyntaxhighlight>
 
{{Out}}
Line 1,935:
{{trans|C++}}
{{works with|SWI Prolog}}
<langsyntaxhighlight lang="prolog">% See https://en.wikipedia.org/wiki/ISO_week_date#Weeks_per_year
 
p(Year, P):-
Line 1,972:
 
main:-
print_long_years(1800, 2100).</langsyntaxhighlight>
 
{{out}}
Line 1,987:
=={{header|Python}}==
{{Works with|Python|3.7}}
<langsyntaxhighlight lang="python">'''Long Year ?'''
 
from datetime import date
Line 2,011:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>2004
Line 2,036:
<code>dayofweek</code> is defined at [[Day of the week#Quackery]]
 
<langsyntaxhighlight Quackerylang="quackery"> [ dup dip
[ 1 1 rot dayofweek 4 = ]
31 12 rot dayofweek 4 = or ] is longyear ( n --> b )
Line 2,044:
100 times
[ 2000 i^ + longyear if
[ 2000 i^ + echo sp ] ]</langsyntaxhighlight>
 
{{out}}
Line 2,057:
{{works with|Rakudo|2019.11}}
December 28 is always in the last week of the year. (By ISO8601)
<syntaxhighlight lang="raku" perl6line>sub is-long ($year) { Date.new("$year-12-28").week[1] == 53 }
 
# Testing
say "Long years in the 20th century:\n", (1900..^2000).grep: &is-long;
say "\nLong years in the 21st century:\n", (2000..^2100).grep: &is-long;
say "\nLong years in the 22nd century:\n", (2100..^2200).grep: &is-long;</langsyntaxhighlight>
{{out}}
<pre>Long years in the 20th century:
Line 2,074:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX program determines if a (calendar) year is a SHORT or LONG year (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.*/
Line 2,086:
/*──────────────────────────────────────────────────────────────────────────────────────*/
pWeek: parse arg #; return (# + # % 4 - # % 100 + # % 400) // 7
weeks: parse arg y; if pWeek(y)==4 | pWeek(y-1)==3 then return 53; return 52</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the inputs of: &nbsp; &nbsp; <tt> 1990 &nbsp; 2030 </tt>}}
 
Line 2,135:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
see "long years 2000-2099: "
for year = 2000 to 2100
Line 2,145:
ok
next
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,152:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">
require 'date'
 
Line 2,160:
 
(2020..2030).each{|year| puts "#{year} is long? #{ long_year?(year) }." }
</syntaxhighlight>
</lang>
{{out}}
<pre>2020 is long? true.
Line 2,177:
=={{header|Rust}}==
 
<langsyntaxhighlight Rustlang="rust">extern crate time; // 0.2.16
 
use time::Date;
Line 2,190:
Date::try_from_ymd(year, 12, 28).map_or(false, |date| date.week() == 53)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,216:
{{Out}}Best seen running in your browser by [https://scastie.scala-lang.org/LDKMJ29SSrehyVbCmiMH1Q Scastie (remote JVM)].
 
<langsyntaxhighlight Scalalang="scala">import java.time.temporal.TemporalAdjusters.firstInMonth
import java.time.temporal.{ChronoField, IsoFields}
import java.time.{DayOfWeek, LocalDate, Month}
Line 2,262:
results.zipWithIndex.foreach(solution => println(s"Solution ${solution._2}: ${solution._1.mkString(" ")}"))
 
}</langsyntaxhighlight>
 
=={{header|Scheme}}==
Line 2,271:
The demo code uses <tt>iota</tt> as defined in SRFI-1, so won't work in Schemes lacking that function. Racket requires the addition of <tt>(require srfi/1)</tt>.
 
<langsyntaxhighlight lang="scheme">(define (dec31wd year)
(remainder (apply + (map (lambda (d) (quotient year d)) '(1 4 -100 400))) 7))
 
Line 2,277:
 
(display "Long years between 1800 and 2100:") (newline)
(display (filter long? (iota 300 1800)))</langsyntaxhighlight>
 
{{Out}}
Line 2,284:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">func is_long_year(year) {
Date.parse("#{year}-12-28", "%Y-%m-%d").week == 53
}
Line 2,290:
say ( "Long years in the 20th century:\n", (1900..^2000).grep(is_long_year))
say ("\nLong years in the 21st century:\n", (2000..^2100).grep(is_long_year))
say ("\nLong years in the 22nd century:\n", (2100..^2200).grep(is_long_year))</langsyntaxhighlight>
{{out}}
<pre>
Line 2,304:
 
=={{header|Snobol}}==
<langsyntaxhighlight lang="snobol"> DEFINE('DEC31WD(Year)') :(END_DEC31WD)
DEC31WD DEC31WD = REMDR(Year + (Year / 4) - (Year / 100) + (Year / 400), 7) :(RETURN)
END_DEC31WD
Line 2,322:
 
ISODEMO(1995, 2045)
END</langsyntaxhighlight>
 
{{Out}}
Line 2,337:
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">func isLongYear(_ year: Int) -> Bool {
let year1 = year - 1
let p = (year + (year / 4) - (year / 100) + (year / 400)) % 7
Line 2,347:
for range in [1900...1999, 2000...2099, 2100...2199] {
print("\(range): \(range.filter(isLongYear))")
}</langsyntaxhighlight>
 
{{out}}
Line 2,358:
 
{{trans|C++}}
<syntaxhighlight lang="tcl">
<lang Tcl>
## Reference: https://en.wikipedia.org/wiki/ISO_week_date#Weeks_per_year
 
Line 2,383:
puts "Long years between 1800 and 2100:"
print_long_years 1800 2100
puts ""</langsyntaxhighlight>
{{out}}
<pre>
Line 2,399:
Contents of main module:
 
<langsyntaxhighlight lang="terraform">module "iso-long-years" {
source = "./iso-long-years"
start_year = 1995
Line 2,407:
output "long-years" {
value = module.iso-long-years.long-years
}</langsyntaxhighlight>
 
Contents of <tt>iso-long-years</tt> module:
 
<langsyntaxhighlight lang="terraform">variable start_year {
type = number
}
Line 2,432:
value = compact([for y in [for n in local.year_list: tostring(n)]:
module.iso-long-year[y].isLong ? y : ""])
}</langsyntaxhighlight>
 
Contents of <tt>iso-long-year</tt> module:
 
<langsyntaxhighlight lang="terraform">variable year {
type = string
default = ""
Line 2,451:
output isLong {
value = (local.dec31 % 7 == 4 || local.jan1 % 7 == 4)
}</langsyntaxhighlight>
 
{{Out}}
Line 2,471:
]</pre>
=={{header|TypeScript}}==
<langsyntaxhighlight lang="typescript">const isLongYear = (year: number): boolean => {
const jan1: Date = new Date(year, 0, 1);
const dec31: Date = new Date(year, 11, 31);
Line 2,481:
console.log(y)
}
}</langsyntaxhighlight>
 
{{Out}}
Line 2,497:
 
=== Thursdays check using cal(1) and grep(1) ===
<langsyntaxhighlight lang="sh">long_year() {
cal 1 $1 | grep -q ' 3 *$' && return 0
cal 12 $1 | grep -q ' 26 *$'
}</langsyntaxhighlight>
 
=== Straightforward check using GNU date(1) ===
December 28th is always in the last week of the year, so just check whether or not that's week 53:
 
<langsyntaxhighlight lang="sh">long_year() {
expr $(date -d "$1-12-28" +%V) = 53 >/dev/null
}</langsyntaxhighlight>
 
=== Direct computation with built-in arithmetic in newer shells ===
Line 2,513:
{{works with|Korn Shell}}
{{works with|Zsh}}
<langsyntaxhighlight lang="sh">dec31wd() {
# return weekday (time_t tm_wday, 0=Sunday) of December 31st of the given year
typeset -i y=$1
Line 2,524:
typeset -i y=$1
(( 4 == $(dec31wd $y) || 3 == $(dec31wd $(( y - 1 ))) ))
}</langsyntaxhighlight>
 
Demo code for any of the above:
 
<langsyntaxhighlight lang="sh">for y in $(seq 1995 2045); do
if long_year $y; then
echo $y
fi
done | column
</syntaxhighlight>
</lang>
 
{{Out}}
Line 2,544:
{{works with|VBA|6.5}}
{{works with|VBA|7.1}}
<langsyntaxhighlight lang="vb">Option Explicit
 
Function IsLongYear(ByVal Year As Integer) As Boolean
Line 2,566:
Next l
End Sub
</syntaxhighlight>
</lang>
 
==={{header|Visual Basic for DOS}}===
Translated from Delohi
<langsyntaxhighlight lang="vb">OPTION EXPLICIT
 
DECLARE FUNCTION p (Yr AS INTEGER) AS INTEGER
Line 2,601:
LongYear = (p(Yr) = 4) OR (p(Yr - 1) = 3)
END FUNCTION
</syntaxhighlight>
</lang>
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|Wren-date}}
<langsyntaxhighlight lang="ecmascript">import "/date" for Date
 
var centuries = ["20th", "21st", "22nd"]
Line 2,620:
}
System.print(longYears)
}</langsyntaxhighlight>
 
{{out}}
Line 2,637:
{{trans|Commodore BASIC}}
{{works with|EXPL-32}}
<langsyntaxhighlight lang="xpl0">
\Long year
code Rem=2, CrLf=9, IntIn=10, IntOut=11, Text=12, Clear=40;
Line 2,662:
CrLf(0);
end
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,673:
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">fcn isLongYear(y){ Time.Date.weeksInYear(y)==53 }
foreach nm,y in (T(T("20th",1900), T("21st",2000), T("22nd",2100))){
println("\nLong years in the %s century:\n%s".fmt(nm,
[y..y+99].filter(isLongYear).concat(" ")));
}</langsyntaxhighlight>
{{out}}
<pre>
10,333

edits