Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #882 happened again in 1.2.0-beta01 #1360

Closed
Vadim-Smirnov opened this issue Jun 2, 2020 · 17 comments
Closed

Issue #882 happened again in 1.2.0-beta01 #1360

Vadim-Smirnov opened this issue Jun 2, 2020 · 17 comments
Assignees
Labels

Comments

@Vadim-Smirnov
Copy link

Datepicker to highlight wrong the day as today

@Vadim-Smirnov Vadim-Smirnov changed the title Issue #882 happened again Issue #882 happened again in 1.2.0-beta01 Jun 2, 2020
@ColtonIdle
Copy link

I see that #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
Copy link

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

@Vadim-Smirnov
Copy link
Author

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

@DvTonder
Copy link

DvTonder commented Jun 3, 2020

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

@postfixNotation
Copy link

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

@Manu-Jindal
Copy link

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
Copy link
Contributor

wcshi commented Jun 16, 2020

Hi @Manu-Jindal this commit (712a2ce) 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:
#824 (comment)

@Manu-Jindal
Copy link

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

@ed-george
Copy link

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
Copy link

Abu-Abdullah commented Jul 25, 2020

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
Copy link
Contributor

ymarian commented Jul 30, 2020

@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 ymarian closed this as completed Jul 30, 2020
@Abu-Abdullah
Copy link

@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
Copy link

aoben10 commented Aug 3, 2020

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
Copy link

VincentJoshuaET commented Jan 14, 2021

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

@vishalpatel1327
Copy link

vishalpatel1327 commented Mar 25, 2021

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
Copy link

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
Copy link

NonCoderF commented May 7, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests