Work around the bug in ComposeScheduleView, fix #1720 (#1722)

DatePicker seems to think that it's in UTC. So setting selected time
might not work as aspect and receiving value from it might be in UTC
as well. This commit fixes the second issue by interpreting the date
as UTC date. Tested with America/New_York (GMT-5 at the moment) and
Russia/Kamchatka (GMT+12).
This commit is contained in:
Ivan Kupalov 2020-03-09 20:43:01 +01:00 committed by GitHub
parent 91dd3e4f5f
commit 6a87e3e352
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -192,6 +192,9 @@ public class ComposeScheduleView extends ConstraintLayout {
private void onDateSet(long selection) { private void onDateSet(long selection) {
initializeSuggestedTime(); initializeSuggestedTime();
Calendar newDate = getCalendar(); Calendar newDate = getCalendar();
// working around bug in DatePicker where date is UTC #1720
// see https://github.com/material-components/material-components-android/issues/882
newDate.setTimeZone(TimeZone.getTimeZone("UTC"));
newDate.setTimeInMillis(selection); newDate.setTimeInMillis(selection);
scheduleDateTime.set(newDate.get(Calendar.YEAR), newDate.get(Calendar.MONTH), newDate.get(Calendar.DATE)); scheduleDateTime.set(newDate.get(Calendar.YEAR), newDate.get(Calendar.MONTH), newDate.get(Calendar.DATE));
openPickTimeDialog(); openPickTimeDialog();