2
0

🐛 Fix date parsing with european format

This commit is contained in:
Baptiste Arnaud
2024-06-10 15:30:05 +02:00
parent 2b420c4e44
commit 209cec34b9
3 changed files with 11 additions and 7 deletions

View File

@ -1,7 +1,7 @@
import { isDefined } from '@typebot.io/lib'
import { ParsedReply } from '../../../types'
import { DateInputBlock } from '@typebot.io/schemas'
import { parse as chronoParse } from 'chrono-node'
import { en as chronoParser } from 'chrono-node'
import { format } from 'date-fns'
import { defaultDateInputOptions } from '@typebot.io/schemas/features/blocks/inputs/date/constants'
@ -9,7 +9,11 @@ export const parseDateReply = (
reply: string,
block: DateInputBlock
): ParsedReply => {
const parsedDate = chronoParse(reply)
const parsedDate = (
block.options?.format ?? defaultDateInputOptions.format
).startsWith('dd')
? chronoParser.GB.parse(reply)
: chronoParser.parse(reply)
if (parsedDate.length === 0) return { status: 'fail' }
const formatString =
block.options?.format ??

View File

@ -21,7 +21,7 @@
"@udecode/plate-common": "30.4.5",
"@typebot.io/logic": "workspace:*",
"ai": "3.1.12",
"chrono-node": "2.7.5",
"chrono-node": "2.7.6",
"date-fns": "2.30.0",
"date-fns-tz": "2.0.0",
"google-auth-library": "8.9.0",

8
pnpm-lock.yaml generated
View File

@ -757,8 +757,8 @@ importers:
specifier: 3.1.12
version: 3.1.12(openai@4.47.1)(react@18.2.0)(solid-js@1.7.8)(svelte@4.2.12)(vue@3.4.21)(zod@3.22.4)
chrono-node:
specifier: 2.7.5
version: 2.7.5
specifier: 2.7.6
version: 2.7.6
date-fns:
specifier: 2.30.0
version: 2.30.0
@ -12079,8 +12079,8 @@ packages:
engines: {node: '>=6.0'}
dev: false
/chrono-node@2.7.5:
resolution: {integrity: sha512-VJWqFN5rWmXVvXAxOD4i0jX8Tb4cLswaslyaAFhxM45zNXPsZleygPbgiaYBD7ORb9fj07zBgJb0Q6eKL+0iJg==}
/chrono-node@2.7.6:
resolution: {integrity: sha512-yugKSRLHc6B6kXxm/DwNc94zhaddAjCSO9IOGH3w7NIWNM+gUoLl/2/XLndiw4I+XhU4H2LOhC5Ab2JjS6JWsA==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dependencies:
dayjs: 1.11.10