From 98d1b26429df12e2385204a19ee6bdf5a6edaef5 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 15 Jan 2021 23:44:08 -0800 Subject: [PATCH] Improve accuracy of date subtraction. --- voussoir.net/eternalseptember/eternalseptember.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/voussoir.net/eternalseptember/eternalseptember.js b/voussoir.net/eternalseptember/eternalseptember.js index c810961..d33c0ca 100644 --- a/voussoir.net/eternalseptember/eternalseptember.js +++ b/voussoir.net/eternalseptember/eternalseptember.js @@ -36,6 +36,15 @@ eternalseptember.MONTH_NAMES = [ "December", ] +eternalseptember.date_subtract = +function date_subtract(now, then) +{ + now = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate()); + then = Date.UTC(then.getFullYear(), then.getMonth(), then.getDate()); + + return Math.floor((now - then) / (1000*60*60*24)); +} + eternalseptember.twelvehour = function twelvehour(hour) { @@ -51,7 +60,7 @@ eternalseptember.strftime = function strftime(date, format) { const diff = date - eternalseptember.EPOCH; - const diff_days = parseInt(diff / (1000*60*60*24)); + const diff_days = eternalseptember.date_subtract(date, eternalseptember.EPOCH); const day_of_month = diff_days + 1 const day_of_year = diff_days + 244