From df744f3af46fc227a934f16cb63c7a6038e7133b Mon Sep 17 00:00:00 2001 From: Maxim Grach Date: Fri, 1 Feb 2013 11:41:28 +0600 Subject: feat(dateFilter): add `[.,]sss` formatter for milliseconds Also Implement getMilliseconds() method of TzDate and add test for this in ngMock. --- src/ng/filter/filters.js | 4 ++++ src/ngMock/angular-mocks.js | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ng/filter/filters.js b/src/ng/filter/filters.js index 3459ef88..4680a306 100644 --- a/src/ng/filter/filters.js +++ b/src/ng/filter/filters.js @@ -241,6 +241,9 @@ var DATE_FORMATS = { m: dateGetter('Minutes', 1), ss: dateGetter('Seconds', 2), s: dateGetter('Seconds', 1), + // while ISO 8601 requires fractions to be prefixed with `.` or `,` + // we can be just safely rely on using `sss` since we currently don't support single or two digit fractions + sss: dateGetter('Milliseconds', 3), EEEE: dateStrGetter('Day'), EEE: dateStrGetter('Day', true), a: ampmGetter, @@ -279,6 +282,7 @@ var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+ * * `'m'`: Minute in hour (0-59) * * `'ss'`: Second in minute, padded (00-59) * * `'s'`: Second in minute (0-59) + * * `'.sss' or ',sss'`: Millisecond in second, padded (000-999) * * `'a'`: am/pm marker * * `'Z'`: 4 digit (+sign) representation of the timezone offset (-1200-1200) * diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index c0b499ef..3bd93a40 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -456,6 +456,7 @@ angular.mock.$LogProvider = function() { * newYearInBratislava.getDate() => 1; * newYearInBratislava.getHours() => 0; * newYearInBratislava.getMinutes() => 0; + * newYearInBratislava.getSeconds() => 0; * * */ @@ -512,6 +513,10 @@ angular.mock.$LogProvider = function() { return self.date.getSeconds(); }; + self.getMilliseconds = function() { + return self.date.getMilliseconds(); + }; + self.getTimezoneOffset = function() { return offset * 60; }; @@ -562,7 +567,7 @@ angular.mock.$LogProvider = function() { } //hide all methods not implemented in this mock that the Date prototype exposes - var unimplementedMethods = ['getMilliseconds', 'getUTCDay', + var unimplementedMethods = ['getUTCDay', 'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds', 'setMinutes', 'setMonth', 'setSeconds', 'setTime', 'setUTCDate', 'setUTCFullYear', 'setUTCHours', 'setUTCMilliseconds', 'setUTCMinutes', 'setUTCMonth', 'setUTCSeconds', -- cgit v1.2.3