From 52da330cd1783a4a0cdf26f7b10326aac2502c73 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Sat, 15 Aug 2020 10:11:44 -0400 Subject: move common macros to separate header --- src/time/_time.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/time/_time.h (limited to 'src/time') diff --git a/src/time/_time.h b/src/time/_time.h new file mode 100644 index 00000000..e80bfdb7 --- /dev/null +++ b/src/time/_time.h @@ -0,0 +1,25 @@ +#ifndef ___TIME_H__ +#define ___TIME_H__ + +#define SEC_PER_MIN (60L) + +#define MIN_PER_HR (60L) +#define SEC_PER_HR ((SEC_PER_MIN) * (MIN_PER_HR)) + +#define HR_PER_DAY (24L) +#define SEC_PER_DAY ((SEC_PER_HR) * (HR_PER_DAY)) + +#define DAY_PER_YEAR (365L) /* not counting leap year */ +#define SEC_PER_YEAR ((SEC_PER_DAY) * (DAY_PER_YEAR)) +#define MON_PER_YEAR (12L) + +#define ISLEAPYEAR(y) ((y) % 4L == 0 && ((y) % 100L != 0 || (y) % 400L == 0)) + +/* it's really 1970, but tm_year is 0 based from 1900 */ +#define EPOCH_YEAR (70) + +/* months are zero based, so February is 1, etc. */ +#define DAYS_IN(y, m) (m == 1 ? (ISLEAPYEAR(y) ? 29 : 28) : \ + ((m == 3 || m == 5 || m == 8 || m == 10) ? 30 : 31)) + +#endif -- cgit v1.2.1