aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <[email protected]>2025-07-01 10:38:54 +0800
committerMitch Curtis <[email protected]>2025-07-04 10:05:42 +0800
commit2e1337d87a60b8d1a30f5296bf3f614ec0bca383 (patch)
treefc876f3345f7c1fc351e5613374b6ef40a81642b
parent703451464bf47afd736991cae0ed16691e6aeb2e (diff)
MonthGrid: address post-merge review feedback on timezone patchHEADdev
Amends 57325020f65665d91e63dc300d674a8e8dc411f1. - Add a comment explaining why we store QQuickMonthGridPrivate::pressedDate as QDateTime now. - Store QDateTimes as local time to simplify things. - Make firstDateToDisplay const while we're here. Task-number: QTBUG-72208 Pick-to: 6.8 6.9 6.10 Change-Id: I9fbee12608855f30d229b4e3a4e78da5561feb44 Reviewed-by: Edward Welbourne <[email protected]>
-rw-r--r--src/quicktemplates/qquickmonthgrid.cpp3
-rw-r--r--src/quicktemplates/qquickmonthmodel.cpp18
2 files changed, 8 insertions, 13 deletions
diff --git a/src/quicktemplates/qquickmonthgrid.cpp b/src/quicktemplates/qquickmonthgrid.cpp
index 1fc81b514f..797260d855 100644
--- a/src/quicktemplates/qquickmonthgrid.cpp
+++ b/src/quicktemplates/qquickmonthgrid.cpp
@@ -95,6 +95,9 @@ public:
QString title;
QVariant source;
+
+ // Only the date matters, but we have to store it as QDateTime for compatibility
+ // with Date: QTBUG-72208. See QQuickMonthModelPrivate::populate for more info.
QDateTime pressedDate;
int pressTimer;
QQuickItem *pressedItem;
diff --git a/src/quicktemplates/qquickmonthmodel.cpp b/src/quicktemplates/qquickmonthmodel.cpp
index 0cbdb448e1..a3cbda990b 100644
--- a/src/quicktemplates/qquickmonthmodel.cpp
+++ b/src/quicktemplates/qquickmonthmodel.cpp
@@ -50,19 +50,15 @@ bool QQuickMonthModelPrivate::populate(int m, int y, const QLocale &l, bool forc
// QDate is converted to local time when converted to a JavaScript Date,
// so if we stored our dates as QDates, it's possible that the date provided
// to delegates will be wrong in certain timezones:
- // e.g. 00:00 UTC converted to UTC-8 is 20:00 the day before.
- // To account for this, we pick a time of day that can't possibly result
- // in a different day when converted to local time.
- QDateTime firstDayOfMonthDateTime(firstDayOfMonthDate, QTime(0, 0), QTimeZone(QTimeZone::UTC));
- const int localTimeOffsetFromUtc = QDateTime(firstDayOfMonthDate, QTime(0, 0), QTimeZone(QTimeZone::LocalTime)).offsetFromUtc();
- const int timeOffsetAdjustment = localTimeOffsetFromUtc * -1;
- firstDayOfMonthDateTime.setSecsSinceEpoch(firstDayOfMonthDateTime.toSecsSinceEpoch() + timeOffsetAdjustment);
+ // e.g. 00:00 UTC converted to UTC-8 is 16:00 the day before.
+ // To account for this, we store our dates as local QDateTimes.
+ const QDateTime firstDayOfMonthDateTime = firstDayOfMonthDate.startOfDay();
int difference = ((firstDayOfMonthDate.dayOfWeek() - l.firstDayOfWeek()) + 7) % 7;
// The first day to display should never be the 1st of the month, as we want some days from
// the previous month to be visible.
if (difference == 0)
difference += 7;
- QDateTime firstDateToDisplay = firstDayOfMonthDateTime.addDays(-difference);
+ const QDateTime firstDateToDisplay = firstDayOfMonthDateTime.addDays(-difference);
today = QDate::currentDate();
for (int i = 0; i < daysOnACalendarMonth; ++i)
@@ -71,11 +67,7 @@ bool QQuickMonthModelPrivate::populate(int m, int y, const QLocale &l, bool forc
q->setTitle(l.standaloneMonthName(m) + QStringLiteral(" ") + QString::number(y));
qCDebug(lcMonthModel) << "populated model for month" << m << "year" << y << "locale" << locale
- << "initial firstDayOfMonthDateTime" << QDateTime(firstDayOfMonthDate, QTime(0, 0), QTimeZone(QTimeZone::UTC))
- << "localTimeOffsetFromUtc" << localTimeOffsetFromUtc / 60 / 60
- << "timeOffsetAdjustment" << timeOffsetAdjustment / 60 / 60
- << "firstDayOfMonthDateTime" << firstDayOfMonthDateTime
- << "firstDayOfMonthDateTime.toLocalTime()" << firstDayOfMonthDateTime.toLocalTime();
+ << "firstDayOfMonthDateTime" << firstDayOfMonthDateTime;
return true;
}