Skip to content

Commit d1c51ac

Browse files
committed
Merge #249: Proper formatting of BlockClock's remaining sync time
542e4d4 qml: proper formatting of BlockClock remaining sync time (Jarol Rodriguez) Pull request description: Applies proper formatting to the value obtained from `nodeModel.remainingSyncTime`, as specified in our [design docs](https://bitcoincore.app/block-clock/). Displays the largest unit of time left until we get to less than 5 hours left, in which case it will shows both hours and minutes. When it reaches minutes, it only shows minutes until there is less than 5 minutes, which then it will display both minutes and seconds. This works for now, but we'll probably want a different approach so that the units and the word "left" can be translated. | weeks | days | hours | h & m | minutes | m & s | seconds | | ----- | ---- | ----- | ----- | ------- | ----- | ------- | | <img width="217" alt="Screen Shot 2023-02-05 at 9 21 37 PM" src="https://user-images.githubusercontent.com/23396902/216868784-54679ec6-9be2-40c0-8e3b-8b339b724fb0.png"> | <img width="217" alt="Screen Shot 2023-02-05 at 9 17 29 PM" src="https://user-images.githubusercontent.com/23396902/216868832-db71f629-8089-4b28-8a95-31b67df993ea.png"> | <img width="217" alt="Screen Shot 2023-02-05 at 9 17 33 PM" src="https://user-images.githubusercontent.com/23396902/216868895-3b4ad2e1-6ea5-4f9d-beb5-dd2d588ac8fd.png"> | <img width="217" alt="Screen Shot 2023-02-05 at 9 14 21 PM" src="https://user-images.githubusercontent.com/23396902/216868971-e37d2b87-faee-4d71-bbb1-c9782fb70336.png"> | <img width="217" alt="Screen Shot 2023-02-05 at 9 14 26 PM" src="https://user-images.githubusercontent.com/23396902/216869000-70909261-380a-4b2c-950b-9e1998358569.png"> | <img width="217" alt="Screen Shot 2023-02-05 at 9 15 10 PM" src="https://user-images.githubusercontent.com/23396902/216869019-4a7f8e46-629c-469d-8720-a477114fec89.png"> | <img width="217" alt="Screen Shot 2023-02-05 at 9 16 11 PM" src="https://user-images.githubusercontent.com/23396902/216869057-3c91e834-4df6-4fc9-b07c-4837f0d5dbf1.png"> | Fixes #225 [![Windows](https://img.shields.io/badge/OS-Windows-green)](https://api.cirrus-ci.com/v1/artifact/github/bitcoin-core/gui-qml/win64/insecure_win_gui.zip?branch=pull/249) [![Intel macOS](https://img.shields.io/badge/OS-Intel%20macOS-green)](https://api.cirrus-ci.com/v1/artifact/github/bitcoin-core/gui-qml/macos/insecure_mac_gui.zip?branch=pull/249) [![Apple Silicon macOS](https://img.shields.io/badge/OS-Apple%20Silicon%20macOS-green)](https://api.cirrus-ci.com/v1/artifact/github/bitcoin-core/gui-qml/macos_arm64/insecure_mac_arm64_gui.zip?branch=pull/249) [![ARM64 Android](https://img.shields.io/badge/OS-Android-green)](https://api.cirrus-ci.com/v1/artifact/github/bitcoin-core/gui-qml/android/insecure_android_apk.zip?branch=pull/249) ACKs for top commit: johnny9: ACK 542e4d4 Tree-SHA512: 1af1f88ef8c024405bf3edfc2f0f085cc5c285b3f1d3b8e95284e0298b50e6084553390c5e374e92c5dd9f056f2a073e31ec076d860e156e33a095c3cc62b7ad
2 parents 4ca3b72 + 542e4d4 commit d1c51ac

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)