Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 8facf60

Browse files
chrisirhcWesley Cho
authored and
Wesley Cho
committed
feat(dateparser): add support for milliseconds
Closes #3499
1 parent 6324486 commit 8facf60

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Diff for: src/dateparser/dateparser.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ angular.module('ui.bootstrap.dateparser', [])
6565
regex: '[0-9]|[1-5][0-9]',
6666
apply: function(value) { this.minutes = +value; }
6767
},
68+
'sss': {
69+
regex: '[0-9][0-9][0-9]',
70+
apply: function(value) { this.milliseconds = +value; }
71+
},
6872
'ss': {
6973
regex: '[0-5][0-9]',
7074
apply: function(value) { this.seconds = +value; }
@@ -120,7 +124,7 @@ angular.module('ui.bootstrap.dateparser', [])
120124
results = input.match(regex);
121125

122126
if ( results && results.length ) {
123-
var fields = { year: 1900, month: 0, date: 1, hours: 0, minutes: 0, seconds: 0 }, dt;
127+
var fields = { year: 1900, month: 0, date: 1, hours: 0, minutes: 0, seconds: 0, milliseconds: 0 }, dt;
124128

125129
for( var i = 1, n = results.length; i < n; i++ ) {
126130
var mapper = map[i-1];
@@ -130,7 +134,7 @@ angular.module('ui.bootstrap.dateparser', [])
130134
}
131135

132136
if ( isValid(fields.year, fields.month, fields.date) ) {
133-
dt = new Date(fields.year, fields.month, fields.date, fields.hours, fields.minutes, fields.seconds);
137+
dt = new Date(fields.year, fields.month, fields.date, fields.hours, fields.minutes, fields.seconds, fields.milliseconds);
134138
}
135139

136140
return dt;

Diff for: src/dateparser/test/dateparser.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ describe('date parser', function () {
9696
expectParse('22.March.15.2:1', 'd.MMMM.yy.H:m', new Date(2015, 2, 22, 2, 1));
9797
});
9898

99+
it('should work correctly for `sss`', function() {
100+
expectParse('22.March.15.123', 'd.MMMM.yy.sss', new Date(2015, 2, 22, 0, 0, 0, 123));
101+
expectParse('8-March-1991-059', 'd-MMMM-yyyy-sss', new Date(1991, 2, 8, 0, 0, 0, 59));
102+
expectParse('February/5/1980/000', 'MMMM/d/yyyy/sss', new Date(1980, 1, 5, 0, 0, 0));
103+
expectParse('1955/February/5 003', 'yyyy/MMMM/d sss', new Date(1955, 1, 5, 0, 0, 0, 3));
104+
expectParse('11-08-13 046', 'd-MM-yy sss', new Date(2013, 7, 11, 0, 0, 0, 46));
105+
expectParse('22.March.15.22:33:044', 'd.MMMM.yy.HH:mm:sss', new Date(2015, 2, 22, 22, 33, 0, 44));
106+
expectParse('22.March.15.0:0:001', 'd.MMMM.yy.H:m:sss', new Date(2015, 2, 22, 0, 0, 0, 1));
107+
});
108+
99109
it('should work correctly for `ss`', function() {
100110
expectParse('22.March.15.22', 'd.MMMM.yy.ss', new Date(2015, 2, 22, 0, 0, 22));
101111
expectParse('8-March-1991-59', 'd-MMMM-yyyy-ss', new Date(1991, 2, 8, 0, 0, 59));

0 commit comments

Comments
 (0)