Material-components-android: [DatePicker] Wrong selected date text show when selected earlier date

Created on 29 Aug 2019  路  14Comments  路  Source: material-components/material-components-android

Description:
When you selected date, the date text would show in the selected date area like "Aug 29, 2019".

But if you selected an earlier date, for example, 1900-01-05, the date text will be "Jan 4, 1900" which is a wrong text.

Expected behavior:
Select 1900-01-05 and show the text "Jan 5, 1900".

Source code:
Use the official demo.

Android API version:
Android P

Material Library version:
1.1.0-alpha09

Device:
Oppo R15

bug

Most helpful comment

@ldjcmu Please take into consideration that working with dates shouldn't be that hard and that sometimes simpler is better. In this case year/month/day solution is the absolute simplest API. Then it's up to the developer to handle date and time operations, which are super complex, especially when timezones are involved.

Better to have an API that doesn't introduce the complexity of date time operations. It makes the MaterialdatePicker implementation really difficult to use.

All 14 comments

Hi hvsimon,

I think this issue might be related to timezones or a day boundary. Do you mind providing the timezone of your device and about what time of day you found this bug?

Hi hvsimon,

I think this issue might be related to timezones or a day boundary. Do you mind providing the timezone of your device and about what time of day you found this bug?

The timezone is UTC+8 and I found it at 14:12 UTC+8.

Hi hvsimon,

I've managed to repro this issue if I change the timezone while the demo is running, but not if I launch the demo with a new timezone set. Did you happen to change any system settings around the time you encountered this issue?

I can also reproduce this issue using the emulator.

Here are settings and result
image

image

Please restart(swipe to kill and open again) the demo app after change settings.

Not all text are wrong. The day after 1937-10-02 (include) is correct. Otherwise is wrong.

Thanks for all of this information. We've tracked this down to an issue with how DateFormat parses dates. Specifically, for the value "-2208848400000", android.icu.text.DateFormat.YEAR_ABBR_MONTH_DAY (the implementation we try to use) returns text representing 1900-01-02 compared with java.text.DateFormat.MEDIUM which returns text representing 1900-01-03. android.icu.text.DateFormat appears to be off by an hour in its parsing.

Thanks for your diligent reporting and clear information. I'll update once we have a fix submitted.

This is fixed in the next release.

Is it fixed in 1.1.0-beta01 ?

It seems this bug is also on setSelection

calendar.timeInMillis ==> October 4
builder.setSelection(calendar.timeInMillis) I see October 3

Still having this issue.

Ok I fixed it by parsing my string date "20190101" using SimpleDateFormat and using the UTC timezone.

I think we need another way to set the selection date using month year day Ints or a string.....

I agree that the current use of long millis from the UTC timezone is not the simplest API. We want to use the new java8 time APIs (LocalDate), but can't do that upgrade right now. I'll see if we're ok adding a year/month/day version as an interim solution.

@ldjcmu Please take into consideration that working with dates shouldn't be that hard and that sometimes simpler is better. In this case year/month/day solution is the absolute simplest API. Then it's up to the developer to handle date and time operations, which are super complex, especially when timezones are involved.

Better to have an API that doesn't introduce the complexity of date time operations. It makes the MaterialdatePicker implementation really difficult to use.

I agree with you completely. We have to decide if the interim API is worth committing to for long-term support even though we want to use the java 8 time API.

I am not trying to arbitrarily make things more complex.

@ldjcmu After downloading AS 4.0 Canary I now understand why you've taken the direction you've taken. LocalDate is suddenly available for APIs below 26 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KelvinPac picture KelvinPac  路  3Comments

TdevM picture TdevM  路  3Comments

zkovar picture zkovar  路  3Comments

sepehr-alipour picture sepehr-alipour  路  3Comments

Sanusy picture Sanusy  路  3Comments