From 209cec34b961a794c0c906da01604bf75910355d Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Mon, 10 Jun 2024 15:30:05 +0200 Subject: [PATCH] :bug: Fix date parsing with european format --- packages/bot-engine/blocks/inputs/date/parseDateReply.ts | 8 ++++++-- packages/bot-engine/package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/bot-engine/blocks/inputs/date/parseDateReply.ts b/packages/bot-engine/blocks/inputs/date/parseDateReply.ts index dbf0e8c839..09adeeca4c 100644 --- a/packages/bot-engine/blocks/inputs/date/parseDateReply.ts +++ b/packages/bot-engine/blocks/inputs/date/parseDateReply.ts @@ -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 ?? diff --git a/packages/bot-engine/package.json b/packages/bot-engine/package.json index 5136c0ae68..df6ff4b5ee 100644 --- a/packages/bot-engine/package.json +++ b/packages/bot-engine/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8ef3495321..8e46fee094 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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