Function Repository Resource:

NextLeapYear

Source Notebook

Find the next leap year

Contributed by: Peter Burbery

ResourceFunction["NextLeapYear"][date]

find the next year that is a leap year.

Details

The output will have a granularity of year.

Examples

Basic Examples

Find the next leap year after today:

In[1]:=
ResourceFunction["NextLeapYear"][]
Out[1]=

Find the next year after 18 February 2002 23:45:45pm with the time zone in Huntington, West Virginia that is a leap year in the Gregorian calendar:

In[2]:=
ResourceFunction["NextLeapYear"][
 DateObject[{2002, 2, 18, 23, 45, 45}, "Instant", "Gregorian", "America/New_York"]]
Out[2]=

Find the next leap year for a random date this year:

In[3]:=
ResourceFunction["NextLeapYear"][RandomDate[]]
Out[3]=

Find the next leap year after D-Day:

In[4]:=
ResourceFunction["NextLeapYear"][
 Entity["MilitaryConflict", "NormandyLandings"]["StartDate"]]
Out[4]=

In the Julian calendar 1900 is a leap year, but in the Gregorian calendar, its not because its divisible by 100 and not by 400. Find the next leap year in the Gregorian calendar:

In[5]:=
LeapYearQ[
 DateObject[{1900, 6, 30, 12, 15, 25.634026303887367`}, "Instant", "Gregorian", -5.`], CalendarType -> "Julian"]
Out[5]=
In[6]:=
LeapYearQ[
 DateObject[{1900, 6, 30, 12, 15, 25.634026303887367`}, "Instant", "Gregorian", -5.`], CalendarType -> "Gregorian"]
Out[6]=

Without a leap year in 1900, the leap year after 1899 is 1904:

In[7]:=
ResourceFunction["NextLeapYear"][DateObject[{1899, 1, 1}, "Day"]]
Out[7]=

Publisher

Peter Burbery

Version History

  • 1.0.0 – 13 January 2023

License Information