Description of Problem:
I have a flight logging app and log all date and time in UTC timezone. The pseudo code is as follows:
datePicker.preferredDatePickerStyle = .compact
datePicker.date = Date.now
datePicker.timeZone = TimeZone(identifier: "UTC")
Most of the time, when I click the label, it opens the calendar-style view as the current month.
However, if the "local date" of the device is +1 day of the UTC date. It opens the calendar-style view as the "last month". For example, if current time is January 15th, 2023 1:05 (AM) in Japan/Tokyo, the UTC time will be January 14th, 2023 16:05. The bug will appear.
How to reproduce:
- Set the device timezone to Tokyo/Japan (UTC+0900). Set the local time to 1:05AM of January 15th, 2023.
- Create a UIDatePicker with style .compact, date to "now", and its timezone to "UTC".
- Click the datepicker, and a calendar-style view will show.
Result expected: The view shows the month of January 2023, with January 15th selected.
Result actually shown: The view shows month of "last" month (December 2022). However, when I scroll to next month, January 15th is already selected anyway.
If you're timezone is Tokyo/Japan (UTC+0900), you can expect this bug when the time is between 12:00AM-08:59AM. Since during this 9 hours period, the date is +1 later then UTC date.
I believe it's a bug, so I filed a bug report with ID FB11946646