- // TODO: This breaks on negative timestamps
-
- int64_t day = *timer / (1000*60*60*24);
- int64_t iday = *timer % (1000*60*60*24);
+}
+struct tm *localtime_r(const time_t *timer, struct tm *ret)
+{
+ // Hours, Mins, Seconds
+ int64_t days = get_days_since_y2k(*timer, &ret->tm_hour, &ret->tm_min, &ret->tm_sec);
+
+ // Week day
+ ret->tm_wday = (days + 6) % 7; // Sun = 0, 1 Jan 2000 was Sat (6)
+
+ // Year and Day of Year
+ bool is_ly;
+ ret->tm_year = 2000 + get_years_since_y2k(days, &is_ly, &ret->tm_yday);