import moment from 'moment' const FRONTEND_FORMAT = 'DD.MM.YYYY' const BACKEND_FORMAT = 'YYYY-MM-DD' export function getDays({ startDate, endDate }) { let currentDay = moment(startDate) const days = [dateFormatBackend(currentDay)] if (!endDate) { return days } const end = moment(endDate) while (currentDay < end) { currentDay = currentDay.add(1, 'day') days.push(dateFormatBackend(currentDay)) } return days } function dateFormat(date, format) { if (!date) { return null } return moment(date).format(format) } export function dateFormatBackend(date) { return dateFormat(date, BACKEND_FORMAT) } export function dateFormatFrontend(date) { return dateFormat(date, FRONTEND_FORMAT) } function dateParse(string, format) { const date = moment(string, format) if (date.isValid()) { // @ts-expect-error ts-migrate(2339) FIXME: Property 'getDate' does not exist on type 'Moment'... Remove this comment to see the full error message return date.getDate() } return null } export function dateParseFrontend(string) { return dateParse(string, FRONTEND_FORMAT) }