From a4d4c6a327453bb4a3063bcbb1d4db76b1cb9238 Mon Sep 17 00:00:00 2001 From: gugegev5 <1725763838@qq.com> Date: Mon, 30 Jul 2018 10:41:03 +0800 Subject: [PATCH 1/2] auto format auto add 0 when input sth like 01:1 --- src/timeInput.jsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/timeInput.jsx b/src/timeInput.jsx index d8dade8..0610c6a 100644 --- a/src/timeInput.jsx +++ b/src/timeInput.jsx @@ -78,6 +78,14 @@ class TimeInput extends Component { if (val == this.state.time) { return; } + + if (val.length === 6) { + const times = val.split(":"); + if(times.length === 2 && times[1].length === 3) { + val = val.substr(0, 3) + val.substr(4, 2); + } + } + if (this.isValid(val)) { if (val.length === 2 && this.lastVal.length !== 3 && val.indexOf(':') === -1) { From c4fedfd55a9528b26bc4b8ea8907c32e15e79de1 Mon Sep 17 00:00:00 2001 From: gugegev5 <1725763838@qq.com> Date: Mon, 30 Jul 2018 10:45:32 +0800 Subject: [PATCH 2/2] auto format --- src/timeInput.jsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/timeInput.jsx b/src/timeInput.jsx index 0610c6a..ac77b82 100644 --- a/src/timeInput.jsx +++ b/src/timeInput.jsx @@ -95,6 +95,13 @@ class TimeInput extends Component { if (val.length === 2 && this.lastVal.length === 3) { val = val.slice(0, 1); } + + if (val.length === 4) { + const times = val.split(":"); + if(times.length === 2 && times[1].length === 1) { + val = val.substr(0, 3) + "0" + val.substr(3, 1); + } + } if (val.length > 5) { return false;