# Leap algorithm

427pages on
this wiki

Whether a calendar uses a leap day, leap week or leap month or a combination thereof, there needs to be some arithmetic or observational leap rule to determine when to insert a leap item. When it’s arithmetic this rule can be stated as a leap algorithm. Most algorithms follow a distinct pattern.

## Design Edit

Pretty much every calendar developed by and for humans is the resulting compromise of the attempt to align several astronomic periodicals that are not integer multiples of each other. As a matter of fact, the exact length of each cycle changes over time and it depends on where one was to select the cue and fix points of observation.

Day (D)
The revolution of the Earth around its own axis. Terrestrial cycle.
Week (W)
An arbitrary number deemed useful for short-term repetitive tasks and schedules. Usually similar to phase. Cultural cycle.
Phase (P)
A period between the 4 extremes of a lunation. Quarter-lunar cycle.
Month (M)
Usually similar to lunation.
Lunation (L)
The revolution of the Moon around the Earth. Lunar cycle.
Season (S)
A period between the 4 extremes of a year. Quarter-solar cycle.
Year (Y)
The revolution of the Earth around the Sun. Solar cycle.

Leap cycle (C)
For each leap item that is determined by an algorithmic rule, there exists a constant number of applications after which it repeats.
Era (E)
The least common multiple of leap cycles of a calendar system. Often erroneously thought to be the same as one of the leap cycles.

Many calendars only implicitly define leap rules for some items. The Gregorian reform, for instance, effectively defined a leap cycle of 400 years with 97 leap days in it. The resulting number of days, 146’097, is divisible by 7, hence the leap cycle also contains a whole number of weeks. There was no rule when to count a 53rd week in a year, however, until a predecessor of ISO 8601 defined one. Mostly unknown, the Catholic church maintains a synchronized lunar calendar for its Easter computus which has a leap cycle of 10’000 years. Since the latter is a multiple of 400, each Gregorian Era runs for 10’000 years or 3’652’425 days or 123’683 lunations.

## Patterns Edit

Some (old) calendars have no leap rule at all and thereby allow the seasons to drift through the year over time.

### Every nth year Edit

The Julian calendar, like some others, has a very simple rule for determining leap days: they occur in every fourth year, which – for the sake of simplicity – is every year whose ordinal number is evenly divisible by 4. The leap cycle therefore is 4 years and the mean year 365.25 days long (+08:00:00).

### Every nth year with skips Edit

The Gregorian reform modifies the Julian rule by omitting every 25th leap day, i.e. in century years, but the 100th Julian leap day is kept, i.e. every 4th omission is not executed (in years divisible by 400). With 97 leap day per 4 centuries, the mean year is exactly 365.2425 days (+05:49:12). So sometimes there are 8 years between leap days.

Rules like this increase the seasonal “jitter”, i.e. the maximum positive and negative offset of calendrical season dates from their actual astronomic observance.

### Every nth year with exceptions Edit

In the once proposed Dee calendar, the Julian rule of every fourth would have an exception every eighth time when the distance between leap years was five years instead. Its leap cycle is therefore 33 years long, 7 × 4 + 1 × 5, with a mean year of 365.2̅4̅ days (+05:49:05.4̅5̅).

Rules like that offer a smoother approximation of astronomic phenomena, but are harder to do in one’s head, because one needs to know when the current cycle started. The rule can be restated in terms of the absolute ordinal year number and a division operation.

### Every nth and every mth year Edit

This is rare, for leap days at least.

The Dee cycle of 33 years could, for the sake of an example, also have a leap day every 6th and one every 11th year: 5 + 3 = 8, but the resulting pattern (6/11/12/18/22/24/30/33) would sometimes make subsequent years to have leap days. The leap cycle must be shorter than n × m and the count must be reset thereafter.

### Remainder of a certain division Edit

For a smoothly spread, symmetric alignment of leap items per cycle which are either n or n+1 years apart there is a generic rule:

It is a leap year only if the remainder of the sum of the rounded half cycle length in years int(c/2) and the product of number of leap items per cycle i and ordinal year number o divided by the cycle length in years c is less than the number of leap items per cycle i:
$(\lfloor\tfrac{c}{2}\rfloor + i \times o) \mod c < i$
$n = ⌊c ÷ i⌋$

Usually there will be a small number of sub-cycles. This algorithm is employed by the Symmetry454 Calendar, among others.

If applied to the Gregorian cycle of 400 years with 97 leap days, it will have 11 Dee-like 33-year sub-cycles and one 37-year sub-cycle in the middle. The following years would have a leap day:

• 003, 007, 011, 015, 019, 023, 027, 031,
• 036, 040, 044, 048, 052, 056, 060, 064,
• 069, 073, 077, 081, 085, 089, 093, 097,
• 102, 106, 110, 114, 118, 122, 126, 130,
• 135, 139, 143, 147, 151, 155, 159, 163,
• 168, 172, 176, 180, 184, 188, 192, 196, 200,
• 205, 209, 213, 217, 221, 225, 229, 233,
• 238, 242, 246, 250, 254, 258, 262, 266,
• 271, 275, 279, 283, 287, 291, 295, 299,
• 304, 308, 312, 316, 320, 324, 328, 332,
• 337, 341, 345, 349, 353, 357, 361, 365,
• 370, 374, 378, 382, 386, 390, 394, 398

## Conversion Edit

It is possible, most of the time, to derive dependent leap cycles for hypothetic leap items from the nominal rule.

### Leap day to leap week Edit

See ISO week date to realize that this can be done but is not pretty for the pattern “every nth year with skips”. The implied rule of majority (“Thursday rule”) is simple enough, but the occurrence of leap weeks throughout the leap cycle looks highly irregular. There is no simple rule or formula to determine the existence of a 53rd week from the ordinal year number, as there is no simple algorithm to determine the dow of the first day of the year.

### Leap week to leap day Edit

Karl Palmen:

A leap day calendar can be constructed for any leap week calendar, where the leap weeks occur in intervals of 4, 5, 6 or 7 years. This excludes, divide-by-five with exceptionsskips, which has 10-year intervals, and divide-by-six with additional leap weeks, which has intervals of 3 years or less.

1. Make every year of the leap day calendar that corresponds to a year with a leap week start 3 days later than the year with the leap week (on day 3 of the week).
2. For each interval starting with such a year and running to the next such year, allocate leap years as follows:
•  7-year interval - 0 leap years
•  6-year interval - 1 leap year
•  5-year interval - 2 leap years
•  4-year interval - 3 leap years
It does matter, which of these years are leap years and so we have some flexibility in choosing the leap years to occur in an often regular manner.

This does not exhaust all possibilities, for example one could have a year corresponding to a year with a leap week start 2 days later, if that year is a leap year. This allows some intervals of 3 years, which would have 4 consecutive leap years, including both the years with leap weeks 3 years apart. This does not allow two consecutive intervals of 3 years and hence does not allow divide-by-six.