-
-
Notifications
You must be signed in to change notification settings - Fork 419
timestamp cleanup #1508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
timestamp cleanup #1508
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -447,21 +447,35 @@ function localizeTimestamp(input) { | |
| return formatSafe(input, tz); | ||
|
|
||
| function formatSafe(str, tz) { | ||
| const date = new Date(str); | ||
| // CHECK: Does the input string have timezone information? | ||
| // - Ends with Z: "2026-02-11T11:37:02Z" | ||
| // - Has GMT±offset: "Wed Feb 11 2026 12:34:12 GMT+1100 (...)" | ||
| // - Has offset at end: "2026-02-11 11:37:02+11:00" | ||
| // - Has timezone name in parentheses: "(Australian Eastern Daylight Time)" | ||
| const hasOffset = /Z$/i.test(str.trim()) || | ||
| /GMT[+-]\d{2,4}/.test(str) || | ||
| /[+-]\d{2}:?\d{2}$/.test(str.trim()) || | ||
| /\([^)]+\)$/.test(str.trim()); | ||
|
|
||
| // ⚠️ CRITICAL: All DB timestamps are stored in UTC without timezone markers. | ||
| // If no offset is present, we must explicitly mark it as UTC by appending 'Z' | ||
| // so JavaScript doesn't interpret it as local browser time. | ||
| let isoStr = str.trim(); | ||
| if (!hasOffset) { | ||
| // Ensure proper ISO format before appending Z | ||
| // Replace space with 'T' if needed: "2026-02-11 11:37:02" → "2026-02-11T11:37:02Z" | ||
| isoStr = isoStr.trim().replace(/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})$/, '$1T$2') + 'Z'; | ||
| } | ||
|
Comment on lines
+455
to
+468
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Appending When case 5 (RFC2822, line 425) matches a string like Consider limiting the Proposed fix let isoStr = str.trim();
if (!hasOffset) {
- // Ensure proper ISO format before appending Z
- // Replace space with 'T' if needed: "2026-02-11 11:37:02" → "2026-02-11T11:37:02Z"
- isoStr = isoStr.trim().replace(/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})$/, '$1T$2') + 'Z';
+ // Only force UTC for ISO-shaped strings (DB timestamps)
+ if (/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(:\d{2})?$/.test(isoStr)) {
+ isoStr = isoStr.replace(' ', 'T') + 'Z';
+ }
}🤖 Prompt for AI Agents |
||
|
|
||
| const date = new Date(isoStr); | ||
| if (!isFinite(date)) { | ||
| console.error(`ERROR: Couldn't parse date: '${str}' with TIMEZONE ${tz}`); | ||
| return 'Failed conversion'; | ||
| } | ||
|
|
||
| // CHECK: Does the input string have an offset (e.g., +11:00 or Z)? | ||
| // If it does, and we apply a 'tz' again, we double-shift. | ||
| const hasOffset = /[Z|[+-]\d{2}:?\d{2}]$/.test(str.trim()); | ||
|
|
||
| return new Intl.DateTimeFormat(LOCALE, { | ||
| // If it has an offset, we display it as-is (UTC mode in Intl | ||
| // effectively means "don't add more hours"). | ||
| // If no offset, apply your variable 'tz'. | ||
| timeZone: hasOffset ? 'UTC' : tz, | ||
| // Convert from UTC to user's configured timezone | ||
| timeZone: tz, | ||
| year: 'numeric', month: '2-digit', day: '2-digit', | ||
| hour: '2-digit', minute: '2-digit', second: '2-digit', | ||
| hour12: false | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.