1
0

fix: gantt route sync

This commit is contained in:
Dominik Pschenitschni
2022-11-09 18:33:06 +01:00
parent 13bd434cb9
commit 7ec2b6c0d2
5 changed files with 53 additions and 21 deletions

View File

@ -1,8 +1,16 @@
import {format} from 'date-fns'
import {DATEFNS_DATE_FORMAT_KEBAB} from '@/constants/date'
import type {DateISO} from '@/types/DateISO'
import type {DateKebab} from '@/types/DateKebab'
// ✅ Format a date to YYYY-MM-DD (or any other format)
function padTo2Digits(num: number) {
return num.toString().padStart(2, '0')
}
export function isoToKebabDate(isoDate: DateISO) {
return format(new Date(isoDate), DATEFNS_DATE_FORMAT_KEBAB) as DateKebab
const date = new Date(isoDate)
return [
date.getFullYear(),
padTo2Digits(date.getMonth() + 1), // January is 0, but we want it to be 1
padTo2Digits(date.getDate()),
].join('-') as DateKebab
}

View File

@ -22,7 +22,7 @@ export function parseDateProp(kebabDate: DateKebab | undefined): string | undefi
if (!dateValuesAreValid) {
throw new Error('Invalid date values')
}
return new Date(year, month, date).toISOString() as DateISO
return new Date(year, month - 1, date).toISOString() as DateISO
} catch(e) {
// ignore nonsense route queries
return