Skip to content

Commit d58c6ca

Browse files
authored
Merge pull request #44 from PureSwift/feature/datepicker-locale
2 parents 94c2038 + 625fdd5 commit d58c6ca

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

  • Demo/swiftui/src/commonMain/kotlin/com/pureswift/swiftui

Demo/swiftui/src/commonMain/kotlin/com/pureswift/swiftui/Render.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -529,15 +529,13 @@ private fun RenderDatePicker(node: ViewNode) {
529529
}
530530
}
531531

532-
private val monthAbbreviations = arrayOf("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
533-
532+
// Formats the selection in the device locale's medium date style (e.g.
533+
// "Jul 23, 2026", "23 juil. 2026", "2026/07/23"). UTC matches the epoch-millis
534+
// the DatePicker and Foundation's Date both use.
534535
private fun formatDateMillis(millis: Long): String {
535-
val calendar = java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone("UTC"))
536-
calendar.timeInMillis = millis
537-
val month = monthAbbreviations[calendar.get(java.util.Calendar.MONTH)]
538-
val day = calendar.get(java.util.Calendar.DAY_OF_MONTH)
539-
val year = calendar.get(java.util.Calendar.YEAR)
540-
return "$month $day, $year"
536+
val format = java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM)
537+
format.timeZone = java.util.TimeZone.getTimeZone("UTC")
538+
return format.format(java.util.Date(millis))
541539
}
542540

543541
// A trigger button opening a dropdown; each child Button becomes a menu item

0 commit comments

Comments
 (0)