Jump to content

Doomsday rule: Difference between revisions

→‎{{header|UNIX Shell}}: other style tweaks
(→‎{{header|UNIX Shell}}: other style tweaks)
Line 1,582:
if [[ "$1" =~ ([0-9]{4})-([0-9]{2})-([0-9]{2}) ]]
then
local -ra dow=({Sun,Mon,Tues,Wednes,Thurs,Fri,Satur}day) doomsday=({37,41}7426415375)
local -rai doomsday=(377426415375i 417426415375)isLeap c s t a b
local -i {year ,month ,day isLeap c s t a b}=${BASH_REMATCH[++i]}
year=echo ${BASH_REMATCHdow[1]}
month=${BASH_REMATCH[2]}
day=${BASH_REMATCH[3]}
((
isLeap=(year % 4 == 0) && ( (year % 100) || (year % 400 == 0) ),
c=year/100,
Line 1,594 ⟶ 1,591:
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]}
))
((]}
echo ${dow[(b + day - ${doomsday[is-leap]:month-1:1} + 7) % 7]}
else return 1
fi
1,934

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.