+ /* Now time is the number of days since 1970-01-01 (a Thursday) */
+ result->tm_wday = (time + 4) % 7;
+
+ /* Below from http://howardhinnant.github.io/date_algorithms.html */
+ time += 719468;
+ era = time / 146097;
+ doe = time - era * 146097;
+ yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365;
+
+ result->tm_year = yoe + era * 400;
+ result->tm_yday = doe - (365 * yoe + yoe / 4 - yoe / 100);
+ mp = (5 * result->tm_yday + 2) / 153;
+ result->tm_mday = result->tm_yday - (153 * mp + 2) / 5 + 1;
+ result->tm_mon = mp + (mp < 10 ? 2 : -10);
+ if (result->tm_mon <=2)
+ result->tm_year++;
+
+ /* result->tm_yday is March 1st indexed at this point; fix up */
+ result->tm_yday += 28 + 31;
+ if (is_leap(result->tm_year))
+ result->tm_yday++;