leapc
Loading...
Searching...
No Matches
leap.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: MIT */
10#ifndef __LEAP_H__
11#define __LEAP_H__
12
13#include <stdbool.h>
14
19#define LEAP_MCM 693961
20
30bool is_leap(int year);
31
46int leap_add(int year);
47
60int leap_thru(int year);
61
70int leap_day(int year);
71
77struct leap_off {
81 int year;
85 int day;
86};
87
105static inline bool equal_leap_off(struct leap_off lhs, struct leap_off rhs) {
106 return lhs.year == rhs.year && lhs.day == rhs.day;
107}
108
134struct leap_off leap_off(int year, int day_off);
135
145int leap_mday(int year, int month);
146
156int leap_yday(int year, int month);
157
163struct leap_date {
167 int year;
174 int month;
181 int day;
182};
183
193static inline bool equal_leap_date(struct leap_date lhs, struct leap_date rhs) {
194 return lhs.year == rhs.year && lhs.month == rhs.month && lhs.day == rhs.day;
195}
196
210struct leap_date leap_date(int year, int day_off);
211
218static inline struct leap_date leap_date_from_off(struct leap_off off) { return leap_date(off.year, off.day); }
219
231struct leap_off leap_from(int year, int month, int day);
232
240static inline struct leap_off leap_from_date(struct leap_date date) {
241 return leap_from(date.year, date.month, date.day);
242}
243
255struct leap_date leap_abs_date(int day_off);
256
267int leap_abs_from(int year, int month, int day);
268
275static inline int leap_abs_from_date(struct leap_date date) { return leap_abs_from(date.year, date.month, date.day); }
276
277#endif /* __LEAP_H__ */
static bool equal_leap_off(struct leap_off lhs, struct leap_off rhs)
Compares two leap_off structures for equality.
Definition leap.h:105
int leap_thru(int year)
Leap years completed from year 0 up to but not including the first day of the specified year.
Definition leap.c:30
struct leap_off leap_from(int year, int month, int day)
Day from year, month and day of month.
Definition leap.c:129
static int leap_abs_from_date(struct leap_date date)
Absolute date from leap_date structure.
Definition leap.h:275
static struct leap_date leap_date_from_off(struct leap_off off)
Date from leap offset.
Definition leap.h:218
int leap_mday(int year, int month)
Day of month from year and month.
Definition leap.c:80
static struct leap_off leap_from_date(struct leap_date date)
Day from leap date.
Definition leap.h:240
bool is_leap(int year)
Determine if a year is a leap year.
Definition leap.c:13
struct leap_date leap_abs_date(int day_off)
Absolute date from day of year.
Definition leap.c:135
static bool equal_leap_date(struct leap_date lhs, struct leap_date rhs)
Compares two leap_date structures for equality.
Definition leap.h:193
int leap_add(int year)
Adds one for a leap year otherwise zero.
Definition leap.c:28
int leap_day(int year)
Counts leap-adjusted days up to some year.
Definition leap.c:48
int leap_yday(int year, int month)
Day of year from year and month.
Definition leap.c:86
int leap_abs_from(int year, int month, int day)
Absolute date from year, month, and day of month.
Definition leap.c:137
Leap year date structure.
Definition leap.h:163
int year
Year.
Definition leap.h:167
int month
Month of year starting from 1 for January.
Definition leap.h:174
int day
Day of month starting from 1 for the first day of the month.
Definition leap.h:181
Leap offset by year and day.
Definition leap.h:77
int day
Day of year offset.
Definition leap.h:85
int year
Year offset.
Definition leap.h:81