Fix timezone display: parse UTC timestamps correctly in logs pages
Agent-Logs-Url: https://github.com/christianlouis/InboxConverge/sessions/70a69601-e0b9-4a00-bcf4-0a85d2bdf6cb Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Parse an ISO-8601 datetime string as UTC.
|
||||
*
|
||||
* The backend stores all timestamps in UTC. When the serialised string has no
|
||||
* explicit timezone indicator (no trailing `Z` or `±HH:MM` offset), JavaScript's
|
||||
* `Date` constructor treats it as *local* time. For clients in UTC+N this
|
||||
* shifts every timestamp N hours into the past, causing "Xh ago" relative
|
||||
* labels and `toLocaleString()` absolute dates to be wrong.
|
||||
*
|
||||
* This helper appends `Z` to any timezone-naive ISO string so it is always
|
||||
* interpreted as UTC. Strings that already carry timezone info are passed
|
||||
* through unchanged.
|
||||
*/
|
||||
export function parseUTC(iso: string): Date {
|
||||
return new Date(/Z|[+-]\d{2}:?\d{2}$/.test(iso) ? iso : iso + 'Z');
|
||||
}
|
||||
Reference in New Issue
Block a user