Doomsday rule: Difference between revisions
→{{header|UNIX Shell}}: style tweak
(add bash entry) |
(→{{header|UNIX Shell}}: style tweak) |
||
Line 1,579:
<syntaxhighlight lang=bash>#!/usr/bin/env bash
conway()
local -ra dow=({Sun,Mon,Tues,Wednes,Thurs,Fri,Satur}day)▼
then
local -ra doomsday=(377426415375 417426415375)▼
▲ local -ra dow=({Sun,Mon,Tues,Wednes,Thurs,Fri,Satur}day)
local -i year month day isLeap c s t a b▼
▲ local -ra doomsday=(377426415375 417426415375)
▲ [[ "$1" =~ ([0-9]{4})-([0-9]{2})-([0-9]{2}) ]] || return 1
▲ local -i year month day isLeap c s t a b
year=${BASH_REMATCH[1]}▼
((▼
isLeap=(year % 4 == 0) && ( (year % 100) || (year % 400 == 0) ),▼
c=year/100,▼
s=(year%100)/12,▼
t=(year % 100) % 12,▼
a=(5*(c%4)+2) % 7,▼
b=(s + t + (t / 4) + a ) % 7▼
))▼
echo ${dow[(b + day - ${doomsday[is-leap]:month-1:1} + 7) % 7]}▼
else return 1
fi
▲ ((
▲ isLeap=(year % 4 == 0) && ( (year % 100) || (year % 400 == 0) ),
▲ c=year/100,
▲ s=(year%100)/12,
▲ t=(year % 100) % 12,
▲ a=(5*(c%4)+2) % 7,
▲ b=(s + t + (t / 4) + a ) % 7
▲ ))
▲ echo ${dow[(b + day - ${doomsday[is-leap]:month-1:1} + 7) % 7]}
for date in 1800-01-06 1875-03-29 1915-12-07 1970-12-23 2043-05-14 2077-02-12 2101-04-02
do conway "$date"
|