From: Claudio Cambra Date: Mon, 3 Oct 2022 08:47:27 +0000 (+0200) Subject: Fix default date parser handling of timezones X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~11^2~169^2~9 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=79c0f3464a28159bddcb783722a01663c31a3bc5;p=nextcloud-desktop.git Fix default date parser handling of timezones Signed-off-by: Claudio Cambra --- diff --git a/src/gui/filedetails/ShareDelegate.qml b/src/gui/filedetails/ShareDelegate.qml index a7632f712..7b8626e7b 100644 --- a/src/gui/filedetails/ShareDelegate.qml +++ b/src/gui/filedetails/ShareDelegate.qml @@ -599,7 +599,10 @@ GridLayout { // https://invent.kde.org/pim/kalendar/-/blob/release/22.08/src/contents/ui/KalendarUtils/dateutils.js function parseDateString(dateString) { function defaultParse() { - return Date.fromLocaleDateString(Qt.locale(), dateString, Locale.NarrowFormat); + const defaultParsedDate = Date.fromLocaleDateString(Qt.locale(), dateString, Locale.NarrowFormat); + // JS always generates date in system locale, eliminate timezone difference to UTC + const msecsSinceEpoch = defaultParsedDate.getTime() - (defaultParsedDate.getTimezoneOffset() * 60 * 1000); + return new Date(msecsSinceEpoch); } const dateStringDelimiterMatches = dateString.match(/\D/); @@ -626,6 +629,7 @@ GridLayout { if(splitDateString.length === 0 || splitDateString.length > 3 || userProvidedYear.length >= stringifiedCurrentYear.length) { + return defaultParse(); } @@ -640,6 +644,8 @@ GridLayout { const monthIndexNum = Number(splitDateString[localisedDateMonthPosition]) - 1; const dayNum = Number(splitDateString[localisedDateDayPosition]); + console.log(dayNum, monthIndexNum, fixedYearNum); + // Modification: return date in UTC return new Date(Date.UTC(fixedYearNum, monthIndexNum, dayNum)); } @@ -647,6 +653,7 @@ GridLayout { Layout.fillWidth: true height: visible ? implicitHeight : 0 + // We want all the internal benefits of the spinbox but don't actually want the // buttons, so set an empty item as a dummy up.indicator: Item {} @@ -680,6 +687,10 @@ GridLayout { !root.waitingForExpireDateEnabledChange onValueModified: { + if (!enabled || !activeFocus) { + return; + } + root.setExpireDate(value * dayInMSecs); root.waitingForExpireDateChange = true; }