generated from Tinkoff/angular-open-source-starter
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kit): use 1 as min segment value in
Date
-related masks (#197)
- Loading branch information
1 parent
0853483
commit c85ca23
Showing
11 changed files
with
110 additions
and
20 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
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
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
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
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
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
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
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
24 changes: 24 additions & 0 deletions
24
projects/kit/src/lib/utils/date/raise-segment-value-to-min.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {MaskitoDateSegments} from '../../types'; | ||
import {getObjectFromEntries} from '../get-object-from-entries'; | ||
import {getDateSegmentValueLength} from './date-segment-value-length'; | ||
|
||
export function raiseSegmentValueToMin( | ||
segments: Partial<MaskitoDateSegments>, | ||
fullMode: string, | ||
): Partial<MaskitoDateSegments> { | ||
const segmentsLength = getDateSegmentValueLength(fullMode); | ||
|
||
return getObjectFromEntries( | ||
Object.entries<string>(segments).map(([key, value]: [string, string]) => { | ||
const segmentLength = | ||
segmentsLength[key as keyof Partial<MaskitoDateSegments>]; | ||
|
||
return [ | ||
key, | ||
value.length === segmentLength && value.match(/^0+$/) | ||
? '1'.padStart(segmentLength, '0') | ||
: value, | ||
]; | ||
}), | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
projects/kit/src/lib/utils/date/tests/get-date-segment-value-length.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {getDateSegmentValueLength} from '../date-segment-value-length'; | ||
|
||
describe('getDateSegmentValueLength', () => { | ||
it('short date', () => { | ||
expect(getDateSegmentValueLength('mm.yy')).toEqual({day: 0, month: 2, year: 2}); | ||
}); | ||
|
||
it('full date', () => { | ||
expect(getDateSegmentValueLength('dd.mm.yyyy')).toEqual({ | ||
day: 2, | ||
month: 2, | ||
year: 4, | ||
}); | ||
}); | ||
}); |
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