summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-08-15 10:12:04 -0400
committerJakob Kaivo <jkk@ung.org>2020-08-15 10:12:04 -0400
commit72a8a08a56082d29e425c3bec3fdd98596d3d390 (patch)
tree860008e0151329ef2b1d540238a55bfd9d678103
parent076cc42d3bb1e2f3b91d815e08d8d7e199a2be7a (diff)
move macros to _time.h
-rw-r--r--src/time/gmtime.c19
1 files changed, 3 insertions, 16 deletions
diff --git a/src/time/gmtime.c b/src/time/gmtime.c
index 9850e839..6e59612e 100644
--- a/src/time/gmtime.c
+++ b/src/time/gmtime.c
@@ -1,15 +1,6 @@
#include <time.h>
#include "_assert.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 ISLEAPYEAR(y) ((y) % 4L == 0 && ((y) % 100L != 0 || (y) % 400L == 0))
-# define EPOCH_YEAR (70)
+#include "_time.h"
/** convert arithmetic time to broken down time **/
@@ -18,7 +9,6 @@ struct tm * gmtime(const time_t * timer)
static struct tm tm = {0};
time_t seconds = 0;
int days = 0;
- int days_per_mon[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
ASSERT_NONNULL(timer);
seconds = *timer;
@@ -33,9 +23,6 @@ struct tm * gmtime(const time_t * timer)
}
tm.tm_year++;
}
- if (ISLEAPYEAR(tm.tm_year + 1900)) {
- days_per_mon[1] = 29;
- }
tm.tm_yday = (int)(seconds / SEC_PER_DAY);
seconds = seconds % SEC_PER_DAY;
@@ -46,8 +33,8 @@ struct tm * gmtime(const time_t * timer)
days = tm.tm_yday;
tm.tm_mon = 0;
- while (days > days_per_mon[tm.tm_mon]) {
- days -= days_per_mon[tm.tm_mon];
+ while (days > DAYS_IN(tm.tm_year, tm.tm_mon)) {
+ days -= DAYS_IN(tm.tm_year, tm.tm_mon);
tm.tm_mon++;
}
tm.tm_mday = days;