From 93eb6da68defc06089bf1dc01f2f241b955aa9bc Mon Sep 17 00:00:00 2001 From: James Collins Date: Fri, 24 Feb 2023 22:18:07 +1000 Subject: [PATCH] bugfixes with isBefore and isAfter --- resources/js/helpers/datetime.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/resources/js/helpers/datetime.ts b/resources/js/helpers/datetime.ts index 8998285..97b2d81 100644 --- a/resources/js/helpers/datetime.ts +++ b/resources/js/helpers/datetime.ts @@ -379,13 +379,17 @@ export class SMDate { * @param {Date|SMDate} d (optional) The date to check. If none, use now * @returns {boolean} If the date is before the passed date. */ - public isBefore(d: Date | SMDate = new Date()): boolean { + public isBefore(d: Date | SMDate = new SMDate("now")): boolean { const otherDate = d instanceof SMDate ? d.date : d; if (otherDate == null) { return false; } - return otherDate < otherDate; + if (this.date == null) { + return true; + } + + return otherDate > this.date; } /** @@ -394,13 +398,17 @@ export class SMDate { * @param {Date|SMDate} d (optional) The date to check. If none, use now * @returns {boolean} If the date is after the passed date. */ - public isAfter(d: Date | SMDate = new Date()): boolean { + public isAfter(d: Date | SMDate = new SMDate("now")): boolean { const otherDate = d instanceof SMDate ? d.date : d; if (otherDate == null) { return false; } - return otherDate > otherDate; + if (this.date == null) { + return true; + } + + return otherDate < this.date; } /**