summaryrefslogtreecommitdiff
path: root/src/time
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-08-15 10:11:44 -0400
committerJakob Kaivo <jkk@ung.org>2020-08-15 10:11:44 -0400
commit52da330cd1783a4a0cdf26f7b10326aac2502c73 (patch)
tree75db35d64bc6153a8d43fce4c5dd02db3f52d2ef /src/time
parent36950c4d3bce143c3ecdc4ee96b97c33576571bb (diff)
move common macros to separate header
Diffstat (limited to 'src/time')
-rw-r--r--src/time/_time.h25
1 files changed, 25 insertions, 0 deletions
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