Skip to content

Commit 542e4d4

Browse files
committed
qml: proper formatting of BlockClock remaining sync time
1 parent 4ca3b72 commit 542e4d4

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/qml/components/BlockClock.qml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Item {
9797
PropertyChanges {
9898
target: root
9999
header: Math.round(nodeModel.verificationProgress * 100) + "%"
100-
subText: Math.round(nodeModel.remainingSyncTime/60000) > 0 ? Math.round(nodeModel.remainingSyncTime/60000) + "mins" : Math.round(nodeModel.remainingSyncTime/1000) + "secs"
100+
subText: formatRemainingSyncTime(nodeModel.remainingSyncTime)
101101
}
102102
},
103103

@@ -146,4 +146,39 @@ Item {
146146
}
147147
}
148148
]
149+
150+
function formatRemainingSyncTime(milliseconds) {
151+
var minutes = Math.floor(milliseconds / 60000);
152+
var seconds = Math.floor((milliseconds % 60000) / 1000);
153+
var weeks = Math.floor(minutes / 10080);
154+
minutes %= 10080;
155+
var days = Math.floor(minutes / 1440);
156+
minutes %= 1440;
157+
var hours = Math.floor(minutes / 60);
158+
minutes %= 60;
159+
160+
if (weeks > 0) {
161+
return "~" + weeks + (weeks === 1 ? " week" : " weeks") + " left";
162+
}
163+
if (days > 0) {
164+
return "~" + days + (days === 1 ? " day" : " days") + " left";
165+
}
166+
if (hours >= 5) {
167+
return "~" + hours + (hours === 1 ? " hour" : " hours") + " left";
168+
}
169+
if (hours > 0) {
170+
return "~" + hours + "h " + minutes + "m" + " left";
171+
}
172+
if (minutes >= 5) {
173+
return "~" + minutes + (minutes === 1 ? " minute" : " minutes") + " left";
174+
}
175+
if (minutes > 0) {
176+
return "~" + minutes + "m " + seconds + "s" + " left";
177+
}
178+
if (seconds > 0) {
179+
return "~" + seconds + (seconds === 1 ? " second" : " seconds") + " left";
180+
}
181+
182+
return "~0 seconds left";
183+
}
149184
}

0 commit comments

Comments
 (0)