Skip to content

Commit

Permalink
fix(kit): fix normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Belokopytov committed Oct 31, 2024
1 parent e3b42ac commit 2029a90
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions projects/kit/src/lib/processors/normalize-date-preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,27 @@ 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[] = [];

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) {
timeParts.push(segment);
continue;
}

if (template) {
if (isLastFromTemplate || isLastSegment) {
if (template && template.length === segment.length) {
if (isLastTemplateSegment) {
dateParts.push(segment);
dates.push(dateParts.join(dateSegmentsSeparator));
dateParts = [];
Expand All @@ -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);
}

Expand Down

0 comments on commit 2029a90

Please sign in to comment.