react-native-datepicker icon indicating copy to clipboard operation
react-native-datepicker copied to clipboard

datepicker show Incorrect time

Open lossen opened this issue 7 years ago • 5 comments

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.

srdetryguio

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

  1. react-native -v: 0.46.4
  2. node -v: 8.2.0
  3. npm -v: 5.3.0
  4. yarn --version: 0.24.6
  5. target platform: Android | iOS
  6. operating system: Mac

lossen avatar Jan 31 '18 05:01 lossen

@lossen Have you solved your problem?

svlada avatar Apr 05 '18 13:04 svlada

Same problem here!

oldaccountmarco avatar Dec 10 '18 13:12 oldaccountmarco

How you implemented the code for the time selection picker.??

renishdeveloper avatar Dec 21 '18 07:12 renishdeveloper

I am also getting the same issue.

devprakashbinary avatar Dec 31 '19 10:12 devprakashbinary

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)

Garamani avatar Jun 11 '21 09:06 Garamani