UIDatePicker modal view show incorrect (last) month

84 Views Asked by At

My UIDatePicker (with style .compact) is set to Today by default, and always in timezone UTC.

    cell.datePicker.subviews[0].backgroundColor = nil
    cell.datePicker.backgroundColor = .secondarySystemGroupedBackground
    cell.datePicker.timeZone = TimeZone(identifier: "UTC")
    cell.datePicker.date = flight.date
    cell.datePicker.addTarget(self, action: #selector(handleDatePicker(sender:)), for: UIControl.Event.valueChanged)

After clicking on the textfield "Jan 11, 2023", it will show a calendar-style editor. However, the date was set to today (Jan 11, 2023), but it shows the month of "December 2022" initially.

incorrect calendar view

After I click the arrow (next month), the date (Jan 11) was pre-selected correctly.

pre-set date

The expected behavior should be after clicking the text "Jan 11, 2023", the month of "Jan 2023" is shown with Jan 11 pre-selected. This bug can only be re-produced if the date is set to "today", but the UTC date and the local date are different. For example, I'm in UTC+8 timezone. The date is set to "2023-01-11 17:30:00 +0000". When the UTC time is Jan 11, 2023 17:30Z, and the local time is Jan 12, 2023 01:30L. It will show "December 2022" when the modal view first shown.

1

There are 1 best solutions below

0
benck On

This is a confirmed bug before iOS 16.4. Three months after reported through Apple Feedback with ID FB11946646, the bug is now resolved since iOS 16.5 beta 2.