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

Function format_epoch_ms

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

Format milliseconds since Unix epoch as a `YYYY-MM-DD HH:MM:SS` UTC string.

(ms: i64)

Source from the content-addressed store, hash-verified

167
168/// Format milliseconds since Unix epoch as a `YYYY-MM-DD HH:MM:SS` UTC string.
169fn format_epoch_ms(ms: i64) -> String {
170 use std::time::UNIX_EPOCH;
171
172 let Ok(ms_u64) = u64::try_from(ms) else {
173 return "-".to_string();
174 };
175 let Ok(time) = UNIX_EPOCH
176 .checked_add(Duration::from_millis(ms_u64))
177 .ok_or(())
178 else {
179 return "-".to_string();
180 };
181 let Ok(dur) = time.duration_since(UNIX_EPOCH) else {
182 return "-".to_string();
183 };
184
185 let secs = dur.as_secs();
186 let days = secs / 86400;
187 let time_of_day = secs % 86400;
188 let hours = time_of_day / 3600;
189 let minutes = (time_of_day % 3600) / 60;
190 let seconds = time_of_day % 60;
191
192 // Convert days since epoch to year-month-day using a basic civil calendar algorithm.
193 let (y, m, d) = civil_from_days(days);
194 format!("{y:04}-{m:02}-{d:02} {hours:02}:{minutes:02}:{seconds:02}")
195}
196
197/// Convert days since 1970-01-01 to (year, month, day).
198/// Algorithm from Howard Hinnant's `chrono`-compatible date library.

Callers 2

sandbox_listFunction · 0.85
format_optional_epoch_msFunction · 0.85

Calls 1

civil_from_daysFunction · 0.85

Tested by

no test coverage detected