Four steps are used to determine if a year is a leap year. They can be presented in different order, but my preference for coding purposes is;
-
A year that can be evenly divided by 400 is a leap year (e.g. 2000).
-
Except as provided in step 1, a year that can be evenly divided by 100 is NOT a leap year (e.g. 1900).
-
Except as provided in step 2, a year that can be evenly divided by 4 is a leap year (e.g. 2004).
-
Every year not covered by steps 1 through 3 is NOT a leap year (e.g. 2002).
A simple and fast (1 millisecond) AppleScript that performs the above tasks is:
set testYear to 1900 --> false
set testYear to 2000 --> true
set testYear to 2002 --> false
set testYear to 2004 --> true
if (testYear mod 400 is 0) then
return true
else if (testYear mod 100 is 0) then
return false
else if (testYear mod 4 is 0) then
return true
else
return false
end if
The exact same logic is employed in this shortcut, which takes 10 milliseconds to run.
Leap Year Test Math.shortcut (22.8 KB)
Another approach is to test whether the specified year has a February 29th. The following is an example that takes 20 milliseconds.
Leap Year Test Date.shortcut (22.4 KB)
Google AI says the following can be used, but it didn’t work for me. I tried changing | to || and & to &&, but that also didn’t work.
Leap Year Test Expression.shortcut (21.9 KB)


