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 <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-07-26 16:20:04 -04:00
parent 65b547f60b
commit d222c306e0
3 changed files with 13 additions and 3 deletions

View File

@ -5,12 +5,18 @@
#define OCARINA_CORE_DATE_H
#include <core/file.h>
#include <stdint.h>
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;
};
};

View File

@ -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, \

View File

@ -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");