(Android) PICKER_TYPE_DATE_AND_TIME Picker shows date - 1 day when editing
This is a strange one. I could have sworn that this wasn't happening before, but I don't see any change affecting the Picker in the commits. The following minimal code reproduces the issue:
Form hi = new Form("Test", new BorderLayout());
Container center = new Container(BoxLayout.y());
Picker startDateTimePicker = new Picker();
startDateTimePicker.setType(Display.PICKER_TYPE_DATE_AND_TIME);
startDateTimePicker.setDate(new Date());
center.add(startDateTimePicker);
hi.add(BorderLayout.CENTER, center);
hi.show();
Using this code, when the picker displays the following example date:
It then shows this other date when tapped and starting to edit:

From what I have seen, it doesn't always happen. I would say 90% of times. Race condition?
I know we are in code freeze but it would be great if this very small issue could be fixed. I've pasted very detailed code on how to reproduce here. I tried fixing myself but unfortunately couldn't figure it out. Perhaps the person who first developed this one can help more, hopefully it will be an easy win
As of today, this is still happening
Is this only happening in Android, or can you reproduce it in the simulator?
This also happens in the simulator
Tried this test case today and couldn't reproduce it. I also stepped through the code and wasn't able to identify where this would be happening. Could be timezone related. Tried in a few different timezones with no results.
https://user-images.githubusercontent.com/11293898/143045753-e460b720-5999-4d80-a624-bfa1be135566.mp4
Here is the result of the code above. As it can be seen, each time the picker is tapped, the edit panel switches to date - 1 day My time zone is UTC +00
@shannah I was able to fix this in my own version of CN1. The problem is that the selected index of the spinner is calculated and then truncated, not rounded. Would be good to fix in CN1's code. The line here needs to be changed from
int out = (int)((currentValue - min) / DAY);
to
int out = (int) Math.round((new Long(this.currentValue).doubleValue() - new Long(this.min).doubleValue()) / new Long(DAY).doubleValue());
Testing this requires choosing dates in the future incrementally, one day at a time. Faulty results may not be obtained until 40+ days are tested, but it could be more. Because of how the value is truncated, depending on the time of day different results will be obtained too. But the above code fixes this teething issue
Actually scrap this. The error still persists (now adding a day instead of subtracting)
I managed to fix this but the solution is ugly and not worth sharing. Basically, I run an extra check to see if the date is as intended and if it isn't I move the date to +-1 day as needed before showing the dialog (in SpinnerDateModel)