From 9f40645d8af708b9203cb56f02dcebe4ca8c8535 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Tue, 27 Aug 2024 17:35:18 +1000 Subject: [PATCH] Refactor age pretty printing --- src/bilirubin_lib.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/bilirubin_lib.js b/src/bilirubin_lib.js index b407adb..f29d6b2 100644 --- a/src/bilirubin_lib.js +++ b/src/bilirubin_lib.js @@ -79,14 +79,24 @@ function exchange_thresh(d, gestation) { // -------------- // Utility functions +function prettyPrintHours(d) { + if (d < 0.5/24) { + return '0 hours'; + } + if (d < 1.5/24) { + return '1 hour'; + } + return (d * 24).toFixed(0) + ' hours'; +} + function prettyPrintDays(d) { if (d < 1) { - return (d * 24).toFixed(0) + ' hours'; + return prettyPrintHours(d); } if (d < 2) { - return '1 day, ' + ((d % 1) * 24).toFixed(0) + ' hours'; + return '1 day, ' + prettyPrintHours(d % 1); } - return Math.floor(d) + ' days, ' + ((d % 1) * 24).toFixed(0) + ' hours'; + return Math.floor(d) + ' days, ' + prettyPrintHours(d % 1); } function prettyPrintBilirubin(b) {