From 8b39e849b1d22d1a69a0b36670104ec34162b291 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Tue, 27 Aug 2024 17:36:00 +1000 Subject: [PATCH] Round 23.5 hours+ to the next day when pretty printing --- src/bilirubin_lib.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/bilirubin_lib.js b/src/bilirubin_lib.js index f29d6b2..c55c260 100644 --- a/src/bilirubin_lib.js +++ b/src/bilirubin_lib.js @@ -80,6 +80,10 @@ function exchange_thresh(d, gestation) { // Utility functions function prettyPrintHours(d) { + if (d >= 23.5/24) { + throw new Error('>24 hours passed to prettyPrintHours'); + } + if (d < 0.5/24) { return '0 hours'; } @@ -90,13 +94,16 @@ function prettyPrintHours(d) { } function prettyPrintDays(d) { - if (d < 1) { + if (d < 23.5/24) { return prettyPrintHours(d); } - if (d < 2) { + if (d < 1 + 23.5/24) { 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) {