Round 23.5 hours+ to the next day when pretty printing

This commit is contained in:
RunasSudo 2024-08-27 17:36:00 +10:00
parent 9f40645d8a
commit 8b39e849b1
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -80,6 +80,10 @@ function exchange_thresh(d, gestation) {
// Utility functions // Utility functions
function prettyPrintHours(d) { function prettyPrintHours(d) {
if (d >= 23.5/24) {
throw new Error('>24 hours passed to prettyPrintHours');
}
if (d < 0.5/24) { if (d < 0.5/24) {
return '0 hours'; return '0 hours';
} }
@ -90,13 +94,16 @@ function prettyPrintHours(d) {
} }
function prettyPrintDays(d) { function prettyPrintDays(d) {
if (d < 1) { if (d < 23.5/24) {
return prettyPrintHours(d); return prettyPrintHours(d);
} }
if (d < 2) { if (d < 1 + 23.5/24) {
return '1 day, ' + prettyPrintHours(d % 1); return '1 day, ' + prettyPrintHours(d % 1);
} }
return Math.floor(d) + ' days, ' + prettyPrintHours(d % 1);
let d_rounded = Math.round(d * 24) / 24; // Round 23.5 hours+ to the next day
return Math.floor(d_rounded) + ' days, ' + prettyPrintHours(d_rounded % 1);
} }
function prettyPrintBilirubin(b) { function prettyPrintBilirubin(b) {