react-native-datepicker
react-native-datepicker copied to clipboard
datepicker show Incorrect time
Issue
If you do not select a time and right click confirm button will show the current time. But I set minuteInterval = 5 and this parameter ignore.
Expected Behavior
If you do not select time and right click confirm button will show current time given minute interval.
Code
<Item style={{ ...styles.inlineInput }} stackedLabel>
<Label style={styles.label}>{'Date'.toUpperCase()}</Label>
<Input
style={initial || date.length > 0
? { ...styles.input }
: {...styles.input,...styles.inputInvalid}}
value={date ? moment(date).format("MMMM DD, YYYY") : date}
onFocus={() => this.datepicker.onPressDate()}/>
<DatePicker
style={{width: 0,height:0}}
date={date}
mode="date"
format="MM/DD/YYYY"
minDate={new Date()}
confirmBtnText="Confirm"
cancelBtnText="Cancel"
hideText={true}
showIcon={false}
onDateChange={(date) => onDateChange(date)}
ref={(d) => { this.datepicker = d }}
/>
</Item>
Environment
-
react-native -v
: 0.46.4 -
node -v
: 8.2.0 -
npm -v
: 5.3.0 -
yarn --version
: 0.24.6 -
target platform
: Android | iOS -
operating system
: Mac
@lossen Have you solved your problem?
Same problem here!
How you implemented the code for the time selection picker.??
I am also getting the same issue.
This is a quick fix:
onDateChange={(time) => {
let [hours, minutes] = time.split(':');
hours = parseInt(hours);
minutes = parseInt(minutes);
// Convert hours and minutes to time in minutes
time = (hours * 60) + minutes;
let rounded = Math.floor(time / 15) * 15;
let rHr = ''+Math.floor(rounded / 60)
let rMin = ''+ rounded % 60
const roundTime = rHr.padStart(2, '0')+':'+rMin.padStart(2, '0')
this.setState(
{activityTime: roundTime}
)
}
}
Thanks to This time rounding method. (I changed Math.round to Math.floor, so the output corresponds to DatePicker)