Commit ab86bd37 authored by David Edmundson's avatar David Edmundson Committed by Nate Graham
Browse files

applets/digital-clock: Fix date drift

dateTimeChanged is called every second. This in turn checks if the date
has changed. If so we call setupLabels which updates the clock.

The date label used to use main.currentTime which is a value set in the
binding of the timeLabel's text property. The order of this being
updated vs running this code is undefined.

Bug 1: We compare an ever so slightly different date source to the one
used in the date text label.

Bug 2: We are not necessarily updating the date label with the most
updated time.

Overall we can't mix declarative and imperative design patterns. This
patch commits to being imperative and introduces a function to get the
current time so that the date label and time label will always get the
most up to date value even if they update from different trigers.

BUG: 452554
FIXED-IN: 5.24.5
(cherry picked from commit 5430c3a0)
parent 757b5e8c
Pipeline #166532 passed with stage
in 7 minutes and 42 seconds
......@@ -17,7 +17,6 @@ Item {
id: main
property string timeFormat
property date currentTime
property bool showSeconds: plasmoid.configuration.showSeconds
property bool showLocalTimezone: plasmoid.configuration.showLocalTimezone
......@@ -78,7 +77,7 @@ Item {
target: plasmoid
function onContextualActionsAboutToShow() {
ClipboardMenu.secondsIncluded = main.showSeconds;
ClipboardMenu.currentDate = main.currentTime;
ClipboardMenu.currentDate = main.getCurrentTime();
}
}
......@@ -97,6 +96,16 @@ Item {
}
}
function getCurrentTime() {
// get the time for the given timezone from the dataengine
var now = dataSource.data[plasmoid.configuration.lastSelectedTimezone]["DateTime"];
// get current UTC time
var msUTC = now.getTime() + (now.getTimezoneOffset() * 60000);
// add the dataengine TZ offset to it
var currentTime = new Date(msUTC + (dataSource.data[plasmoid.configuration.lastSelectedTimezone]["Offset"] * 1000));
return currentTime;
}
states: [
State {
name: "horizontalPanel"
......@@ -496,17 +505,7 @@ Item {
}
minimumPixelSize: 1
text: {
// get the time for the given timezone from the dataengine
var now = dataSource.data[plasmoid.configuration.lastSelectedTimezone]["DateTime"];
// get current UTC time
var msUTC = now.getTime() + (now.getTimezoneOffset() * 60000);
// add the dataengine TZ offset to it
var currentTime = new Date(msUTC + (dataSource.data[plasmoid.configuration.lastSelectedTimezone]["Offset"] * 1000));
main.currentTime = currentTime;
return Qt.formatTime(currentTime, main.timeFormat);
}
text: Qt.formatTime(main.getCurrentTime(), main.timeFormat)
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
......@@ -633,7 +632,7 @@ Item {
if (main.showDate) {
dateLabel.text = Qt.formatDate(main.currentTime, main.dateFormat);
dateLabel.text = Qt.formatDate(main.getCurrentTime(), main.dateFormat);
} else {
// clear it so it doesn't take space in the layout
dateLabel.text = "";
......@@ -673,7 +672,7 @@ Item {
if (main.showDate) {
// If the date has changed, force size recalculation, because the day name
// or the month name can now be longer/shorter, so we need to adjust applet size
const currentDate = Qt.formatDateTime(dataSource.data["Local"]["DateTime"], "yyyy-MM-dd");
const currentDate = Qt.formatDateTime(main.getCurrentTime(), "yyyy-MM-dd");
if (main.lastDate !== currentDate) {
doCorrections = true;
main.lastDate = currentDate
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment