react-native-date-picker icon indicating copy to clipboard operation
react-native-date-picker copied to clipboard

Android: onDateChange won't trigger when I select past 1 hour. but it was working fine if i select past more than 1 hour

Open ewu-tarun opened this issue 7 years ago • 13 comments

ewu-tarun avatar Jul 18 '19 05:07 ewu-tarun

Hi @TarunDas005. I don't manage to reproduce this, please provide example code which reproduces the issue.

henninghall avatar Jul 23 '19 21:07 henninghall

@henninghall, I can also reproduce this and it happens only on Android.

For me it happens when changing specifically time picker's hour wheel on first render (so date is initially provided in code) from 11 AM to 12 PM (am/pm changes automatically) or 1PM to 12 PM.

Would be great if fix for this issue was released as a hot fix before migrating to RN 60.x.

Aurintas avatar Jul 24 '19 09:07 Aurintas

@henninghall, Please check @Aurintas comments. I found this in the same scenario

ewu-tarun avatar Jul 25 '19 02:07 ewu-tarun

@henninghall Another case is when changing time picker's hour wheel on the first render (so the date is initially provided in code) from 11 AM to 10 AM. Could you please fix this issue and update the library?

ewu-tarun avatar Jul 25 '19 03:07 ewu-tarun

Thanks guys for further explanation. I will hopefully be able too look into it within a week. Please feel free to send a pull request if you find a solution yourselves!

henninghall avatar Jul 25 '19 12:07 henninghall

@TarunDas @Aurintas I am still not able to reproduce it. Could you please provide a code sample? I have tried the following:

import React, { Component } from 'react';
import DatePicker from 'react-native-date-picker';

const initialDate = new Date()
initialDate.setHours(12)

export default class MinimalExample extends Component {

  state = { date: initialDate }

  render = () =>
    <DatePicker
      date={this.state.date}
      onDateChange={date => {
        this.setState({ date })
        console.log("onDateChange", date);
      }} 
    />

}

henninghall avatar Jul 26 '19 15:07 henninghall

@henninghall set DatePicker to mode="time" and try using this date as initial:

const initialDate = new Date("Mon Jul 29 2019 12:20:00 GMT+0300 (EEST)");

In this scenario, changing from 12 PM to 11 AM does not call onDateChange callback for me.

Aurintas avatar Jul 29 '19 08:07 Aurintas

const initialDate = new Date("Mon Jul 29 2019 12:20:00 GMT+0300 (EEST)");

That line will still show different initial hour depending on the time zone you are in. I will appreciate if you can reproduce it by using for example initialDate.setHours(12) instead. Or tell me your time zone?

I still don't manage to reproduce it, let me once again ask again for a full sample? It would help a lot. Thanks.

henninghall avatar Jul 29 '19 17:07 henninghall

"Europe/Vilnius" timezone, -180 offset

Aurintas avatar Jul 30 '19 06:07 Aurintas

@Aurintas Still not getting it. I have sat Europe/Vilnius as my timezone and running following example:

import React, { Component } from "react";
import { Text, View } from "react-native";
import DatePicker from "react-native-date-picker";

const initialDate = new Date("Mon Jul 29 2019 12:20:00 GMT+0300 (EEST)");

export default class MinimalExample extends Component {
  state = { date: initialDate };

  render = () => (
    <View>
      <Text>{this.state.date.toISOString()}</Text>
      <DatePicker
        date={this.state.date}
        mode="time"
        onDateChange={date => {
          this.setState({ date });
          console.log("onDateChange", date);
        }}
      />
    </View>
  );
}

Could you please confirm that you getting the error with that sample code?

henninghall avatar Jul 31 '19 16:07 henninghall

@henninghall Thank you for taking time to look at this.

We've noticed that it depends on device time. Basically, it works incorrectly when you change hours wheel to currently set device time (hour).

So the issue is seen if it's 1 PM (device time), initial date is set to 2 PM and I scroll hours wheel to 1 PM (one step upwards). Same if it's 2 PM, initial date 3 PM and scroll to 2 PM. And so on.

This time issue persists even when using setHours on new Date().

Aurintas avatar Aug 02 '19 11:08 Aurintas

@Aurintas Thanks for helping out investigating this. I now managed to track down the issue, will make a new release with this fix within a couple of days!

henninghall avatar Aug 04 '19 20:08 henninghall

Released in v2.6.1

henninghall avatar Aug 05 '19 21:08 henninghall