package console import ( "testing" "time" ) func TestUntilHelper(t *testing.T) { // humanAge always renders both components in the 1-24h bucket // ("4h0m", never bare "4h"), and untilText's own time.Until call runs a // few microseconds after this Add — just enough for the floored minute // to round down once. "~4h1m" covers the (vanishingly unlikely) case // where the call lands before that rollover. if got := untilText(time.Now().Add(4*time.Hour + time.Minute)); got != "~4h0m" && got != "~4h1m" { t.Errorf("until ~4h = %q", got) } if got := untilText(time.Time{}); got != "now" { t.Errorf("until zero = %q", got) } if got := untilText(time.Now().Add(-time.Hour)); got != "now" { t.Errorf("until past = %q", got) } }