The forum has helped me a lot over the past several years, and I thought I would give something back. Hope you find this useful.
Code: Select all
{
# Fast and accurate Leap Year calculation
:local months [:toarray "jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec"];
:local CurrentDate [system clock get date]; # current date (mar/01/1981)
:local yr [:tonum [:pick $CurrentDate 7 11]]; # current year
:local mo [:pick $CurrentDate 0 3]; # current month (jan...dec)
:local mm ([find key=$mo in=$months]+1); # month (1...12)
:local leap; # current leap year (true|false)
:local days; # No_of days in the current month
{
:if (($yr&3!=0)||(($yr&15!=0)&&((($yr/25)*25)=$yr))) do={
:set $leap false} else={:set $leap true}; :set $days 30
:if ($mm!=2) do={:set $days ($days+(($mm+($mm>>3))&1))
} else={:if (!$leap) do={:set $days ($days-2)
} else={:set $days ($days-1)}}
}
# testing
:put ( " Year: $yr Leap: $leap " )
:put ( " Month: $mo Days: $days " )
}