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:
parent
bf13f0c5ac
commit
0c1e0df5ae
1 changed files with 13 additions and 9 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue