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

DatePicker. Fix today circle #782

Merged
merged 12 commits into from
Sep 5, 2023

Conversation

alexzhirkevich
Copy link

@alexzhirkevich alexzhirkevich commented Aug 31, 2023

Proposed Changes

  1. Fix one more bug from Kotlinx datetime CalendarModel (support date picker on darwin and web) #717 🥲.
    Today time millis should be at the midnight.
    Added the last test from Android that checks the equality of legacy and new models. Forgot to do it in the first PR.
    Prostite brakodela 🙏

  2. Use narrow weekdays format instead of short (as in non-legacy model on Android).
    It should be more consistent with Android 26+ (see screenshots from fixed issue).
    Also removed hardcoded weekdays names as all platforms have localized ones.

  3. Replace input format building with existing function from common (missed that it already exists). It should be more stable for unusual locales.

  4. atStartOfDay can produce non-midnight time. Some calendar model methods require midnight and some start of day. Aligned all methods with the newer android implementation

Testing

Test: EqualityOfCalendarModelsTest. This should protect from other bugs i believe

Issues Fixed

Fixes: JetBrains/compose-multiplatform#3591

@m-sasha
Copy link
Member

m-sasha commented Aug 31, 2023

@alexzhirkevich I started investigating before I noticed your PR.

Today time millis should be at the start of day.

Indeed, this seems to be the problem.

month = localDate.monthNumber,
dayOfMonth = localDate.dayOfMonth,
utcTimeMillis = localDate.date
.atStartOfDayIn(TimeZone.UTC)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://kotlinlang.org/api/kotlinx-datetime/kotlinx-datetime/kotlinx.datetime/at-start-of-day-in.html says atStartOfDay isn't necessarily at midnight, and we do want midnight here because of how isToday is computed:

val dateInMillis = month.startUtcTimeMillis + (dayNumber * MillisecondsIn24Hours)
val isToday = dateInMillis == today.utcTimeMillis

that's why I suggested to use atTime(0,0).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe both will be wrong, that is neither will match dateInMillis? I'm not sure. The way isToday is computed looks bad to me.

But Android uses

utcTimeMillis = systemLocalDate.atTime(LocalTime.MIDNIGHT)
                    .atZone(utcTimeZoneId).toInstant().toEpochMilli()

so maybe it's better to stick with that, unless you're sure atStartOfDayIn is correct.

Copy link
Author

@alexzhirkevich alexzhirkevich Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is what CalendarModel interface comments (from canonical date method) says about it:

* The returned date will hold milliseconds value that represent the start of the day, which may
* be different than the one provided to this function.

So it does not exactly say it needs to be 00:00, but start of day 🤔

Maybe today method should behave differently


Newer android calendar model takes it at midnight, lets do the same
(but canonical date it takes at start of day 🥲🔫)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aligned all methods with the Android implementation

@m-sasha
Copy link
Member

m-sasha commented Sep 5, 2023

@alexzhirkevich Would you like me to merge this?

@alexzhirkevich
Copy link
Author

@alexzhirkevich Would you like me to merge this?

Yep if everything looks good to you

@m-sasha m-sasha merged commit 8ee0520 into JetBrains:jb-main Sep 5, 2023
igordmn pushed a commit that referenced this pull request Jan 30, 2024
@alexzhirkevich alexzhirkevich deleted the today-circle-fix branch July 15, 2024 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Today's date is not highlighted with a circle in the material3 datePicker on iOS.
2 participants