Skip to content

fix(ui5-dynamic-date-range): correct off-by-one-day date shift in negative UTC offsets - #14017

Open
unazko wants to merge 5 commits into
mainfrom
dynamic_date_range_timezone
Open

fix(ui5-dynamic-date-range): correct off-by-one-day date shift in negative UTC offsets#14017
unazko wants to merge 5 commits into
mainfrom
dynamic_date_range_timezone

Conversation

@unazko

@unazko unazko commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Issue:

When selecting dates using the DATE, DATERANGE, FROMDATETIME or TODATETIME
options, the returned dates were one day earlier than what the user picked in the
calendar. This only affected users in timezones behind UTC (e.g. Americas), where
the internal calendar timestamp was being interpreted as the previous local day.

Solution:

The timestamp coming from the calendar represents a specific calendar
day in UTC. Instead of converting it directly to a JavaScript Date (which shifts
it into local time), we now use the existing CalendarDate abstraction to extract
the correct day and produce a local Date that always matches what the user
selected, regardless of timezone. The conversion is extracted into a shared
calendarTimestampToLocalDate helper in toDates.ts so all affected options use
a single consistent implementation.

A unit test for calendarTimestampToLocalDate is included, validating that the
local date components of the result always match the UTC date of the calendar
timestamp. Note: the test is most meaningful in negative UTC-offset environments;
to verify locally run the calendar selection tests with TZ=America/Los_Angeles.

Fixes: #14005

…ative UTC offsets

Issue: When selecting dates using the DATE or DATERANGE options, the resolved
values were shifted one day earlier than what the user selected in the calendar.
This occurred in browsers running in negative UTC-offset timezones (e.g.
America/Los_Angeles, America/Monterrey). The calendar fires selectedDates as
Unix timestamps in seconds representing UTC midnight. Both SingleDate and
DateRange converted these directly via new Date(ts * 1000) / UI5Date.getInstance(ts * 1000),
producing a Date at UTC midnight. In a GMT-6 environment, that instant is the
previous day at 18:00 local time. The subsequent setHours(0, 0, 0, 0) call in
toDates() then locked in the wrong local day.

Solution: Replace the raw timestamp-to-Date conversion in handleSelectionChange
with CalendarDate.fromTimestamp(ts * 1000).toLocalJSDate(). CalendarDate is a
date-only abstraction that stores the day in UTC internally; toLocalJSDate()
re-applies the UTC year/month/date as local date fields, ensuring the resulting
Date always represents the correct calendar day at local midnight regardless of
timezone offset. This mirrors the same pattern already used in CalendarDate
internally.

Fixes: #14005
@unazko
unazko temporarily deployed to netlify-preview September 2, 2026 08:00 — with GitHub Actions Inactive
@unazko
unazko temporarily deployed to netlify-preview September 2, 2026 08:05 — with GitHub Actions Inactive
@sap-ui5-webcomponents-release

Copy link
Copy Markdown

@unazko
unazko temporarily deployed to netlify-preview September 2, 2026 08:32 — with GitHub Actions Inactive
@didip1000
didip1000 self-requested a review September 3, 2026 06:35

@didip1000 didip1000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think SingleDate would also need to be fixed

@unazko

unazko commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

I think SingleDate would also need to be fixed

Actually the SingleDate option was already fixed, but you have a good point. There are two more options that have the same timezone related issue.

…ative UTC offsets

Issue: When selecting dates using the DATE, DATERANGE, FROMDATETIME or TODATETIME
options, the returned dates were one day earlier than what the user picked in the
calendar. This only affected users in timezones behind UTC (e.g. Americas), where
the internal calendar timestamp was being interpreted as the previous local day.

Solution: The timestamp coming from the calendar represents a specific calendar
day in UTC. Instead of converting it directly to a JavaScript Date (which shifts
it into local time), we now use the existing CalendarDate abstraction to extract
the correct day and produce a local Date that always matches what the user
selected, regardless of timezone. The conversion is extracted into a shared
calendarTimestampToLocalDate helper in toDates.ts so all affected options use
a single consistent implementation.

A unit test for calendarTimestampToLocalDate is included, validating that the
local date components of the result always match the UTC date of the calendar
timestamp. Note: the test is most meaningful in negative UTC-offset environments;
to verify locally run the calendar selection tests with TZ=America/Los_Angeles.

Fixes: #14005
@unazko
unazko deployed to netlify-preview September 4, 2026 08:26 — with GitHub Actions Active
@unazko
unazko requested a review from didip1000 September 4, 2026 08:27
@unazko
unazko deployed to netlify-preview September 4, 2026 08:27 — with GitHub Actions Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DynamicDateRange]: DATERANGE shifts custom selected dates by one day

2 participants