|
| bool | is_leap (int year) |
| | Determine if a year is a leap year.
|
| |
| int | leap_add (int year) |
| | Adds one for a leap year otherwise zero.
|
| |
| int | leap_thru (int year) |
| | Leap years completed from year 0 up to but not including the first day of the specified year.
|
| |
| int | leap_day (int year) |
| | Counts leap-adjusted days up to some year.
|
| |
| static bool | equal_leap_off (struct leap_off lhs, struct leap_off rhs) |
| | Compares two leap_off structures for equality.
|
| |
| struct leap_off | leap_off (int year, int day_off) |
| | Offsets year and day of year.
|
| |
| int | leap_mday (int year, int month) |
| | Day of month from year and month.
|
| |
| int | leap_yday (int year, int month) |
| | Day of year from year and month.
|
| |
| static bool | equal_leap_date (struct leap_date lhs, struct leap_date rhs) |
| | Compares two leap_date structures for equality.
|
| |
| struct leap_date | leap_date (int year, int day_off) |
| | Date from year and day of year.
|
| |
| static struct leap_date | leap_date_from_off (struct leap_off off) |
| | Date from leap offset.
|
| |
| struct leap_off | leap_from (int year, int month, int day) |
| | Day from year, month and day of month.
|
| |
| static struct leap_off | leap_from_date (struct leap_date date) |
| | Day from leap date.
|
| |
| struct leap_date | leap_abs_date (int day_off) |
| | Absolute date from day of year.
|
| |
| int | leap_abs_from (int year, int month, int day) |
| | Absolute date from year, month, and day of month.
|
| |
| static int | leap_abs_from_date (struct leap_date date) |
| | Absolute date from leap_date structure.
|
| |
Leap year function prototypes.
Provides functions to determine if a year is a leap year, count leap years up to a given year, and calculate leap-adjusted days.
- Copyright
- 2025, Roy Ratcliffe, Northumberland, United Kingdom
Definition in file leap.h.
| struct leap_date leap_abs_date |
( |
int |
day_off | ) |
|
Absolute date from day of year.
Converts a day offset (from year 0) into a (year, month, day) date. The absolute day is anchored to year 0 such that day 0 corresponds to 0-01-01, making leap_day(0) == 0. Absolute days differ from Unix epoch days (which start at 1970-01-01).
- Parameters
-
| day_off | The absolute day offset, starting from 0 for the first day of year 0. |
- Returns
- The leap_date structure (year, month, day) corresponding to the absolute day.
Definition at line 135 of file leap.c.
| int leap_abs_from |
( |
int |
year, |
|
|
int |
month, |
|
|
int |
day |
|
) |
| |
Absolute date from year, month, and day of month.
Converts a (year, month, day) date into an absolute day offset from year 0 such that day 0 corresponds to 0-01-01, making leap_day(0) == 0. The absolute day is anchored at year 0, not Unix epoch (1970-01-01).
- Parameters
-
| year | The year. |
| month | The month, starting from 1 for January. |
| day | Day of the month, starting from 1 for the first day of the month. |
- Returns
- The absolute day offset from year 0.
Definition at line 137 of file leap.c.
Adds one for a leap year otherwise zero.
Answers 1 if the year is a leap year, otherwise answers 0. This is the same result as is_leap() except that the result is an explicit integer; 1 for leap years, 0 for non-leap years.
Compute the number of days in a given year as:
int leap_add(int year)
Adds one for a leap year otherwise zero.
- Parameters
-
- Return values
-
| 1 | if the year is a leap year. |
| 0 | if the year is not a leap year. |
Definition at line 28 of file leap.c.
| struct leap_off leap_from |
( |
int |
year, |
|
|
int |
month, |
|
|
int |
day |
|
) |
| |
Day from year, month and day of month.
Adjusts the month so that it sits in-between 1 and 12 inclusively. The month offsets the year. Returns the absolute date from the given year, month, and day of month.
- Parameters
-
| year | The year. |
| month | The month, starting from 1 for January. |
| day | The one-based day of the month, starting from 1 for the first day of the month. |
- Returns
- The absolute date as the number of days since the epoch.
Definition at line 129 of file leap.c.
Offsets year and day of year.
Year and day of year from year and day of year. Adjust the day so that it sits in-between 0 and 365 or 366, inclusively.
The day adjusts to be within the range of 0 to 365 or 366 inclusively, and the year is adjusted accordingly.
This function ensures that the day of the year does not exceed the number of days in the year, accounting for leap years. If the day is negative or exceeds the number of days in the year, it adjusts the year and day accordingly. The day is adjusted to be 0-based, meaning it starts from 0 for the first day of the year. The year is adjusted to account for the number of days in the year, which can be either 365 or 366 depending on whether it is a leap year.
- Parameters
-
| year | The year. |
| day_off | The day of the year offset, starting from 0. It can be negative or exceed the number of days in the year. |
- Return values
-
| leap_off.year | The year adjusted to account for the number of days in the year. The resulting year becomes normalised according to the day adjustment whether positive or negative. |
| leap_off.day | The adjusted day of the year, starting from 0 for the first day. The day is guaranteed to be within the bounds of the year. 0 <= day < 365 or 366 depending on whether it is a leap year. |
Definition at line 70 of file leap.c.
| int leap_thru |
( |
int |
year | ) |
|
Leap years completed from year 0 up to but not including the first day of the specified year.
Counts the number of leap years that have occurred from year 0 up to but not including the first day of the given year. This is calculated as the number of years divisible by 4, minus those divisible by 100, plus those divisible by 400. This accounts for the rules of leap years in the Gregorian calendar.
- Parameters
-
| year | The target year up to which leap years should be counted. |
- Returns
- The total number of leap years from year 0 through the specified year.
Definition at line 30 of file leap.c.