remove duplicated epoch handling, test it

This commit is contained in:
Sergio R. Caprile committed 2026-07-15 15:53:38 -03:00
1 parent 7a2a3fc136
commit b6a353cae9
7 files changed
+63 -80

No files matched your search

+16
View File
@@ -9,6 +9,22 @@ void mg_bzero(volatile unsigned char *buf, size_t len) {
}
}
uint64_t mg_timegm(unsigned int year, unsigned int month, unsigned int day,
unsigned int hour, unsigned int min, unsigned int sec) {
static const uint16_t dm[12] = {0, 31, 59, 90, 120, 151,
181, 212, 243, 273, 304, 334};
const uint64_t day_secs = 86400;
const uint64_t year_secs = 31536000;
unsigned int y, ly;
if (year < 1970) return 0;
y = year - 1900;
ly = month > 2 ? y + 1 : y;
return (uint64_t) sec + 60 * min + 3600 * hour +
day_secs * (dm[month - 1] + day - 1) + year_secs * (y - 70) +
day_secs * ((ly - 69) / 4) - day_secs * ((ly - 1) / 100) +
day_secs * ((ly + 299) / 400);
}
#if MG_ENABLE_CUSTOM_RANDOM
#else
bool mg_random(void *buf, size_t len) {