Skip to content

Commit f3b695d

Browse files
authored
Merge branch 'master' into simeonoff/add-row-styling
2 parents 58d35c3 + b4fb058 commit f3b695d

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

projects/igniteui-angular/src/lib/date-picker/date-picker.utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ export abstract class DatePickerUtil {
6868
}
6969
parts[dp.type] = value;
7070
});
71+
parts[DatePart.Month] -= 1;
7172

72-
if (parts[DatePart.Month] < 1 || 12 < parts[DatePart.Month]) {
73+
if (parts[DatePart.Month] < 0 || 11 < parts[DatePart.Month]) {
7374
return null;
7475
}
7576

@@ -88,7 +89,7 @@ export abstract class DatePickerUtil {
8889

8990
return new Date(
9091
parts[DatePart.Year] || 2000,
91-
parts[DatePart.Month] - 1 || 0,
92+
parts[DatePart.Month] || 0,
9293
parts[DatePart.Date] || 1,
9394
parts[DatePart.Hours] || 0,
9495
parts[DatePart.Minutes] || 0,

projects/igniteui-angular/src/lib/directives/date-time-editor/date-time-parsing.spec.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ describe('Date Time Parsing', () => {
1212
it('should correctly parse all date time parts (base)', () => {
1313
const result = DatePickerUtil.parseDateTimeFormat('dd/MM/yyyy HH:mm:ss tt');
1414
const expected = [
15-
{start: 0, end: 2, type: DatePart.Date, format: 'dd'},
16-
{start: 2, end: 3, type: DatePart.Literal, format: '/'},
17-
{start: 3, end: 5, type: DatePart.Month, format: 'MM'},
18-
{start: 5, end: 6, type: DatePart.Literal, format: '/'},
19-
{start: 6, end: 10, type: DatePart.Year, format: 'yyyy'},
20-
{start: 10, end: 11, type: DatePart.Literal, format: ' '},
21-
{start: 11, end: 13, type: DatePart.Hours, format: 'HH'},
22-
{start: 13, end: 14, type: DatePart.Literal, format: ':'},
23-
{start: 14, end: 16, type: DatePart.Minutes, format: 'mm'},
24-
{start: 16, end: 17, type: DatePart.Literal, format: ':'},
25-
{start: 17, end: 19, type: DatePart.Seconds, format: 'ss'},
26-
{start: 19, end: 20, type: DatePart.Literal, format: ' '},
27-
{start: 20, end: 22, type: DatePart.AmPm, format: 'tt'}
15+
{ start: 0, end: 2, type: DatePart.Date, format: 'dd' },
16+
{ start: 2, end: 3, type: DatePart.Literal, format: '/' },
17+
{ start: 3, end: 5, type: DatePart.Month, format: 'MM' },
18+
{ start: 5, end: 6, type: DatePart.Literal, format: '/' },
19+
{ start: 6, end: 10, type: DatePart.Year, format: 'yyyy' },
20+
{ start: 10, end: 11, type: DatePart.Literal, format: ' ' },
21+
{ start: 11, end: 13, type: DatePart.Hours, format: 'HH' },
22+
{ start: 13, end: 14, type: DatePart.Literal, format: ':' },
23+
{ start: 14, end: 16, type: DatePart.Minutes, format: 'mm' },
24+
{ start: 16, end: 17, type: DatePart.Literal, format: ':' },
25+
{ start: 17, end: 19, type: DatePart.Seconds, format: 'ss' },
26+
{ start: 19, end: 20, type: DatePart.Literal, format: ' ' },
27+
{ start: 20, end: 22, type: DatePart.AmPm, format: 'tt' }
2828
];
2929
expect(JSON.stringify(result)).toEqual(JSON.stringify(expected));
3030
});
@@ -67,4 +67,14 @@ describe('Date Time Parsing', () => {
6767
expect(resDict[DatePart.Month]).toEqual(jasmine.objectContaining({ start: 5, end: 7 }));
6868
expect(resDict[DatePart.Date]).toEqual(jasmine.objectContaining({ start: 8, end: 10 }));
6969
});
70+
71+
it('should correctly parse boundary dates', () => {
72+
const parts = DatePickerUtil.parseDateTimeFormat('MM/dd/yyyy');
73+
let result = DatePickerUtil.parseValueFromMask('08/31/2020', parts);
74+
expect(result).toEqual(new Date(2020, 7, 31));
75+
result = DatePickerUtil.parseValueFromMask('09/30/2020', parts);
76+
expect(result).toEqual(new Date(2020, 8, 30));
77+
result = DatePickerUtil.parseValueFromMask('10/31/2020', parts);
78+
expect(result).toEqual(new Date(2020, 9, 31));
79+
});
7080
});

0 commit comments

Comments
 (0)