From a26e58b43e944f246f9dd29073824e9dc8368f98 Mon Sep 17 00:00:00 2001 From: Thomas Ruoff Date: Wed, 29 Jul 2020 00:00:42 +0200 Subject: [PATCH] add dateFormat helper --- lib/dateHelper.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/dateHelper.js b/lib/dateHelper.js index f4fcf2d..e62ccd9 100644 --- a/lib/dateHelper.js +++ b/lib/dateHelper.js @@ -2,7 +2,7 @@ import moment from 'moment' export function getDays({ startDate, endDate }) { let currentDay = moment(startDate) - const days = [currentDay.format('YYYY-MM-DD')] + const days = [dateFormat(currentDay)] if (!endDate) { return days @@ -11,8 +11,15 @@ export function getDays({ startDate, endDate }) { const end = moment(endDate) while (currentDay < end) { currentDay = currentDay.add(1, 'day') - days.push(currentDay.format('YYYY-MM-DD')) + days.push(dateFormat(currentDay)) } return days } + +export function dateFormat(date) { + if (!date) { + return null + } + return moment(date).format('YYYY-MM-DD') +}