capacitor-community / date-picker

Native DateTime Picker Plugin for Capacitor Apps
MIT License
87 stars 29 forks source link

Date doesn't change when mode is dateAndTime #39

Open steve-allam opened 3 years ago

steve-allam commented 3 years ago

Describe the bug The date does not change when mode "dateAndTime" is used (and there is an initial date in options) in DatePickerPlugin.java, on completion of the DatePickerDialog, if mode is dateAndTime, the routine 'launchTime()' is called.

The first thing launchTime does is:

if (pickerDate != null) {
        calendar.setTime(parseDateFromString(pickerDate));
    } 

This sets the time from the pickerDate variable, which is the input date to the whole component, hence ignoring any changes that might have been made by the DatePickerDialog. The same logic is repeated a bit further down in the same function.

If changed to:

if (pickerMode.equals("time") && (pickerDate != null)) { calendar.setTime(parseDateFromString(pickerDate)); }

Then all is ok.

To Reproduce Steps to reproduce the behavior:

var opts:DatePickerOptions = { date: "2021-04-17T20:00", mode: "dateAndTime", format:"yyyy-MM-dd'T'HH:mm", theme: "light", is24h: true }; DatePicker.present(opts).then((res) => { console.log('date result'+JSON.stringify(res)); });

  1. Change the date.
  2. Change the time, if you want.
  3. You will see that the time has changed, but the date is still 17th April.

Expected behavior The date to change!

Additional context "@capacitor-community/date-picker": "^0.2.3", "@capacitor/android": "^2.4.7", "@capacitor/cli": "^2.4.7", "@capacitor/core": "^2.4.7", "@ionic-native/core": "^5.32.0",

danielprrazevedo commented 3 years ago

Is this only in dateAndTime mode?

steve-allam commented 3 years ago

Hi,

Yes it is. It is the transition between the date picker and time picker that the issue occurs, the time picker takes the original input date which overwrites any change made in the date picker

Regards,

Steve

Steve Allam | Director | Imhotek UK Ltd Mob: 07976 522793 Shamelessly advertising my son's T-shirts at: shop.boldpen.uk

On 18 April 2021 00:06:33 Daniel Pereira @.***> wrote:

Is this only in dateAndTime mode? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

samarties commented 3 years ago

This is fixed by https://github.com/capacitor-community/date-picker/pull/35

mariusvn commented 2 years ago

i confirm but it still needs to be updated on npm