Skip to content

Commit

Permalink
Merge pull request #60 from nosir/bug-fix
Browse files Browse the repository at this point in the history
[bug-fix] Date input improvement
  • Loading branch information
nosir authored Jul 21, 2016
2 parents 0a63989 + c295a52 commit 14d938c
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 37 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": "0.4.9",
"version": "0.4.10",
"author": {
"name": "Max Huang",
"email": "[email protected]",
Expand Down
22 changes: 15 additions & 7 deletions dist/cleave-react.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions dist/cleave.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,22 +557,30 @@ DateFormatter.prototype = {
owner.blocks.forEach(function (length, index) {
if (value.length > 0) {
var sub = value.slice(0, length),
sub0 = sub.slice(0, 1),
rest = value.slice(length);

switch (owner.datePattern[index]) {
case 'd':
if (parseInt(sub, 10) > 31) {
if (sub === '00') {
sub = '01';
} else if (parseInt(sub0, 10) > 3) {
sub = '0' + sub0;
} else if (parseInt(sub, 10) > 31) {
sub = '31';
} else if (parseInt(sub, 10) === 0) {
//sub = '01';
}

break;

case 'm':
if (parseInt(sub, 10) > 12) {
if (sub === '00') {
sub = '01';
} else if (parseInt(sub0, 10) > 1) {
sub = '0' + sub0;
} else if (parseInt(sub, 10) > 12) {
sub = '12';
} else if (parseInt(sub, 10) === 0) {
//sub = '01';
}

break;
}

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"form",
"input"
],
"version": "0.4.9",
"version": "0.4.10",
"author": {
"name": "Max Huang",
"url": "http://github.com/nosir",
Expand Down
20 changes: 14 additions & 6 deletions src/shortcuts/DateFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,30 @@ DateFormatter.prototype = {
owner.blocks.forEach(function (length, index) {
if (value.length > 0) {
var sub = value.slice(0, length),
sub0 = sub.slice(0, 1),
rest = value.slice(length);

switch (owner.datePattern[index]) {
case 'd':
if (parseInt(sub, 10) > 31) {
if (sub === '00') {
sub = '01';
} else if (parseInt(sub0, 10) > 3) {
sub = '0' + sub0;
} else if (parseInt(sub, 10) > 31) {
sub = '31';
} else if (parseInt(sub, 10) === 0) {
//sub = '01';
}

break;

case 'm':
if (parseInt(sub, 10) > 12) {
if (sub === '00') {
sub = '01';
} else if (parseInt(sub0, 10) > 1) {
sub = '0' + sub0;
} else if (parseInt(sub, 10) > 12) {
sub = '12';
} else if (parseInt(sub, 10) === 0) {
//sub = '01';
}

break;
}

Expand Down
36 changes: 24 additions & 12 deletions test/fixtures/date.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@
],
[
"99071965",
"31071965"
"09071965"
],
[
"08991965",
"08121965"
"08091965"
],
[
"08121965000",
"08121965"
],
[
"08001965",
"08001965"
"08011965"
],
[
"00081965",
"00081965"
"08141965",
"08121965"
],
[
"4",
"04"
]
]
},
Expand All @@ -48,28 +52,32 @@
"010765"
],
[
"990765",
"330765",
"310765"
],
[
"089965",
"081265"
"080965"
],
[
"08126599",
"081265"
],
[
"08/99*6599",
"08/18*6599",
"081265"
],
[
"080065",
"080065"
"080165"
],
[
"000865",
"000865"
"010865"
],
[
"900065",
"090165"
]
]
},
Expand All @@ -84,7 +92,7 @@
"0718"
],
[
"9918",
"1918",
"1218"
],
[
Expand All @@ -93,7 +101,11 @@
],
[
"0008",
"0008"
"0108"
],
[
"9018",
"0918"
]
]
}
Expand Down

0 comments on commit 14d938c

Please sign in to comment.