Skip to main content

render_go_duration

Function render_go_duration 

Source
pub fn render_go_duration(d: Duration) -> String
Expand description

Render a Duration back to a Go-style duration string, using the largest unit that divides it exactly (21600s"6h", 1200s"20m", else "{n}s").

Round-trips through parse_go_duration by construction — it emits only the single-unit grammar that function accepts. Two callers need it:

  • kopia argv. Durations that reach a kopia CLI flag must never be the user’s raw text. kopia’s time.ParseDuration REJECTS a bare number (--epoch-min-duration=3600time: missing unit in duration "3600") while parse_go_duration happily accepts one — so passing the string through would admit at the webhook and crash in the mover, breaking this module’s stated contract. Parse, then render, and the mismatch is gone.
  • Status mirrors. kopia reports durations as time.Duration nanoseconds; rendering them through here is what makes status comparable to spec and stable across reconciles (no "24h" vs "24h0m0s" ambiguity).