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

Commit 701e0cb

Browse files
RobJacobswesleycho
authored andcommitted
feat(dateparser): use 68 as the yy format pivot year
- Use the same pivot year (68) for 2 digit date years as moment.js. 68 becomes 2068, 69 becomes 1969. Closes #5735
1 parent fc02fd1 commit 701e0cb

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Diff for: src/dateparser/dateparser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ angular.module('ui.bootstrap.dateparser', [])
2727
{
2828
key: 'yy',
2929
regex: '\\d{2}',
30-
apply: function(value) { this.year = +value + 2000; },
30+
apply: function(value) { value = +value; this.year = value < 69 ? value + 2000 : value + 1900; },
3131
formatter: function(date) {
3232
var _date = new Date();
3333
_date.setFullYear(Math.abs(date.getFullYear()));

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,16 @@ describe('date parser', function() {
282282
it('should work correctly for `yy`', function() {
283283
expectParse('17.11.13', 'dd.MM.yy', new Date(2013, 10, 17, 0));
284284
expectParse('02-05-11', 'dd-MM-yy', new Date(2011, 4, 2, 0));
285-
expectParse('02/05/80', 'MM/dd/yy', new Date(2080, 1, 5, 0));
285+
expectParse('02/05/80', 'MM/dd/yy', new Date(1980, 1, 5, 0));
286286
expectParse('55/02/05', 'yy/MM/dd', new Date(2055, 1, 5, 0));
287287
expectParse('11-08-13', 'dd-MM-yy', new Date(2013, 7, 11, 0));
288288
});
289289

290+
it('should use `68` as the pivot year for `yy`', function() {
291+
expectParse('17.11.68', 'dd.MM.yy', new Date(2068, 10, 17, 0));
292+
expectParse('17.11.69', 'dd.MM.yy', new Date(1969, 10, 17, 0));
293+
});
294+
290295
it('should work correctly for `y`', function() {
291296
expectParse('17.11.2013', 'dd.MM.y', new Date(2013, 10, 17, 0));
292297
expectParse('31.12.2013', 'dd.MM.y', new Date(2013, 11, 31, 0));

0 commit comments

Comments
 (0)