mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-23 03:30:02 +08:00
fix(dateFilter): support sub-second precision on dateFilter
This commit is contained in:
committed by
Misko Hevery
parent
05c88b866b
commit
f299fd5122
@@ -320,7 +320,7 @@ dateFilter.$inject = ['$locale'];
|
||||
function dateFilter($locale) {
|
||||
|
||||
|
||||
var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/;
|
||||
var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/;
|
||||
function jsonStringToDate(string){
|
||||
var match;
|
||||
if (match = string.match(R_ISO8601_STR)) {
|
||||
|
||||
@@ -270,5 +270,18 @@ describe('filters', function() {
|
||||
//no time
|
||||
expect(date('2003-09-10', format)).toEqual('2003-09 00');
|
||||
});
|
||||
|
||||
it('should support different degrees of subsecond precision', function () {
|
||||
var format = 'yyyy-MM-dd';
|
||||
|
||||
expect(date('2003-09-10T13:02:03.12345678Z', format)).toEqual('2003-09-10');
|
||||
expect(date('2003-09-10T13:02:03.1234567Z', format)).toEqual('2003-09-10');
|
||||
expect(date('2003-09-10T13:02:03.123456Z', format)).toEqual('2003-09-10');
|
||||
expect(date('2003-09-10T13:02:03.12345Z', format)).toEqual('2003-09-10');
|
||||
expect(date('2003-09-10T13:02:03.1234Z', format)).toEqual('2003-09-10');
|
||||
expect(date('2003-09-10T13:02:03.123Z', format)).toEqual('2003-09-10');
|
||||
expect(date('2003-09-10T13:02:03.12Z', format)).toEqual('2003-09-10');
|
||||
expect(date('2003-09-10T13:02:03.1Z', format)).toEqual('2003-09-10');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user