mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
feat(dateFilter): add [.,]sss formatter for milliseconds
Also Implement getMilliseconds() method of TzDate and add test for this in ngMock.
This commit is contained in:
parent
8155c3a29e
commit
df744f3af4
4 changed files with 30 additions and 4 deletions
|
|
@ -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)
|
||||
*
|
||||
|
|
|
|||
7
src/ngMock/angular-mocks.js
vendored
7
src/ngMock/angular-mocks.js
vendored
|
|
@ -456,6 +456,7 @@ angular.mock.$LogProvider = function() {
|
|||
* newYearInBratislava.getDate() => 1;
|
||||
* newYearInBratislava.getHours() => 0;
|
||||
* newYearInBratislava.getMinutes() => 0;
|
||||
* newYearInBratislava.getSeconds() => 0;
|
||||
* </pre>
|
||||
*
|
||||
*/
|
||||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -162,9 +162,9 @@ describe('filters', function() {
|
|||
|
||||
describe('date', function() {
|
||||
|
||||
var morning = new angular.mock.TzDate(+5, '2010-09-03T12:05:08.000Z'); //7am
|
||||
var noon = new angular.mock.TzDate(+5, '2010-09-03T17:05:08.000Z'); //12pm
|
||||
var midnight = new angular.mock.TzDate(+5, '2010-09-03T05:05:08.000Z'); //12am
|
||||
var morning = new angular.mock.TzDate(+5, '2010-09-03T12:05:08.001Z'); //7am
|
||||
var noon = new angular.mock.TzDate(+5, '2010-09-03T17:05:08.012Z'); //12pm
|
||||
var midnight = new angular.mock.TzDate(+5, '2010-09-03T05:05:08.123Z'); //12am
|
||||
var earlyDate = new angular.mock.TzDate(+5, '0001-09-03T05:05:08.000Z');
|
||||
|
||||
var date;
|
||||
|
|
@ -192,15 +192,24 @@ describe('filters', function() {
|
|||
expect(date(morning, "yy-MM-dd HH:mm:ss")).
|
||||
toEqual('10-09-03 07:05:08');
|
||||
|
||||
expect(date(morning, "yy-MM-dd HH:mm:ss.sss")).
|
||||
toEqual('10-09-03 07:05:08.001');
|
||||
|
||||
expect(date(midnight, "yyyy-M-d h=H:m:saZ")).
|
||||
toEqual('2010-9-3 12=0:5:8AM-0500');
|
||||
|
||||
expect(date(midnight, "yyyy-MM-dd hh=HH:mm:ssaZ")).
|
||||
toEqual('2010-09-03 12=00:05:08AM-0500');
|
||||
|
||||
expect(date(midnight, "yyyy-MM-dd hh=HH:mm:ss.sssaZ")).
|
||||
toEqual('2010-09-03 12=00:05:08.123AM-0500');
|
||||
|
||||
expect(date(noon, "yyyy-MM-dd hh=HH:mm:ssaZ")).
|
||||
toEqual('2010-09-03 12=12:05:08PM-0500');
|
||||
|
||||
expect(date(noon, "yyyy-MM-dd hh=HH:mm:ss.sssaZ")).
|
||||
toEqual('2010-09-03 12=12:05:08.012PM-0500');
|
||||
|
||||
expect(date(noon, "EEE, MMM d, yyyy")).
|
||||
toEqual('Fri, Sep 3, 2010');
|
||||
|
||||
|
|
|
|||
8
test/ngMock/angular-mocksSpec.js
vendored
8
test/ngMock/angular-mocksSpec.js
vendored
|
|
@ -109,6 +109,13 @@ describe('ngMock', function() {
|
|||
});
|
||||
|
||||
|
||||
it('should fake getMilliseconds method', function() {
|
||||
expect(new angular.mock.TzDate(0, '2010-09-03T23:05:08.003Z').getMilliseconds()).toBe(3);
|
||||
expect(new angular.mock.TzDate(0, '2010-09-03T23:05:08.023Z').getMilliseconds()).toBe(23);
|
||||
expect(new angular.mock.TzDate(0, '2010-09-03T23:05:08.123Z').getMilliseconds()).toBe(123);
|
||||
});
|
||||
|
||||
|
||||
it('should create a date representing new year in Bratislava', function() {
|
||||
var newYearInBratislava = new angular.mock.TzDate(-1, '2009-12-31T23:00:00.000Z');
|
||||
expect(newYearInBratislava.getTimezoneOffset()).toBe(-60);
|
||||
|
|
@ -117,6 +124,7 @@ describe('ngMock', function() {
|
|||
expect(newYearInBratislava.getDate()).toBe(1);
|
||||
expect(newYearInBratislava.getHours()).toBe(0);
|
||||
expect(newYearInBratislava.getMinutes()).toBe(0);
|
||||
expect(newYearInBratislava.getSeconds()).toBe(0);
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue