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 selection of the current day #877

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ internal actual object PlatformDateFormat {
val nsDate = NSDate.dateWithTimeIntervalSince1970(utcTimeMillis / 1000.0)

return NSDateFormatter().apply {
setTimeZone(TimeZone.UTC.toNSTimeZone())
setLocale(locale)
setLocalizedDateFormatFromTemplate(skeleton)
}.stringFromDate(nsDate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal actual object PlatformDateFormat {

val date = Instant
.fromEpochMilliseconds(utcTimeMillis)
.toLocalDateTime(TimeZone.currentSystemDefault())
.toLocalDateTime(TimeZone.UTC)

val jsDate = Date(utcTimeMillis)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,45 @@ internal class KotlinxDatetimeCalendarModelTest {
.isEqualTo(date.format(model, "yMMMd", locale))
}

@Test
fun formatDate_differentTZ() {

if (!supportsDateSkeleton)
return

val defaultTz = getTimeZone()

val locale = calendarLocale("en","US")

val date =
CalendarDate(
year = 2022,
month = 1,
dayOfMonth = 1,
utcTimeMillis = January2022Millis
)

val test = {
assertThat(model.formatWithSkeleton(date, "yMMMd", locale)).isEqualTo("Jan 1, 2022")
assertThat(model.formatWithSkeleton(date, "dMMMy", locale)).isEqualTo("Jan 1, 2022")
assertThat(model.formatWithSkeleton(date, "yMMMMEEEEd", locale))
.isEqualTo("Saturday, January 1, 2022")
// Check that the direct formatting is equal to the one the model does.
assertThat(model.formatWithSkeleton(date, "yMMMd", locale))
.isEqualTo(date.format(model, "yMMMd", locale))
}

setTimeZone("GMT-5")

test()

setTimeZone("GMT+5")

test()

setTimeZone(defaultTz)
}

@Test
fun formatMonth() {

Expand All @@ -273,6 +312,36 @@ internal class KotlinxDatetimeCalendarModelTest {
.isEqualTo(month.format(model, "yMMMM", locale))
}

@Test
fun formatMonth_differentTz() {

if (!supportsDateSkeleton)
return
val defaultTz = getTimeZone()


val locale = calendarLocale("en", "US")
val month = model.getMonth(year = 2022, month = 3)

val test = {
assertThat(model.formatWithSkeleton(month, "yMMMM", locale)).isEqualTo("March 2022")
assertThat(model.formatWithSkeleton(month, "MMMMy", locale)).isEqualTo("March 2022")
// Check that the direct formatting is equal to the one the model does.
assertThat(model.formatWithSkeleton(month, "yMMMM", locale))
.isEqualTo(month.format(model, "yMMMM", locale))
}

setTimeZone("GMT-5")

test()

setTimeZone("GMT+5")

test()

setTimeZone(defaultTz)
}

@Test
fun weekdayNames() {
// Ensure we are running on a US locale for this test.
Expand Down