fix: Date value cannot be pasted into date field in data browser#3243
fix: Date value cannot be pasted into date field in data browser#3243mtrezza merged 4 commits intoparse-community:alphafrom
Conversation
|
🚀 Thanks for opening this pull request! |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughRemoved automatic prop-to-state sync in DateTimeEditor and changed commitDate timezone handling to treat inputs ending with 'Z' or 'UTC' as explicit timezones (use parsed value) and treat other inputs as local time (convert to UTC). Replaced manual UTC string assembly with locale-based formatting in dateStringUTC. Changes
Sequence Diagram(s)Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/components/DateTimeEditor/DateTimeEditor.react.js (1)
84-101: Timezone detection may miss common formats.The fix correctly handles the paste scenario for local time inputs, but the timezone detection is limited:
- Only checks for
'Z'and'UTC'suffixes, missing other common formats like'+00:00','+0000','GMT', or offset timezones like'+05:30'.- The check is case-sensitive—
'utc'or'Utc'would be treated as local time.For example, pasting
2024-03-01T10:00:00+05:30would incorrectly be treated as local time and double-converted.Consider a more robust timezone detection:
♻️ Suggested improvement for timezone detection
} else { - if (this.state.text.endsWith('Z') || this.state.text.endsWith('UTC')) { + // Check for explicit timezone indicators (Z, UTC, GMT, or numeric offsets like +00:00, -0530) + const hasExplicitTimezone = /(?:Z|UTC|GMT|[+-]\d{2}:?\d{2})$/i.test(this.state.text.trim()); + if (hasExplicitTimezone) { // Timezone is explicit; the parsed Date is already correct. this.setState({ value: date }); } else {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/DateTimeEditor/DateTimeEditor.react.js` around lines 84 - 101, The timezone detection that checks this.state.text.endsWith('Z') or 'UTC' is too narrow and case-sensitive; update the check in DateTimeEditor to use a case-insensitive regex against this.state.text (trimmed) that matches common timezone suffixes such as Z, UTC, GMT and numeric offsets like +05:30 or +0530 (e.g. /(?:Z|UTC|GMT|[+-]\d{2}:?\d{2})$/i). If the regex matches treat the parsed Date as already correct and call this.setState({ value: date }) as before; otherwise keep the existing local-to-UTC conversion that creates utc via Date.UTC(...) and then call this.setState({ value: utc }). Ensure you reference this.state.text for matching and preserve the existing Date.UTC conversion logic and this.setState calls.src/lib/DateUtils.js (1)
105-117: Consider usingtoLocaleStringinstead oftoLocaleDateStringfor semantic clarity.The refactored function is cleaner and works correctly for all callers. However,
toLocaleStringis more semantically appropriate for datetime formatting, sincetoLocaleDateStringis conventionally for date-only values. WhiletoLocaleDateStringwith time options works in practice, switching totoLocaleStringwould make the intent clearer:export function dateStringUTC(date) { return date.toLocaleString('en-GB', { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false, timeZone: 'UTC', timeZoneName: 'short', }); }All current usages display the result in the UI and don't depend on a specific format, so this change is safe.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lib/DateUtils.js` around lines 105 - 117, Replace the use of Date.prototype.toLocaleDateString with toLocaleString in the dateStringUTC function: change the call inside export function dateStringUTC(date) from date.toLocaleDateString(...) to date.toLocaleString(...) while keeping the same locale ('en-GB') and options (year, month, day, hour, minute, second, hour12: false, timeZone: 'UTC', timeZoneName: 'short') so the function semantics match datetime formatting.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/components/DateTimeEditor/DateTimeEditor.react.js`:
- Around line 84-101: The timezone detection that checks
this.state.text.endsWith('Z') or 'UTC' is too narrow and case-sensitive; update
the check in DateTimeEditor to use a case-insensitive regex against
this.state.text (trimmed) that matches common timezone suffixes such as Z, UTC,
GMT and numeric offsets like +05:30 or +0530 (e.g.
/(?:Z|UTC|GMT|[+-]\d{2}:?\d{2})$/i). If the regex matches treat the parsed Date
as already correct and call this.setState({ value: date }) as before; otherwise
keep the existing local-to-UTC conversion that creates utc via Date.UTC(...) and
then call this.setState({ value: utc }). Ensure you reference this.state.text
for matching and preserve the existing Date.UTC conversion logic and
this.setState calls.
In `@src/lib/DateUtils.js`:
- Around line 105-117: Replace the use of Date.prototype.toLocaleDateString with
toLocaleString in the dateStringUTC function: change the call inside export
function dateStringUTC(date) from date.toLocaleDateString(...) to
date.toLocaleString(...) while keeping the same locale ('en-GB') and options
(year, month, day, hour, minute, second, hour12: false, timeZone: 'UTC',
timeZoneName: 'short') so the function semantics match datetime formatting.
# [9.1.0-alpha.3](9.1.0-alpha.2...9.1.0-alpha.3) (2026-03-01) ### Bug Fixes * Date value cannot be pasted into date field in data browser ([#3243](#3243)) ([e902bea](e902bea))
|
🎉 This change has been released in version 9.1.0-alpha.3 |
Pull Request
Issue
Date value cannot be pasted into date field in data browser.
Tasks
Summary by CodeRabbit
Bug Fixes
Refactor