components/calendar: fix today-highlight showing wrong day for UTC+x timezones before UTC midnight

Original commit message(s)

  • components/calendar: fix today-highlight showing wrong day for UTC+x timezones before UTC midnight

Calendar::setToday() calls .date() on a QDateTime with Qt::UTC timeSpec, which returns the UTC date. This gives the wrong date when the system timezone is ahead of UTC and local time is before UTC midnight, because the local date has already advanced past the UTC date (e.g. UTC+6 at 04:00 local is still 22:00 UTC the previous day).

The incoming QDateTime originates from Clock::jsDateTime() which retains Qt::UTC timeSpec. Replace dateTime.date() with dateTime.toLocalTime().date() so the stored date matches the system local timezone, consistent with what JS Date.getDate() returns for the same value.

Apply the same fix to setDisplayedDate(const QDateTime &) so it also handles QDateTime values with Qt::UTC timeSpec correctly.

Reason for the change

Test plan

Pass the newly added test

Screenshots or screen recordings

Bugs fixed

BUG: 521114

Assisted-by: Kilo Code: deepseek-v4-pro

Edited by Fushan Wen

Merge request reports

Loading