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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import kotlin.js.Date
import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDate
import kotlinx.datetime.TimeZone
import kotlinx.datetime.atStartOfDayIn
import kotlinx.datetime.atTime
import kotlinx.datetime.toInstant
import kotlinx.datetime.toLocalDateTime

internal actual object PlatformDateFormat {
Expand Down Expand Up @@ -151,7 +152,8 @@ internal actual object PlatformDateFormat {

return LocalDate(
year, month, day
).atStartOfDayIn(TimeZone.UTC)
).atTime(hour = 0, minute = 0)
.toInstant(TimeZone.UTC)
.toCalendarDate(TimeZone.UTC)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import kotlinx.datetime.Clock
import kotlinx.datetime.DatePeriod
import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalTime
import kotlinx.datetime.Month
import kotlinx.datetime.TimeZone
import kotlinx.datetime.atStartOfDayIn
Expand All @@ -31,6 +32,8 @@ import kotlinx.datetime.toLocalDateTime

internal class KotlinxDatetimeCalendarModel : CalendarModel {

private val midnight = LocalTime(0,0)
alexzhirkevich marked this conversation as resolved.
Show resolved Hide resolved

override val today: CalendarDate
get() {
val localDate = Clock.System.now().toLocalDateTime(systemTZ)
Expand All @@ -39,7 +42,8 @@ internal class KotlinxDatetimeCalendarModel : CalendarModel {
month = localDate.monthNumber,
dayOfMonth = localDate.dayOfMonth,
utcTimeMillis = localDate.date
.atStartOfDayIn(TimeZone.UTC)
.atTime(midnight)
.toInstant(TimeZone.UTC)
.toEpochMilliseconds()
)
}
Expand Down Expand Up @@ -86,7 +90,8 @@ internal class KotlinxDatetimeCalendarModel : CalendarModel {
year = year,
monthNumber = month,
dayOfMonth = 1,
).atStartOfDayIn(TimeZone.UTC)
).atTime(midnight)
.toInstant(TimeZone.UTC)

return getMonth(instant.toEpochMilliseconds())
}
Expand All @@ -105,7 +110,8 @@ internal class KotlinxDatetimeCalendarModel : CalendarModel {
.toLocalDateTime(TimeZone.UTC)
.date
.plus(DatePeriod(months = addedMonthsCount))
.atStartOfDayIn(TimeZone.UTC)
.atTime(midnight)
.toInstant(TimeZone.UTC)
.toCalendarMonth(TimeZone.UTC)
}

Expand Down Expand Up @@ -145,7 +151,8 @@ internal class KotlinxDatetimeCalendarModel : CalendarModel {
daysFromStartOfWeekToFirstOfMonth = monthStart
.daysFromStartOfWeekToFirstOfMonth(),
startUtcTimeMillis = monthStart
.atStartOfDayIn(TimeZone.UTC)
.atTime(midnight)
.toInstant(TimeZone.UTC)
.toEpochMilliseconds()
)
}
Expand Down