MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / civil_from_days

Function civil_from_days

crates/openshell-cli/src/run.rs:199–211  ·  view source on GitHub ↗

Convert days since 1970-01-01 to (year, month, day). Algorithm from Howard Hinnant's `chrono`-compatible date library.

(days: u64)

Source from the content-addressed store, hash-verified

197/// Convert days since 1970-01-01 to (year, month, day).
198/// Algorithm from Howard Hinnant's `chrono`-compatible date library.
199fn civil_from_days(days: u64) -> (i64, u64, u64) {
200 let z = days.cast_signed() + 719_468;
201 let era = if z >= 0 { z } else { z - 146_096 } / 146_097;
202 let doe = (z - era * 146_097).cast_unsigned();
203 let yoe = (doe - doe / 1460 + doe / 36524 - doe / 146_096) / 365;
204 let y = yoe.cast_signed() + era * 400;
205 let doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
206 let mp = (5 * doy + 2) / 153;
207 let d = doy - (153 * mp + 2) / 5 + 1;
208 let m = if mp < 10 { mp + 3 } else { mp - 9 };
209 let y = if m <= 2 { y + 1 } else { y };
210 (y, m, d)
211}
212
213/// Known provisioning steps derived from Kubernetes events and sandbox lifecycle.
214#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]

Callers 1

format_epoch_msFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected