bug(datePipe): passing "hh" to the datepipe (#9774)

closes #9759
This commit is contained in:
Andrei Tserakhau 2016-07-02 01:34:57 +03:00 committed by Victor Berchet
parent 0c65d5cf2b
commit 5eca6e4e40
2 changed files with 15 additions and 11 deletions

View File

@ -19,7 +19,7 @@ export function main() {
var pipe: DatePipe; var pipe: DatePipe;
beforeEach(() => { beforeEach(() => {
date = DateWrapper.create(2015, 6, 15, 21, 3, 1); date = DateWrapper.create(2015, 6, 15, 9, 3, 1);
pipe = new DatePipe(); pipe = new DatePipe();
}); });
@ -56,8 +56,10 @@ export function main() {
expect(pipe.transform(date, 'd')).toEqual('15'); expect(pipe.transform(date, 'd')).toEqual('15');
expect(pipe.transform(date, 'E')).toEqual('Mon'); expect(pipe.transform(date, 'E')).toEqual('Mon');
expect(pipe.transform(date, 'EEEE')).toEqual('Monday'); expect(pipe.transform(date, 'EEEE')).toEqual('Monday');
expect(pipe.transform(date, 'H')).toEqual('21'); expect(pipe.transform(date, 'h')).toEqual('9');
expect(pipe.transform(date, 'j')).toEqual('9 PM'); expect(pipe.transform(date, 'hh')).toEqual('09');
expect(pipe.transform(date, 'HH')).toEqual('09');
expect(pipe.transform(date, 'j')).toEqual('9 AM');
expect(pipe.transform(date, 'm')).toEqual('3'); expect(pipe.transform(date, 'm')).toEqual('3');
expect(pipe.transform(date, 's')).toEqual('1'); expect(pipe.transform(date, 's')).toEqual('1');
expect(pipe.transform(date, 'mm')).toEqual('03'); expect(pipe.transform(date, 'mm')).toEqual('03');
@ -74,22 +76,22 @@ export function main() {
expect(pipe.transform(date, 'MEd')).toEqual('6Mon15'); expect(pipe.transform(date, 'MEd')).toEqual('6Mon15');
expect(pipe.transform(date, 'MMMd')).toEqual('Jun15'); expect(pipe.transform(date, 'MMMd')).toEqual('Jun15');
expect(pipe.transform(date, 'yMMMMEEEEd')).toEqual('Monday, June 15, 2015'); expect(pipe.transform(date, 'yMMMMEEEEd')).toEqual('Monday, June 15, 2015');
expect(pipe.transform(date, 'jms')).toEqual('9:03:01 PM');
expect(pipe.transform(date, 'ms')).toEqual('31'); expect(pipe.transform(date, 'ms')).toEqual('31');
expect(pipe.transform(date, 'jm')).toEqual('9:03 PM'); expect(pipe.transform(date, 'jm')).toEqual('9:03 AM');
}); });
it('should format with pattern aliases', () => { it('should format with pattern aliases', () => {
expect(pipe.transform(date, 'medium')).toEqual('Jun 15, 2015, 9:03:01 PM'); expect(pipe.transform(date, 'medium')).toEqual('Jun 15, 2015, 9:03:01 AM');
expect(pipe.transform(date, 'short')).toEqual('6/15/2015, 9:03 PM'); expect(pipe.transform(date, 'short')).toEqual('6/15/2015, 9:03 AM');
expect(pipe.transform(date, 'dd/MM/yyyy')).toEqual('15/06/2015'); expect(pipe.transform(date, 'dd/MM/yyyy')).toEqual('15/06/2015');
expect(pipe.transform(date, 'MM/dd/yyyy')).toEqual('06/15/2015'); expect(pipe.transform(date, 'MM/dd/yyyy')).toEqual('06/15/2015');
expect(pipe.transform(date, 'fullDate')).toEqual('Monday, June 15, 2015'); expect(pipe.transform(date, 'fullDate')).toEqual('Monday, June 15, 2015');
expect(pipe.transform(date, 'longDate')).toEqual('June 15, 2015'); expect(pipe.transform(date, 'longDate')).toEqual('June 15, 2015');
expect(pipe.transform(date, 'mediumDate')).toEqual('Jun 15, 2015'); expect(pipe.transform(date, 'mediumDate')).toEqual('Jun 15, 2015');
expect(pipe.transform(date, 'shortDate')).toEqual('6/15/2015'); expect(pipe.transform(date, 'shortDate')).toEqual('6/15/2015');
expect(pipe.transform(date, 'mediumTime')).toEqual('9:03:01 PM'); expect(pipe.transform(date, 'mediumTime')).toEqual('9:03:01 AM');
expect(pipe.transform(date, 'shortTime')).toEqual('9:03 PM'); expect(pipe.transform(date, 'shortTime')).toEqual('9:03 AM');
}); });
}); });
} }

View File

@ -78,9 +78,11 @@ var DATE_FORMATS = {
LLLL: datePartGetterFactory(nameCondition('month', 4)), LLLL: datePartGetterFactory(nameCondition('month', 4)),
dd: datePartGetterFactory(digitCondition('day', 2)), dd: datePartGetterFactory(digitCondition('day', 2)),
d: datePartGetterFactory(digitCondition('day', 1)), d: datePartGetterFactory(digitCondition('day', 1)),
HH: hourExtracter(datePartGetterFactory(hour12Modify(digitCondition('hour', 2), false))), HH: digitModifier(
hourExtracter(datePartGetterFactory(hour12Modify(digitCondition('hour', 2), false)))),
H: hourExtracter(datePartGetterFactory(hour12Modify(digitCondition('hour', 1), false))), H: hourExtracter(datePartGetterFactory(hour12Modify(digitCondition('hour', 1), false))),
hh: hourExtracter(datePartGetterFactory(hour12Modify(digitCondition('hour', 2), true))), hh: digitModifier(
hourExtracter(datePartGetterFactory(hour12Modify(digitCondition('hour', 2), true)))),
h: hourExtracter(datePartGetterFactory(hour12Modify(digitCondition('hour', 1), true))), h: hourExtracter(datePartGetterFactory(hour12Modify(digitCondition('hour', 1), true))),
jj: datePartGetterFactory(digitCondition('hour', 2)), jj: datePartGetterFactory(digitCondition('hour', 2)),
j: datePartGetterFactory(digitCondition('hour', 1)), j: datePartGetterFactory(digitCondition('hour', 1)),