Dealing with leap years

I am trying to find a package that deals with leap years. For example a function that returns the number of days that fall on 29 February for some period. (There are some complications: years such that mod(year,100)==0 are normally not leap years, but years such mod(year,400)==0, as year 2000, are leap years)

I would try using Dates (from the standard library docs here: Dates · The Julia Language)

For your example:

using Dates

dr = Date(2000,1,17):Day(1):Date(2020,1,17)
count(x -> monthday(x) == (2, 29), dr)

Also there’s:

isleapyear(2020)

This should address all of the complications of leap years (2020 is a leap year, 2100 is not, 2000 is)

6 Likes