From 2029a90c2e60f3ac8958eff5016c3734ae5cf10e Mon Sep 17 00:00:00 2001 From: Andrey Belokopytov Date: Fri, 1 Nov 2024 00:41:47 +0300 Subject: [PATCH] fix(kit): fix normalization --- .../lib/processors/normalize-date-preprocessor.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/projects/kit/src/lib/processors/normalize-date-preprocessor.ts b/projects/kit/src/lib/processors/normalize-date-preprocessor.ts index d123b7a9a..d67c9c5e9 100644 --- a/projects/kit/src/lib/processors/normalize-date-preprocessor.ts +++ b/projects/kit/src/lib/processors/normalize-date-preprocessor.ts @@ -15,12 +15,10 @@ export function normalizeDatePreprocessor({ }): MaskitoPreprocessor { return ({elementState, data}) => { const dateSegments = data.split(/\D/).filter(Boolean); - const templateSegments = dateModeTemplate - .split(dateSegmentsSeparator) - .filter(Boolean); + const templateSegments = dateModeTemplate.split(dateSegmentsSeparator); const includesTime = data.includes(dateTimeSeparator); - let newData = ''; + let newData = data; const dates: string[] = []; let dateParts: string[] = []; const timeParts: string[] = []; @@ -28,8 +26,7 @@ export function normalizeDatePreprocessor({ for (let index = 0; index < dateSegments.length; index++) { const segment = dateSegments[index]!; const template = templateSegments[index % templateSegments.length]; - const isLastSegment = index === dateSegments.length - 1; - const isLastFromTemplate = + const isLastTemplateSegment = index % templateSegments.length === templateSegments.length - 1; if (index >= templateSegments.length && includesTime) { @@ -37,8 +34,8 @@ export function normalizeDatePreprocessor({ continue; } - if (template) { - if (isLastFromTemplate || isLastSegment) { + if (template && template.length === segment.length) { + if (isLastTemplateSegment) { dateParts.push(segment); dates.push(dateParts.join(dateSegmentsSeparator)); dateParts = []; @@ -50,7 +47,7 @@ export function normalizeDatePreprocessor({ if (dates.length === 1 && timeParts.length > 0) { newData = `${dates[0]}${dateTimeSeparator}${timeParts.join(':')}`; - } else { + } else if (dates.length === 2) { newData = dates.join(rangeSeparator); }