| 368 | } |
| 369 | |
| 370 | func formatAge(now func() time.Time, then time.Time) string { |
| 371 | if then.IsZero() { |
| 372 | return "" |
| 373 | } |
| 374 | current := time.Now().UTC() |
| 375 | if now != nil { |
| 376 | current = now().UTC() |
| 377 | } |
| 378 | delta := max(current.Sub(then.UTC()), 0) |
| 379 | |
| 380 | switch { |
| 381 | case delta < time.Minute: |
| 382 | return fmt.Sprintf("%ds", int(delta.Seconds())) |
| 383 | case delta < time.Hour: |
| 384 | return fmt.Sprintf("%dm", int(delta.Minutes())) |
| 385 | case delta < 24*time.Hour: |
| 386 | return fmt.Sprintf("%dh", int(delta.Hours())) |
| 387 | default: |
| 388 | return fmt.Sprintf("%dd", int(delta.Hours()/24)) |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | func stringOrDash(value string) string { |
| 393 | trimmed := strings.TrimSpace(value) |