Commit 5d058bf
authored
output: format timestamps and durations in --human (#41)
## Description
Formats timestamps and durations in `--human` mode so they're actually human-readable.
**Before:**
```
ID Title Status Created
4621f8ba1a8f4811b32f669c37be53a2 HeyGen in 20 Seconds completed 1774712936
```
**After:**
```
ID Title Status Created
4621f8ba1a8f4811b32f669c37be53a2 HeyGen in 20 Seconds completed 2026-03-28 15:48
```
**Timestamp formatting:**
- Detects unix timestamps by heuristic: integer-valued floats between 1.5e9 and 2.2e9 (covers 2017–2039)
- Formats as UTC: `2006-01-02 15:04`
- Won't false-positive on durations (small floats), IDs (strings), or counts (integers outside range)
**Duration formatting:**
- Detects by field name: any field containing "duration" (case-insensitive)
- `18.9649` → `18s`, `62.5` → `1m 2s`, `3661.0` → `1h 1m 1s`
**Implementation:**
- New `formatCell(v, fieldName)` function wraps `formatValue` with context-aware formatting
- Called from `renderTable` and `renderKeyValue` (both paths get formatting)
- `formatValue` unchanged — JSON mode is unaffected
Stacked on PR #40 (help text fixes).
## Testing
3 new tests:
- `TestHumanFormatter_Data_TimestampFormatting` — unix epoch `1774712936` renders as `2026-03-28 15:48`
- `TestHumanFormatter_Data_DurationFormatting` — float `18.9649` with field name "duration" renders as `18s`
- `TestHumanFormatter_Data_RegularFloatUnaffected` — float `3.14` with field name "score" stays `3.14`1 parent 95a2a10 commit 5d058bf
2 files changed
Lines changed: 84 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
101 | | - | |
| 102 | + | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| |||
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
114 | | - | |
| 115 | + | |
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
| |||
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
162 | | - | |
| 163 | + | |
163 | 164 | | |
164 | 165 | | |
165 | 166 | | |
| |||
232 | 233 | | |
233 | 234 | | |
234 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
235 | 248 | | |
236 | 249 | | |
237 | 250 | | |
| |||
261 | 274 | | |
262 | 275 | | |
263 | 276 | | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
264 | 295 | | |
265 | 296 | | |
266 | 297 | | |
| |||
273 | 304 | | |
274 | 305 | | |
275 | 306 | | |
276 | | - | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
82 | 132 | | |
83 | 133 | | |
84 | 134 | | |
| |||
0 commit comments