mirror of
https://github.com/twentyhq/twenty
synced 2026-04-21 13:37:22 +00:00
fix: parse date-only strings as local midnight in relative date formatting
https://sonarly.com/issue/24466?type=bug DATE fields displayed in RELATIVE format show the wrong day (e.g., "Today" instead of "Tomorrow") for users in timezones west of UTC, because date-only strings are parsed as UTC midnight then compared against local time. Fix: Changed the date parsing in `formatDateISOStringToRelativeDate.ts` line 22 to handle date-only strings (yyyy-MM-dd format, length 10) by appending `T00:00:00` without a trailing `Z`. This forces the `Date` constructor to interpret the string as local midnight instead of UTC midnight. Per the ECMAScript spec, `new Date("2026-04-14")` produces UTC midnight (`2026-04-14T00:00:00.000Z`), which falls on April 13 in timezones west of UTC. By appending `T00:00:00` (no `Z`), the Date constructor uses local time, keeping the date on the correct calendar day for the user's timezone. Full datetime strings (with time and timezone components, length > 10) continue to use the original `new Date(isoDate)` parsing, preserving correct behavior for the `formatDateTimeString` caller that passes datetime values. This matches how the other format branches (USER_SETTINGS, CUSTOM) already handle timezone correctly via `formatInTimeZone` with explicit timezone parameters.
This commit is contained in:
parent
21142d98fe
commit
8efeae86af
1 changed files with 4 additions and 1 deletions
|
|
@ -19,7 +19,10 @@ export const formatDateISOStringToRelativeDate = ({
|
|||
localeCatalog: Locale;
|
||||
}) => {
|
||||
const now = new Date();
|
||||
const targetDate = new Date(isoDate);
|
||||
// For date-only strings (yyyy-MM-dd), append T00:00:00 without Z
|
||||
// to force local-time parsing instead of the spec's default UTC midnight
|
||||
const targetDate =
|
||||
isoDate.length === 10 ? new Date(isoDate + 'T00:00:00') : new Date(isoDate);
|
||||
|
||||
if (isDayMaximumPrecision && isToday(targetDate)) return t`Today`;
|
||||
if (isDayMaximumPrecision && isYesterday(targetDate)) return t`Yesterday`;
|
||||
|
|
|
|||
Loading…
Reference in a new issue