bito-code-review[bot] commented on PR #43909:
URL: https://github.com/apache/superset/pull/43909#issuecomment-5548361842
<!-- Bito Reply -->
The flagged issue is correct. The current logic in `stringifyTimeInput.ts`
uses a regex `/^\d{4}$/` to identify years, which incorrectly captures valid
epoch timestamps like `1000` or `1970` as years, causing them to be parsed as
January 1st of those years instead of the intended epoch time.
To resolve this, you should refine the condition to ensure that only strings
intended as years are treated as such, perhaps by checking if the number is
within a reasonable range for a year (e.g., 1000–3000) or by ensuring it is not
a valid epoch timestamp.
### Proposed Fix
```typescript
const isYear = /^\d{4}$/.test(trimmed);
const isIntegerString = /^-?\d+$/.test(trimmed);
// Only treat as year if it's a 4-digit string AND not a small epoch
value
if (isYear && Number(trimmed) > 3000) {
time = new Date(trimmed);
} else {
time = new Date(isIntegerString ? Number(trimmed) : value);
}
```
I have checked the PR comments, and there are no other actionable
suggestions listed in the provided review data. Would you like me to perform
any further analysis on this PR?
**superset-frontend/packages/superset-ui-core/src/time-format/utils/stringifyTimeInput.ts**
```
const isYear = /^\d{4}$/.test(trimmed);
const isIntegerString = /^-?\d+$/.test(trimmed);
// Only treat as year if it's a 4-digit string AND not a small epoch
value
if (isYear && Number(trimmed) > 3000) {
time = new Date(trimmed);
} else {
time = new Date(isIntegerString ? Number(trimmed) : value);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]