Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit c515104

Browse files
committed
Prevent time reseting(#4)
1 parent 8b904af commit c515104

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

lib/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ var DateTimeInput = function (_Component) {
7171
}
7272

7373
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = DateTimeInput.__proto__ || Object.getPrototypeOf(DateTimeInput)).call.apply(_ref, [this].concat(args))), _this), _this.onChange = function (_, date) {
74-
var tempDate = new Date(_this.props.input.value);
75-
date.setHours(tempDate.getHours());
76-
date.setMinutes(tempDate.getMinutes());
77-
date.setSeconds(tempDate.getSeconds());
74+
if (_this.props.input.value) {
75+
var tempDate = new Date(_this.props.input.value);
76+
date.setHours(tempDate.getHours());
77+
date.setMinutes(tempDate.getMinutes());
78+
date.setSeconds(tempDate.getSeconds());
79+
}
7880

7981
_this.props.input.onChange(date);
8082
_this.props.input.onBlur();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aor-datetime-input",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "aor-datetime-input",
55
"main": "lib/index.js",
66
"author": "iamsimakov",

src/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ export const datify = input => {
2222
class DateTimeInput extends Component {
2323

2424
onChange = (_, date) => {
25-
let tempDate = new Date(this.props.input.value);
26-
date.setHours(tempDate.getHours());
27-
date.setMinutes(tempDate.getMinutes());
28-
date.setSeconds(tempDate.getSeconds());
25+
if (this.props.input.value) {
26+
let tempDate = new Date(this.props.input.value);
27+
date.setHours(tempDate.getHours());
28+
date.setMinutes(tempDate.getMinutes());
29+
date.setSeconds(tempDate.getSeconds());
30+
}
2931

3032
this.props.input.onChange(date);
3133
this.props.input.onBlur();

0 commit comments

Comments
 (0)