This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ported date utility function from http://howardhinnant.github.io/date_algorithms.html | |
// @param z Days since epoch | |
// @return Civic date tuple [y, m, d] | |
local civil_from_days(z) = ( | |
local z1 = z + 719468; | |
local era = std.floor((if z1 >= 0 then z1 else z1 - 146096) / 146097); | |
local doe = (z1 - era * 146097); // [0, 146096] | |
local yoe = std.floor((doe - std.floor(doe / 1460) + std.floor(doe / 36524) - std.floor(doe / 146096)) / 365); // [0, 399] | |
local y = yoe + era * 400; |