Learntrix
Notice: CHECK FACTS BEFORE PUBLISHING — Standard Gregorian calendar specification
Published by Learntrix··4 min read

How Calendar Arithmetic & Leap Years Work

Date arithmetic must account for irregular month lengths, epoch timestamps, and the Gregorian 400-year leap year rule.

1. Gregorian Leap Year Modulo Rules

A solar year is approximately 365.2422 days. To keep civil calendars aligned with solar seasons, leap years are inserted according to three strict rules:

1. A year is a leap year if divisible by 4.

2. EXCEPT if it is divisible by 100, in which case it is NOT a leap year.

3. UNLESS it is also divisible by 400, in which case it IS a leap year.

For example: 2000 was a leap year (divisible by 400), but 1900 and 2100 are not leap years.