material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

Issue #882 happened again in 1.2.0-beta01

Open Vadim-Smirnov opened this issue 6 years ago • 17 comments

Datepicker to highlight wrong the day as today

Vadim-Smirnov avatar Jun 02 '20 10:06 Vadim-Smirnov

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

ColtonIdle avatar Jun 03 '20 01:06 ColtonIdle

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

b95505017 avatar Jun 03 '20 04:06 b95505017

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

Vadim-Smirnov avatar Jun 03 '20 07:06 Vadim-Smirnov

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

DvTonder avatar Jun 03 '20 23:06 DvTonder

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

postfixNotation avatar Jun 04 '20 14:06 postfixNotation

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

Manu-Jindal avatar Jun 14 '20 11:06 Manu-Jindal

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

wcshi avatar Jun 16 '20 14:06 wcshi

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

Manu-Jindal avatar Jun 17 '20 12:06 Manu-Jindal

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?

ed-george avatar Jul 07 '20 11:07 ed-george

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

Abu-Abdullah avatar Jul 25 '20 04:07 Abu-Abdullah

@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.

ymarian avatar Jul 30 '20 15:07 ymarian

@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

Abu-Abdullah avatar Jul 30 '20 15:07 Abu-Abdullah

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

aoben10 avatar Aug 03 '20 19:08 aoben10

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

VincentJoshuaET avatar Jan 14 '21 03:01 VincentJoshuaET

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

vishalpatel1327 avatar Mar 25 '21 12:03 vishalpatel1327

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.

ubuntudroid avatar Mar 22 '22 10:03 ubuntudroid

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_global_okay)) { _, 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

NonCoderF avatar May 07 '24 05:05 NonCoderF