Skip to content

Commit fc3622d

Browse files
authored
Merge pull request #80 from j-wang/fixing-date-time-loss-android
Fix Android Resetting Date or Time
2 parents 5b61de0 + 0e4d688 commit fc3622d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/CustomDatePickerAndroid/index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ export default class CustomDatePickerAndroid extends Component {
4545
mode: this.props.datePickerModeAndroid,
4646
});
4747
if (action !== DatePickerAndroid.dismissedAction) {
48-
const date = moment({ year, month, day }).toDate();
48+
let date;
49+
if (this.props.date) {
50+
let hour = moment(this.props.date).hour();
51+
let minute = moment(this.props.date).minute();
52+
date = moment({ year, month, day, hour, minute }).toDate();
53+
} else {
54+
date = moment({ year, month, day }).toDate();
55+
}
4956

5057
if (this.props.mode === 'datetime') {
5158
// Prepopulate and show time picker
@@ -82,7 +89,17 @@ export default class CustomDatePickerAndroid extends Component {
8289
is24Hour: this.props.is24Hour,
8390
});
8491
if (action !== TimePickerAndroid.dismissedAction) {
85-
const date = moment({ hour, minute }).toDate();
92+
let date;
93+
if (this.props.date) {
94+
// this prevents losing the Date elements
95+
// not sure if this check if necessary; based on date picker above
96+
year = moment(this.props.date).year();
97+
month = moment(this.props.date).month();
98+
day = moment(this.props.date).date();
99+
date = moment({year, month, day, hour, minute}).toDate();
100+
} else {
101+
date = moment({hour, minute}).toDate();
102+
}
86103
this.props.onConfirm(date);
87104
this.props.onHideAfterConfirm(date);
88105
} else {

0 commit comments

Comments
 (0)