generated from Tinkoff/angular-open-source-starter
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fix case for multi-character date segment separator
- Loading branch information
1 parent
e7a63ea
commit 786fb5d
Showing
2 changed files
with
57 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 56 additions & 26 deletions
82
projects/kit/src/lib/masks/date-time/utils/tests/parse-date-time-string.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); | ||
}); | ||
}); |