feat: abstract to useGanttFilter / and useRouteFilter
This commit is contained in:

committed by
kolaente

parent
2acb70c562
commit
2c732eb0d5
5
src/helpers/time/parseBooleanProp.ts
Normal file
5
src/helpers/time/parseBooleanProp.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export function parseBooleanProp(booleanProp: string) {
|
||||
return (booleanProp === 'false' || booleanProp === '0')
|
||||
? false
|
||||
: Boolean(booleanProp)
|
||||
}
|
30
src/helpers/time/parseDateProp.ts
Normal file
30
src/helpers/time/parseDateProp.ts
Normal 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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user