diff --git a/projects/kit/src/lib/masks/date-time/utils/parse-date-time-string.ts b/projects/kit/src/lib/masks/date-time/utils/parse-date-time-string.ts index f278c2547..6b34dc4a6 100644 --- a/projects/kit/src/lib/masks/date-time/utils/parse-date-time-string.ts +++ b/projects/kit/src/lib/masks/date-time/utils/parse-date-time-string.ts @@ -10,7 +10,7 @@ export function parseDateTimeString( '', ).length; const [date = ''] = - new RegExp(`(\\d\\D?){0,${dateDigitsCount - 1}}\\d?`).exec(dateTime) || []; + new RegExp(`(\\d[^\\d]*){0,${dateDigitsCount - 1}}\\d?`).exec(dateTime) || []; const [dateTimeSeparator = ''] = LEADING_NON_DIGIT_RE.exec(dateTime.slice(date.length)) || []; diff --git a/projects/kit/src/lib/masks/date-time/utils/tests/parse-date-time-string.spec.ts b/projects/kit/src/lib/masks/date-time/utils/tests/parse-date-time-string.spec.ts index c2407a3fc..683272592 100644 --- a/projects/kit/src/lib/masks/date-time/utils/tests/parse-date-time-string.spec.ts +++ b/projects/kit/src/lib/masks/date-time/utils/tests/parse-date-time-string.spec.ts @@ -1,33 +1,63 @@ import {parseDateTimeString} from '../parse-date-time-string'; describe('parseDateTimeString', () => { - const parse = (value: string): [string, string] => - parseDateTimeString(value, 'dd.mm.yyyy'); + describe('dd.mm.yyyy', () => { + const parse = (value: string): [string, string] => + parseDateTimeString(value, 'dd.mm.yyyy'); - ( - [ - {input: '', output: ['', '']}, - {input: '02', output: ['02', '']}, - {input: '02.', output: ['02.', '']}, - {input: '0211', output: ['0211', '']}, - {input: '0211.', output: ['0211.', '']}, - {input: '02.112018', output: ['02.112018', '']}, - {input: '02.112018,', output: ['02.112018', '']}, - {input: '02.112018, ', output: ['02.112018', '']}, - {input: '02.11.2018, ', output: ['02.11.2018', '']}, - {input: '021120181620', output: ['02112018', '1620']}, - {input: '02112018,1620', output: ['02112018', '1620']}, - {input: '02112018, 1620', output: ['02112018', '1620']}, - {input: '02112018, 16:20', output: ['02112018', '16:20']}, - {input: '02112018,16:20', output: ['02112018', '16:20']}, - {input: '02.11.2018,1620', output: ['02.11.2018', '1620']}, - {input: '02.11.2018, 1620', output: ['02.11.2018', '1620']}, - {input: '02.11.2018, 16:20', output: ['02.11.2018', '16:20']}, - {input: '02.11.2018,16:20', output: ['02.11.2018', '16:20']}, - ] as const - ).forEach(({input, output}) => { - it(`${input} -> ${JSON.stringify(output)}`, () => { - expect(parse(input)).toEqual(output); + ( + [ + {input: '', output: ['', '']}, + {input: '02', output: ['02', '']}, + {input: '02.', output: ['02.', '']}, + {input: '0211', output: ['0211', '']}, + {input: '0211.', output: ['0211.', '']}, + {input: '02.112018', output: ['02.112018', '']}, + {input: '02.112018,', output: ['02.112018', '']}, + {input: '02.112018, ', output: ['02.112018', '']}, + {input: '02.11.2018, ', output: ['02.11.2018', '']}, + {input: '021120181620', output: ['02112018', '1620']}, + {input: '02112018,1620', output: ['02112018', '1620']}, + {input: '02112018, 1620', output: ['02112018', '1620']}, + {input: '02112018, 16:20', output: ['02112018', '16:20']}, + {input: '02112018,16:20', output: ['02112018', '16:20']}, + {input: '02.11.2018,1620', output: ['02.11.2018', '1620']}, + {input: '02.11.2018, 1620', output: ['02.11.2018', '1620']}, + {input: '02.11.2018, 16:20', output: ['02.11.2018', '16:20']}, + {input: '02.11.2018,16:20', output: ['02.11.2018', '16:20']}, + ] as const + ).forEach(({input, output}) => { + it(`${input} -> ${JSON.stringify(output)}`, () => { + expect(parse(input)).toEqual(output); + }); + }); + }); + + describe('dd. mm. yyyy (date segment separator consists of space and dot)', () => { + const parse = (value: string): [string, string] => + parseDateTimeString(value, 'dd. mm. yyyy'); + + ( + [ + {input: '', output: ['', '']}, + {input: '02', output: ['02', '']}, + {input: '02.', output: ['02.', '']}, + {input: '02. ', output: ['02. ', '']}, + {input: '0211', output: ['0211', '']}, + {input: '0211. ', output: ['0211. ', '']}, + {input: '02. 112018', output: ['02. 112018', '']}, + {input: '02. 112018,', output: ['02. 112018', '']}, + {input: '02. 112018, ', output: ['02. 112018', '']}, + {input: '02. 11. 2018, ', output: ['02. 11. 2018', '']}, + {input: '02. 11. 2018,1620', output: ['02. 11. 2018', '1620']}, + {input: '02. 11. 2018, 1620', output: ['02. 11. 2018', '1620']}, + {input: '02. 11. 2018, 16:20', output: ['02. 11. 2018', '16:20']}, + {input: '02. 11. 2018,16:20', output: ['02. 11. 2018', '16:20']}, + ] as const + ).forEach(({input, output}) => { + it(`${input} -> ${JSON.stringify(output)}`, () => { + expect(parse(input)).toEqual(output); + }); }); }); });