From 1ffee231ec1626ef0bb3d9bb88144468bd52138f Mon Sep 17 00:00:00 2001 From: "salvatore.gravina" Date: Wed, 7 Aug 2024 12:31:23 +0200 Subject: [PATCH] fix(fe-piattaforma): fix validazione data servizio massimo 20240807 --- fe-piattaforma/src/utils/csvUtils.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fe-piattaforma/src/utils/csvUtils.ts b/fe-piattaforma/src/utils/csvUtils.ts index 14ba56f59..d876a3afa 100644 --- a/fe-piattaforma/src/utils/csvUtils.ts +++ b/fe-piattaforma/src/utils/csvUtils.ts @@ -140,7 +140,7 @@ export const validateFields = ( } if (record.SE1) { const parsedDate = new Date(record.SE1); - if(!isValidDateFormat(record.SE1)){ + if(!isValidDateFormat(record.SE1) || !isValidDate(record.SE1)){ //valido tramite regex errors.push("La data inserita per il servizio non e' valida."); } else if (parsedDate > maxDate) { errors.push("La data del servizio e' successiva al 31 Luglio 2024."); @@ -178,6 +178,11 @@ function isValidDateFormat(dateString : string) { return regex.test(dateString); } +function isValidDate(dateString : string) { + let parsedDate = moment(dateString); + return parsedDate.isValid() +} + export function containsOnlyNumber(value: string): boolean { return value >= '0' && value <= '9'; }