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

Commit

Permalink
feat(dateparser): use 68 as the yy format pivot year
Browse files Browse the repository at this point in the history
- Use the same pivot year (68) for 2 digit date years as moment.js.
68 becomes 2068, 69 becomes 1969.

Closes #5735
  • Loading branch information
RobJacobs authored and wesleycho committed Apr 4, 2016
1 parent fc02fd1 commit 701e0cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/dateparser/dateparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ angular.module('ui.bootstrap.dateparser', [])
{
key: 'yy',
regex: '\\d{2}',
apply: function(value) { this.year = +value + 2000; },
apply: function(value) { value = +value; this.year = value < 69 ? value + 2000 : value + 1900; },
formatter: function(date) {
var _date = new Date();
_date.setFullYear(Math.abs(date.getFullYear()));
Expand Down
7 changes: 6 additions & 1 deletion src/dateparser/test/dateparser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,16 @@ describe('date parser', function() {
it('should work correctly for `yy`', function() {
expectParse('17.11.13', 'dd.MM.yy', new Date(2013, 10, 17, 0));
expectParse('02-05-11', 'dd-MM-yy', new Date(2011, 4, 2, 0));
expectParse('02/05/80', 'MM/dd/yy', new Date(2080, 1, 5, 0));
expectParse('02/05/80', 'MM/dd/yy', new Date(1980, 1, 5, 0));
expectParse('55/02/05', 'yy/MM/dd', new Date(2055, 1, 5, 0));
expectParse('11-08-13', 'dd-MM-yy', new Date(2013, 7, 11, 0));
});

it('should use `68` as the pivot year for `yy`', function() {
expectParse('17.11.68', 'dd.MM.yy', new Date(2068, 10, 17, 0));
expectParse('17.11.69', 'dd.MM.yy', new Date(1969, 10, 17, 0));
});

it('should work correctly for `y`', function() {
expectParse('17.11.2013', 'dd.MM.y', new Date(2013, 10, 17, 0));
expectParse('31.12.2013', 'dd.MM.y', new Date(2013, 11, 31, 0));
Expand Down

0 comments on commit 701e0cb

Please sign in to comment.