mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
replace momentjs (incl. calendar)
This commit is contained in:
committed by
Thomas Ruoff
parent
7f4604f0e6
commit
02c2b45747
@@ -1,50 +1,49 @@
|
||||
import moment from 'moment'
|
||||
import { parse, format, addDays } from 'date-fns'
|
||||
|
||||
const FRONTEND_FORMAT = 'DD.MM.YYYY'
|
||||
const BACKEND_FORMAT = 'YYYY-MM-DD'
|
||||
const FRONTEND_FORMAT = 'dd.MM.yyyy'
|
||||
const BACKEND_FORMAT = 'yyyy-MM-dd'
|
||||
|
||||
export function getDays({
|
||||
startDate,
|
||||
endDate,
|
||||
}: {
|
||||
startDate: moment.MomentInput
|
||||
endDate: moment.MomentInput
|
||||
startDate: Date
|
||||
endDate: Date
|
||||
}) {
|
||||
let currentDay = moment(startDate)
|
||||
let currentDay = new Date(startDate.getTime())
|
||||
const days = [dateFormatBackend(currentDay)]
|
||||
|
||||
if (!endDate) {
|
||||
return days
|
||||
}
|
||||
|
||||
const end = moment(endDate)
|
||||
while (currentDay < end) {
|
||||
currentDay = currentDay.add(1, 'day')
|
||||
while (currentDay < endDate) {
|
||||
currentDay = addDays(currentDay, 1)
|
||||
days.push(dateFormatBackend(currentDay))
|
||||
}
|
||||
|
||||
return days
|
||||
}
|
||||
|
||||
function dateFormat(date: moment.MomentInput, format: string) {
|
||||
function dateFormat(date: Date, formatString: string) {
|
||||
if (!date) {
|
||||
return null
|
||||
}
|
||||
return moment(date).format(format)
|
||||
return format(date, formatString)
|
||||
}
|
||||
|
||||
export function dateFormatBackend(date: moment.MomentInput) {
|
||||
export function dateFormatBackend(date: Date) {
|
||||
return dateFormat(date, BACKEND_FORMAT)
|
||||
}
|
||||
|
||||
export function dateFormatFrontend(date: moment.MomentInput) {
|
||||
export function dateFormatFrontend(date: Date) {
|
||||
return dateFormat(date, FRONTEND_FORMAT)
|
||||
}
|
||||
|
||||
function dateParse(input: string, format: string) {
|
||||
const date = moment(input, format)
|
||||
if (date.isValid()) {
|
||||
return date.toDate()
|
||||
function dateParse(input: string, formatString: string) {
|
||||
const date = parse(input, formatString, new Date())
|
||||
if (date.getTime() !== NaN) {
|
||||
return date
|
||||
}
|
||||
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user