Do not use toLocaleTimeString to convert ms to hh:mm:ss format

The current code didn't seem to work on all locales
This commit is contained in:
Albert Vaca Cintora 2023-06-08 23:12:28 +02:00
parent bf13f0c5ac
commit 0c1e0df5ae

View file

@ -44,15 +44,19 @@ Kirigami.Page
root.pluginInterface.volume = muted ? 0 : volumeUnmuted 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) { let hours = Math.floor(totalTimeMs/(1000*60*60));
// Skip a day ahead as Date type's minimum is 1am on the 1st of January and can't go lower let minutes = Math.floor((totalTimeMs-(hours*1000*60*60))/(1000*60));
currentTime.setDate(2) let seconds = Math.floor((totalTimeMs-(minutes*1000*60)-(hours*1000*60*60))/1000);
currentTime.setHours(currentTime.getHours() - 1) if (hours > 0) {
return currentTime.toLocaleTimeString(Qt.locale(),"hh:mm:ss") return `${padTimeNumber(hours)}:${padTimeNumber(minutes)}:${padTimeNumber(seconds)}`;
} else { } else {
return currentTime.toLocaleTimeString(Qt.locale(),"mm:ss") return `${padTimeNumber(minutes)}:${padTimeNumber(seconds)}`;
} }
} }
@ -123,7 +127,7 @@ Kirigami.Page
RowLayout { RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
Label { Label {
text: msToTime(new Date(positionIndicator.item.value), new Date(root.pluginInterface.length)) text: msToTime(positionIndicator.item.value)
} }
MprisSlider { MprisSlider {
@ -133,7 +137,7 @@ Kirigami.Page
} }
Label { Label {
text: msToTime(new Date(root.pluginInterface.length), new Date(root.pluginInterface.length)) text: msToTime(root.pluginInterface.length)
} }
} }
RowLayout { RowLayout {