|
leapc
|
Leap year function implementations. More...

Go to the source code of this file.
Functions | |
| 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. | |
| 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. | |
| struct leap_date | leap_date (int year, int day_off) |
| Date from year and day of year. | |
| struct leap_off | leap_from (int year, int month, int day) |
| Day from year, month and day of month. | |
| 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. | |
Leap year function implementations.
Implements functions to determine if a year is a leap year, count leap years up to a given year, and calculate leap-adjusted days.
Definition in file leap.c.
| bool is_leap | ( | int | year | ) |
Determine if a year is a leap year.
Is a year a leap year? A year is a leap year if it is divisible by four, except for years that are divisible by 100, unless they are also divisible by 400.
| year | The year to check. |
| true | if the year is a leap year. |
| false | if the year is not a leap year. |
| 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).
| day_off | The absolute day offset, starting from 0 for the first day of year 0. |
| 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).
| 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. |
| int leap_add | ( | int | year | ) |
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:
| year | The year to check. |
| 1 | if the year is a leap year. |
| 0 | if the year is not a leap year. |
Date from year and day of year.
Adjust the day so that it sits in-between 1 and 365 (or 366) inclusively. Returns the year, month, and day of the month for the given year and day of year. The day of the month is adjusted to be 1-based, meaning it starts from 1 for the first day of the month.
| year | The year. |
| day_off | Day of the year offset, starting from 0 for first of January. |
| leap_date.year | The year. |
| leap_date.month | The month, starting from 1 for January. |
| leap_date.day | The day of the month, starting from 1 for the first day of the month. |
| int leap_day | ( | int | year | ) |
Counts leap-adjusted days up to some year.
Counts the number of days completed up to but not including the first day of the year.
| year | The year to check. |
| 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.
| 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. |
| int leap_mday | ( | int | year, |
| int | month | ||
| ) |
Day of month from year and month.
Returns the number of days in the month for the given year and month. Accounts for leap years in February.
| year | The year. |
| month | The month ordinal, starting from 1 for January. |
| The | number of days in the month, accounting for leap years in February. |
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.
| 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. |
| 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. |
| 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.
| year | The target year up to which leap years should be counted. |
| int leap_yday | ( | int | year, |
| int | month | ||
| ) |
Day of year from year and month.
Returns the day of the year for the given year and month. The day of the year is calculated by summing the days in the months up to the given month, and adding an extra day if the month is after February in a leap year.
| year | The year. |
| month | The month ordinal, starting from 1 for January. |
| The | day of the year, starting from 0 for first of January. |