Skip to content

Commit

Permalink
🐛 Fix date parsing with european format
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jun 10, 2024
1 parent 2b420c4 commit 209cec3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions packages/bot-engine/blocks/inputs/date/parseDateReply.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
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'

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 ??
Expand Down
2 changes: 1 addition & 1 deletion packages/bot-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 209cec3

Please sign in to comment.