From 0c1e0df5ae329ada7779701977458f6873a7c2d2 Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Thu, 8 Jun 2023 23:12:28 +0200 Subject: [PATCH] Do not use toLocaleTimeString to convert ms to hh:mm:ss format The current code didn't seem to work on all locales --- app/qml/mpris.qml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/qml/mpris.qml b/app/qml/mpris.qml index b470abae8..18ca5c42a 100644 --- a/app/qml/mpris.qml +++ b/app/qml/mpris.qml @@ -44,15 +44,19 @@ Kirigami.Page root.pluginInterface.volume = muted ? 0 : volumeUnmuted } - function msToTime(currentTime, totalTime) + function padTimeNumber(n) { + return (n < 10) ? ("0" + n) : n; + } + + function msToTime(totalTimeMs) { - if (totalTime.getHours() >= 2) { - // Skip a day ahead as Date type's minimum is 1am on the 1st of January and can't go lower - currentTime.setDate(2) - currentTime.setHours(currentTime.getHours() - 1) - return currentTime.toLocaleTimeString(Qt.locale(),"hh:mm:ss") + let hours = Math.floor(totalTimeMs/(1000*60*60)); + let minutes = Math.floor((totalTimeMs-(hours*1000*60*60))/(1000*60)); + let seconds = Math.floor((totalTimeMs-(minutes*1000*60)-(hours*1000*60*60))/1000); + if (hours > 0) { + return `${padTimeNumber(hours)}:${padTimeNumber(minutes)}:${padTimeNumber(seconds)}`; } else { - return currentTime.toLocaleTimeString(Qt.locale(),"mm:ss") + return `${padTimeNumber(minutes)}:${padTimeNumber(seconds)}`; } } @@ -123,7 +127,7 @@ Kirigami.Page RowLayout { Layout.fillWidth: true Label { - text: msToTime(new Date(positionIndicator.item.value), new Date(root.pluginInterface.length)) + text: msToTime(positionIndicator.item.value) } MprisSlider { @@ -133,7 +137,7 @@ Kirigami.Page } Label { - text: msToTime(new Date(root.pluginInterface.length), new Date(root.pluginInterface.length)) + text: msToTime(root.pluginInterface.length) } } RowLayout {