Skip to content

Commit 602f972

Browse files
authored
Merge pull request #9517 from IgniteUI/bpenkov/date-editor-formatting
Treat all year formats that are not "yy" as "yyyy"
2 parents c3087a2 + 322ae21 commit 602f972

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

projects/igniteui-angular/src/lib/date-common/util/date-time.util.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,32 @@ describe(`DateTimeUtil Unit tests`, () => {
4444
expect(resDict[DatePart.Date]).toEqual(jasmine.objectContaining({ start: 3, end: 5 }));
4545
expect(resDict[DatePart.Year]).toEqual(jasmine.objectContaining({ start: 6, end: 8 }));
4646

47+
// d/M/y should be 00/00/0000
48+
result = DateTimeUtil.parseDateTimeFormat('d/M/y');
49+
resDict = reduceToDictionary(result);
50+
expect(result.length).toEqual(5);
51+
expect(resDict[DatePart.Date]).toEqual(jasmine.objectContaining({ start: 0, end: 2 }));
52+
expect(resDict[DatePart.Month]).toEqual(jasmine.objectContaining({ start: 3, end: 5 }));
53+
expect(resDict[DatePart.Year]).toEqual(jasmine.objectContaining({ start: 6, end: 10 }));
54+
55+
// d/M/yyy should be 00/00/0000
56+
result = DateTimeUtil.parseDateTimeFormat('d/M/yyy');
57+
resDict = reduceToDictionary(result);
58+
expect(result.length).toEqual(5);
59+
expect(resDict[DatePart.Date]).toEqual(jasmine.objectContaining({ start: 0, end: 2 }));
60+
expect(resDict[DatePart.Month]).toEqual(jasmine.objectContaining({ start: 3, end: 5 }));
61+
expect(resDict[DatePart.Year]).toEqual(jasmine.objectContaining({ start: 6, end: 10 }));
62+
63+
64+
// d/M/yyyy should 00/00/0000
65+
result = DateTimeUtil.parseDateTimeFormat('d/M/yyyy');
66+
resDict = reduceToDictionary(result);
67+
expect(result.length).toEqual(5);
68+
expect(resDict[DatePart.Date]).toEqual(jasmine.objectContaining({ start: 0, end: 2 }));
69+
expect(resDict[DatePart.Month]).toEqual(jasmine.objectContaining({ start: 3, end: 5 }));
70+
expect(resDict[DatePart.Year]).toEqual(jasmine.objectContaining({ start: 6, end: 10 }));
71+
72+
4773
// H:m:s should be 00:00:00
4874
result = DateTimeUtil.parseDateTimeFormat('H:m:s');
4975
resDict = reduceToDictionary(result);

projects/igniteui-angular/src/lib/date-common/util/date-time.util.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ export abstract class DateTimeUtil {
113113
if (!dateTimeParts.filter(p => p.format.includes(currentPart.format)).length) {
114114
DateTimeUtil.addCurrentPart(currentPart, dateTimeParts);
115115
}
116+
// formats like "y" or "yyy" are treated like "yyyy" while editing
117+
const yearPart = dateTimeParts.filter(p => p.type === DatePart.Year)[0];
118+
if (yearPart && yearPart.format !== 'yy') {
119+
yearPart.end += 4 - yearPart.format.length;
120+
yearPart.format = 'yyyy';
121+
}
116122

117123
return dateTimeParts;
118124
}

0 commit comments

Comments
 (0)