From 75c9b116bb7ab8e972dec4719cae56f2bd2f7c9c Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Wed, 23 Mar 2016 18:44:23 -0700 Subject: [PATCH] fix(date-utils): Fix isPastDate using `moment` --- src/date-utils.es6 | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/date-utils.es6 b/src/date-utils.es6 index 993ec5f07..afc492540 100644 --- a/src/date-utils.es6 +++ b/src/date-utils.es6 @@ -38,20 +38,11 @@ function midnight(momentDate, midnightHour = Hours.Midnight) { return oclock(momentDate.hour(midnightHour)) } -function isPastDate({year, month, day}, ref) { - const refDay = ref.getDate(); - const refMonth = ref.getMonth() + 1; - const refYear = ref.getFullYear(); - if (refYear > year) { - return true; - } - if (refMonth > month) { - return true; - } - if (refDay > day) { - return true; - } - return false; +function isPastDate(inputDateObj, currentDate) { + const inputMoment = moment({...inputDateObj, month: inputDateObj.month - 1}) + const currentMoment = moment(currentDate) + + return inputMoment.isBefore(currentMoment) } const EnforceFutureDate = new chrono.Refiner();