From d222c306e0f11a3e25ec9b52b46b13826b286a6d Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 26 Jul 2016 16:20:04 -0400 Subject: [PATCH] core/date: Force struct date into 32bits Three unsigned integers is overkill for handling dates. Implements #65: Date structure can be represented with a single 32bit value Signed-off-by: Anna Schumaker --- include/core/date.h | 12 +++++++++--- include/tests/test.h | 2 ++ tests/core/date.c | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/core/date.h b/include/core/date.h index 6d7496e7..d9879f53 100644 --- a/include/core/date.h +++ b/include/core/date.h @@ -5,12 +5,18 @@ #define OCARINA_CORE_DATE_H #include +#include struct date { - unsigned int d_year; - unsigned int d_month; - unsigned int d_day; + union { + struct { + uint16_t d_year; + uint8_t d_month; + uint8_t d_day; + }; + uint32_t d_stamp; + }; }; diff --git a/include/tests/test.h b/include/tests/test.h index bef09981..9d8424c9 100644 --- a/include/tests/test.h +++ b/include/tests/test.h @@ -27,9 +27,11 @@ static inline gchar *ptos(void *p) { return g_strdup_printf("%p", p); } #define tostring(x) (_Generic((x), \ char *: stos, \ const char *: stos, \ + unsigned char: utos, \ bool: btos, \ long unsigned int: lutos, \ unsigned int: utos, \ + short unsigned int: utos, \ long int: ltos, \ int: itos, \ float:ftos, \ diff --git a/tests/core/date.c b/tests/core/date.c index d3b97c36..96b4dbed 100644 --- a/tests/core/date.c +++ b/tests/core/date.c @@ -29,6 +29,7 @@ void test_date() test_equal(date.d_year, 1988); test_equal(date.d_month, 6); test_equal(date.d_day, 17); + test_equal(date.d_stamp, 285607876); date_write(&f, &date); file_writef(&f, "\n"); @@ -45,6 +46,7 @@ void test_date() test_equal(date.d_year, 1988); test_equal(date.d_month, 6); test_equal(date.d_day, 17); + test_equal(date.d_stamp, 285607876); str = date_string(&date); test_equal(str, "06/17/88");