material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.01k stars 3.03k forks source link

Issue #882 happened again in 1.2.0-beta01 #1360

Closed Vadim-Smirnov closed 3 years ago

Vadim-Smirnov commented 3 years ago

Datepicker to highlight wrong the day as today

ColtonIdle commented 3 years ago

I see that https://github.com/material-components/material-components-android/issues/882 is related to datepicker.

Can you try version 1.3.0-alpha01?

They just released it with a few fixes under the "MaterialDatePicker" category. Looks like this issue is in that list.

https://github.com/material-components/material-components-android/releases/tag/1.3.0-alpha01

b95505017 commented 3 years ago

@ColtonIdle It's the same commit cherry-pick to beta release, so nothing has changed.

Vadim-Smirnov commented 3 years ago

@ColtonIdle I see that they marked it as fixed, but really nothing changed.

DvTonder commented 3 years ago

The issue still exists for users in UTC + timezones like British standard time (UTC+1)

postfixNotation commented 3 years ago

I'm experiencing the same issue with 1.3.0-alpha01, I'm in Germany UTC+2.

Manu-Jindal commented 3 years ago

Even I am facing this problem, I am in India Timezone (GMT+5:30), and the current date is showing to be yesterdays date. @ymarian @wcshi, any idea when the change will be rolled out? Kindly try to look into this with priority as it is a production app where we are facing this issue.

Using version 1.3.0-alpha01

wcshi commented 3 years ago

Hi @Manu-Jindal this commit (https://github.com/material-components/material-components-android/commit/712a2ce92040b6fc90530ad853633ecd7f258dfc) was made after the 1.3.0-alpha01 cut. It is in our daily release, could you please try it to verify whether it fixes the problem you are facing? Here are some instructions for how to use the daily build: https://github.com/material-components/material-components-android/issues/824#issuecomment-567044986

Manu-Jindal commented 3 years ago

Hi @wcshi, it worked! Thanks a lot! :D

ed-george commented 3 years ago

Do we have any idea when this will make it into a release? It seems like the project is on roughly a monthly release cycle so can we expect this in July's release?

Abu-Abdullah commented 3 years ago

Hi @wcshi i used the material:1.3.0-alpha02 and it seems it solves one issue of highlighting the initial current day. on the other hand, it seems it still has an issue when i use setSelection(long ms). it is not accounting for the time zone offset and is selecting the day prior.

Update: It seems that the value returened from MaterialPickerOnPositiveButtonClickListener is in UTC timezone. is it all functions/logic behind MaterialDatePicker is based on UTC. can we initiate it with the local timezone

ymarian commented 3 years ago

@Abu-Abdullah It's simpler for us to maintain everything in UTC and let the client do conversions. Please let us now if any method is not document correctly.

Abu-Abdullah commented 3 years ago

@ymarian it is confusing that the data picker displays the dates in local and all of its setters/getters are in UTC. one would expect that when he select a date, he will get the time using the same time zone. i was getting the time with offset 4 hours and the date was wrong until i got the idea of UTC is applied in all APIs.

if it is complex as you said, at least such logic should be reflected in the documentations. for example MaterialPickerOnPositiveButtonClickListener is not mentioning anything about UTC

aoben10 commented 3 years ago

Still confused by this. So the picker displays UTC dates by default, and if we wanted to use date in local timezone, we would have to convert the selected date on the picker to local date. Wouldn't that mean the user could select a certain day and local time could show the previous day? Wouldn't that be confusing for the user?

Struggling to figure this one out

VincentJoshuaET commented 3 years ago

I think doing setSelection(${epochMilliInUTC} + TimeZone.getDefault().getOffset(epochMiliInUTC)) does the trick!

vishalpatel1327 commented 3 years ago

Having the same issue in material:1.3.0 ;( @wcshi

also tried material:1.3.0-alpha02 ,material:1.4.0-alpha01 not working suppose select today and open range picker it displays yesterday

ubuntudroid commented 2 years ago

I was confused by all of this as well and just want to sum up how to do things properly client side.

To properly set the selection in UTC:

MaterialDatePicker.Builder.datePicker()
    .setSelection(localTimeInMillis + TimeZone.getDefault().getOffset(localTimeInMillis))

To properly retrieve selection in local time:

val localTimeInMillis = selection - TimeZone.getDefault().getOffset(selection)

And I agree, this should really be part of the documentation.

NonCoderF commented 1 week ago

val finalDate = (SpecificDate?.time ?: 0L) val timeOffset = TimeZone.getDefault().getOffset(finalDate).toLong()

val datePicker = datePicker { this.date = finalDate + if (timeOffset > 0) timeOffset else - timeOffset this.validTo = Date().time + timeOffset this.positiveButton(context.getString(R.string.common_globalokay)) { , y -> val offset = TimeZone.getDefault().getOffset(y).toLong() val selectedDate = y + if (offset > 0) offset else - offset } } datePicker.safeShow((context as AppCompatActivity))

DatePicker is a wrapper DSL over the MaterialDialog......... The offset is added and subtracted accordingly. You guys can figure out the rest.....CHILLLLLL