|
40 | 40 | use crate::hash::Hash; |
41 | 41 | use crate::objects::{MorphObject, Tombstone}; |
42 | 42 | use crate::store::{FsStore, MorphError, ObjectType}; |
| 43 | +use crate::time::now_rfc3339_utc; |
43 | 44 |
|
44 | 45 | /// Identifies the result of a forget operation. Used by the CLI to |
45 | 46 | /// surface a one-line confirmation to the operator. |
@@ -171,7 +172,7 @@ pub fn forget_local( |
171 | 172 | let tombstone = Tombstone { |
172 | 173 | original_hash: target.to_string(), |
173 | 174 | original_kind: kind.to_string(), |
174 | | - forgotten_at: now_iso8601(), |
| 175 | + forgotten_at: now_rfc3339_utc(), |
175 | 176 | actor: actor.to_string(), |
176 | 177 | reason: reason.map(|s| s.to_string()), |
177 | 178 | }; |
@@ -218,47 +219,6 @@ pub const RETROACTIVE_NOTE: &str = |
218 | 219 | before the deletion. If a teammate previously pulled this hash, \ |
219 | 220 | ask them to fetch from the remote again or delete it by hand."; |
220 | 221 |
|
221 | | -fn now_iso8601() -> String { |
222 | | - use std::time::{SystemTime, UNIX_EPOCH}; |
223 | | - let secs = SystemTime::now() |
224 | | - .duration_since(UNIX_EPOCH) |
225 | | - .map(|d| d.as_secs()) |
226 | | - .unwrap_or(0); |
227 | | - chrono_strftime_rfc3339_utc(secs) |
228 | | -} |
229 | | - |
230 | | -/// Tiny self-contained RFC-3339 (UTC) formatter so we don't pull |
231 | | -/// in `chrono` here. Equivalent of `chrono::DateTime::<Utc>::from_timestamp(secs, 0).format(...)`. |
232 | | -fn chrono_strftime_rfc3339_utc(secs: u64) -> String { |
233 | | - let days = (secs / 86400) as i64; |
234 | | - let secs_of_day = secs % 86400; |
235 | | - let h = secs_of_day / 3600; |
236 | | - let m = (secs_of_day % 3600) / 60; |
237 | | - let s = secs_of_day % 60; |
238 | | - |
239 | | - let (y, mo, d) = days_to_ymd(days + 719468); |
240 | | - format!( |
241 | | - "{:04}-{:02}-{:02}T{:02}:{:02}:{:02}Z", |
242 | | - y, mo, d, h, m, s |
243 | | - ) |
244 | | -} |
245 | | - |
246 | | -/// Howard Hinnant's date algorithm — converts days since |
247 | | -/// 0000-03-01 (proleptic Gregorian) to a (year, month, day). |
248 | | -fn days_to_ymd(days_since_epoch: i64) -> (i64, u32, u32) { |
249 | | - let z = days_since_epoch; |
250 | | - let era = if z >= 0 { z } else { z - 146096 } / 146097; |
251 | | - let doe = (z - era * 146097) as u64; |
252 | | - let yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365; |
253 | | - let y = yoe as i64 + era * 400; |
254 | | - let doy = doe - (365 * yoe + yoe / 4 - yoe / 100); |
255 | | - let mp = (5 * doy + 2) / 153; |
256 | | - let d = (doy - (153 * mp + 2) / 5 + 1) as u32; |
257 | | - let m = if mp < 10 { (mp + 3) as u32 } else { (mp - 9) as u32 }; |
258 | | - let y = if m <= 2 { y + 1 } else { y }; |
259 | | - (y, m, d) |
260 | | -} |
261 | | - |
262 | 222 | trait ObjectTypeName { |
263 | 223 | fn object_type_name(&self) -> &'static str; |
264 | 224 | } |
|
0 commit comments