Day of the week: Difference between revisions

Content added Content deleted
No edit summary
Line 1,896: Line 1,896:


=={{header|Julia}}==
=={{header|Julia}}==
<lang Julia>
{{works with|Julia|0.6}}
isdefined(:Date) || using Dates


<lang julia>using Base.Dates
lo = 2008
hi = 2121
xmas = Date(lo, 12, 25):Year(1):Date(hi, 12, 25)


lo, hi = 2008, 2121
smas = recur(xmas) do y
xmas = collect(Date(lo, 12, 25):Year(1):Date(hi, 12, 25))
Dates.dayofweek(y) == Dates.Sun
filter!(xmas) do dt
dayofweek(dt) == Dates.Sunday
end
end


println("Years (from ", lo, " to ", hi, ") having Christmas on a Sunday:")
println("Years from $lo to $hi having Christmas on Sunday: ")
foreach(println, year.(xmas))</lang>

for y in smas
println(" ", Dates.year(y))
end
</lang>

This code uses the <code>Dates</code> module, which is being incorporated into Julian's standard library with the current development version (<tt>0.4</tt>). I've used <code>isdefined</code> to make this code good for the current stable version (<tt>0.3</tt>) as well as for future releases. If <code>Dates</code> is not installed on your instance of Julian try <code>Pkg.add("Dates")</code> from the <tt>REPL</tt>.


{{out}}
{{out}}
<pre>Years (from 2008 to 2121) having Christmas on a Sunday:
<pre>Years from 2008 to 2121 having Christmas on Sunday:
2011
2011
2016
2016
2022
2022
2033
2033
2039
2039
2044
2044
2050
2050
2061
2061
2067
2067
2072
2072
2078
2078
2089
2089
2095
2095
2101
2101
2107
2107
2112
2112
2118
2118</pre>
</pre>


=={{header|K}}==
=={{header|K}}==