Skip to content

Commit

Permalink
[ISSUE-304] Fix date full year leading 0 issue (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
nosir authored Mar 19, 2018
1 parent 9a5c004 commit 9956467
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"form",
"input"
],
"version": "1.1.5",
"version": "1.1.6",
"author": {
"name": "Max Huang",
"email": "[email protected]",
Expand Down
10 changes: 8 additions & 2 deletions dist/cleave-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ return /******/ (function(modules) { // webpackBootstrap
var owner = this, datePattern = owner.datePattern, date = [],
dayIndex = 0, monthIndex = 0, yearIndex = 0,
dayStartIndex = 0, monthStartIndex = 0, yearStartIndex = 0,
day, month, year;
day, month, year, fullYearDone = false;

// mm-dd || dd-mm
if (value.length === 4 && datePattern[0].toLowerCase() !== 'y' && datePattern[1].toLowerCase() !== 'y') {
Expand Down Expand Up @@ -702,6 +702,8 @@ return /******/ (function(modules) { // webpackBootstrap
month = parseInt(value.slice(monthStartIndex, monthStartIndex + 2), 10);
year = parseInt(value.slice(yearStartIndex, yearStartIndex + 4), 10);

fullYearDone = value.slice(yearStartIndex, yearStartIndex + 4).length === 4;

date = this.getFixedDate(day, month, year);
}

Expand All @@ -714,7 +716,7 @@ return /******/ (function(modules) { // webpackBootstrap
case 'm':
return previous + owner.addLeadingZero(date[1]);
default:
return previous + '' + (date[2] || '');
return previous + (fullYearDone ? owner.addLeadingZeroForYear(date[2]) : '');
}
}, '');
},
Expand All @@ -737,6 +739,10 @@ return /******/ (function(modules) { // webpackBootstrap

addLeadingZero: function (number) {
return (number < 10 ? '0' : '') + number;
},

addLeadingZeroForYear: function (number) {
return (number < 10 ? '000' : (number < 100 ? '00' : (number < 1000 ? '0' : ''))) + number;
}
};

Expand Down
4 changes: 2 additions & 2 deletions dist/cleave-angular.min.js

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions dist/cleave-react-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,8 @@ return /******/ (function(modules) { // webpackBootstrap
yearStartIndex = 0,
day,
month,
year;
year,
fullYearDone = false;

// mm-dd || dd-mm
if (value.length === 4 && datePattern[0].toLowerCase() !== 'y' && datePattern[1].toLowerCase() !== 'y') {
Expand Down Expand Up @@ -1958,6 +1959,8 @@ return /******/ (function(modules) { // webpackBootstrap
month = parseInt(value.slice(monthStartIndex, monthStartIndex + 2), 10);
year = parseInt(value.slice(yearStartIndex, yearStartIndex + 4), 10);

fullYearDone = value.slice(yearStartIndex, yearStartIndex + 4).length === 4;

date = this.getFixedDate(day, month, year);
}

Expand All @@ -1970,7 +1973,7 @@ return /******/ (function(modules) { // webpackBootstrap
case 'm':
return previous + owner.addLeadingZero(date[1]);
default:
return previous + '' + (date[2] || '');
return previous + (fullYearDone ? owner.addLeadingZeroForYear(date[2]) : '');
}
}, '');
},
Expand All @@ -1993,6 +1996,10 @@ return /******/ (function(modules) { // webpackBootstrap

addLeadingZero: function addLeadingZero(number) {
return (number < 10 ? '0' : '') + number;
},

addLeadingZeroForYear: function addLeadingZeroForYear(number) {
return (number < 10 ? '000' : number < 100 ? '00' : number < 1000 ? '0' : '') + number;
}
};

Expand Down
4 changes: 2 additions & 2 deletions dist/cleave-react-node.min.js

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions dist/cleave-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,8 @@ return /******/ (function(modules) { // webpackBootstrap
yearStartIndex = 0,
day,
month,
year;
year,
fullYearDone = false;

// mm-dd || dd-mm
if (value.length === 4 && datePattern[0].toLowerCase() !== 'y' && datePattern[1].toLowerCase() !== 'y') {
Expand Down Expand Up @@ -2152,6 +2153,8 @@ return /******/ (function(modules) { // webpackBootstrap
month = parseInt(value.slice(monthStartIndex, monthStartIndex + 2), 10);
year = parseInt(value.slice(yearStartIndex, yearStartIndex + 4), 10);

fullYearDone = value.slice(yearStartIndex, yearStartIndex + 4).length === 4;

date = this.getFixedDate(day, month, year);
}

Expand All @@ -2164,7 +2167,7 @@ return /******/ (function(modules) { // webpackBootstrap
case 'm':
return previous + owner.addLeadingZero(date[1]);
default:
return previous + '' + (date[2] || '');
return previous + (fullYearDone ? owner.addLeadingZeroForYear(date[2]) : '');
}
}, '');
},
Expand All @@ -2187,6 +2190,10 @@ return /******/ (function(modules) { // webpackBootstrap

addLeadingZero: function addLeadingZero(number) {
return (number < 10 ? '0' : '') + number;
},

addLeadingZeroForYear: function addLeadingZeroForYear(number) {
return (number < 10 ? '000' : number < 100 ? '00' : number < 1000 ? '0' : '') + number;
}
};

Expand Down
4 changes: 2 additions & 2 deletions dist/cleave-react.min.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions dist/cleave.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ return /******/ (function(modules) { // webpackBootstrap
var owner = this, datePattern = owner.datePattern, date = [],
dayIndex = 0, monthIndex = 0, yearIndex = 0,
dayStartIndex = 0, monthStartIndex = 0, yearStartIndex = 0,
day, month, year;
day, month, year, fullYearDone = false;

// mm-dd || dd-mm
if (value.length === 4 && datePattern[0].toLowerCase() !== 'y' && datePattern[1].toLowerCase() !== 'y') {
Expand Down Expand Up @@ -702,6 +702,8 @@ return /******/ (function(modules) { // webpackBootstrap
month = parseInt(value.slice(monthStartIndex, monthStartIndex + 2), 10);
year = parseInt(value.slice(yearStartIndex, yearStartIndex + 4), 10);

fullYearDone = value.slice(yearStartIndex, yearStartIndex + 4).length === 4;

date = this.getFixedDate(day, month, year);
}

Expand All @@ -714,7 +716,7 @@ return /******/ (function(modules) { // webpackBootstrap
case 'm':
return previous + owner.addLeadingZero(date[1]);
default:
return previous + '' + (date[2] || '');
return previous + (fullYearDone ? owner.addLeadingZeroForYear(date[2]) : '');
}
}, '');
},
Expand All @@ -737,6 +739,10 @@ return /******/ (function(modules) { // webpackBootstrap

addLeadingZero: function (number) {
return (number < 10 ? '0' : '') + number;
},

addLeadingZeroForYear: function (number) {
return (number < 10 ? '000' : (number < 100 ? '00' : (number < 1000 ? '0' : ''))) + number;
}
};

Expand Down
Loading

0 comments on commit 9956467

Please sign in to comment.