mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 06:57:12 +01:00
date format
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
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 = [dateFormat(currentDay)]
|
||||
const days = [dateFormatBackend(currentDay)]
|
||||
|
||||
if (!endDate) {
|
||||
return days
|
||||
@@ -11,15 +14,36 @@ export function getDays({ startDate, endDate }) {
|
||||
const end = moment(endDate)
|
||||
while (currentDay < end) {
|
||||
currentDay = currentDay.add(1, 'day')
|
||||
days.push(dateFormat(currentDay))
|
||||
days.push(dateFormatBackend(currentDay))
|
||||
}
|
||||
|
||||
return days
|
||||
}
|
||||
|
||||
export function dateFormat(date) {
|
||||
function dateFormat(date, format) {
|
||||
if (!date) {
|
||||
return null
|
||||
}
|
||||
return moment(date).format('YYYY-MM-DD')
|
||||
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, 'MM-DD-YYYY')
|
||||
if (date.isValid()) {
|
||||
return date.getDate()
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function dateParseFrontend(string) {
|
||||
return dateParse(string, FRONTEND_FORMAT)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user