1
0

feat: abstract to useGanttFilter / and useRouteFilter

This commit is contained in:
Dominik Pschenitschni
2022-10-18 14:41:41 +02:00
committed by kolaente
parent 2acb70c562
commit 2c732eb0d5
6 changed files with 154 additions and 126 deletions

View File

@ -0,0 +1,5 @@
export function parseBooleanProp(booleanProp: string) {
return (booleanProp === 'false' || booleanProp === '0')
? false
: Boolean(booleanProp)
}

View File

@ -0,0 +1,30 @@
import type {DateISO} from "@/types/DateISO"
import type {DateKebab} from "@/types/DateKebab"
export function parseDateProp(kebabDate: DateKebab | undefined): string | undefined {
try {
if (!kebabDate) {
throw new Error('No value')
}
const dateValues = kebabDate.split('-')
const [, monthString, dateString] = dateValues
const [year, month, date] = dateValues.map(val => Number(val))
const dateValuesAreValid = (
!Number.isNaN(year) &&
monthString.length >= 1 && monthString.length <= 2 &&
!Number.isNaN(month) &&
month >= 1 && month <= 12 &&
dateString.length >= 1 && dateString.length <= 31 &&
!Number.isNaN(date) &&
date >= 1 && date <= 31
)
if (!dateValuesAreValid) {
throw new Error('Invalid date values')
}
return new Date(year, month, date).toISOString() as DateISO
} catch(e) {
// ignore nonsense route queries
return
}
}