Good that OP is using 4 simplifications: year 2000-2099, no DST, no leap second, no timezone. So OP knows of code limitations concerning these. Various elements of this function break without those givens.
Make
static unsigned short days
aconst
.Use a
long
for your epoch as in:void epoch_to_date_time(date_time_t* date_time,unsigned intlong epoch)
as unsigned
is only guaranteed to range form 0 to at least 65535 which is insufficient here.
For various functions, consider adding
const
. There are pros and cons to this, but may be beneficial in your case:// unsigned int date_time_to_epoch(date_time_t* date_time) unsigned int date_time_to_epoch(const date_time_t* date_time)
There exist equation based (non-loop) solutions to the year-day that do not need a table like your
unsigned short days[4][12]
. Code then looks more complicated, but is faster. Please advise if interested.Most of the magic numbers like 60, 24 are so well-known that constant or macro substitution seems superfluous. But
(365*4+1)
may benefit with something like "DaysPer4Years".