Commit 375dbb8
fix(utils): return original input from date formatters on invalid dates
formatCompactTimestamp and formatAbsoluteDate both build their output
from Date getters. An unparseable string produces an Invalid Date whose
getters return NaN rather than throwing, so formatCompactTimestamp's
try/catch fallback never ran and it returned "NaN-NaN NaN:NaN", while
formatAbsoluteDate returned the literal "Invalid Date".
Both now check Number.isNaN(date.getTime()) up front and fall back to the
original input string, which is what the existing catch was meant to do.
Valid dates are unaffected.
Updates the formatCompactTimestamp invalid-date test to assert the
returned value instead of only its type, and adds a matching test for
formatAbsoluteDate.
Co-authored-by: eeshsaxena <eeshsaxena@gmail.com>1 parent 2977db5 commit 375dbb8
2 files changed
Lines changed: 17 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
71 | 75 | | |
72 | 76 | | |
73 | 77 | | |
| |||
99 | 103 | | |
100 | 104 | | |
101 | 105 | | |
102 | | - | |
| 106 | + | |
103 | 107 | | |
104 | | - | |
| 108 | + | |
| 109 | + | |
105 | 110 | | |
106 | 111 | | |
107 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
107 | 112 | | |
108 | 113 | | |
109 | 114 | | |
| |||
150 | 155 | | |
151 | 156 | | |
152 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
153 | 163 | | |
154 | 164 | | |
155 | 165 | | |
| |||
0 commit comments