Bug in iOS 18 with NSTimeZone and DatePicker

iOS 18 broke some functionality in my Objective-C app with regard to using the DatePicker.

The key lines are as follows:

datePicker.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:timezoneOffset];
datePicker.date = [NSDate date];

When timezoneOffset is -29380, the value for San Francisco, the Date Picker is a whole MONTH off. It shows November instead of December.

But when it is -29359, the value for Seattle, which is in the same time zone (PST), it shows the correct month. In fact, even towns surrounding San Francisco usually return the correct value. Some other cities in other time zones also cause the Date Picker to be a month off.

Which date picker are you talking about here?

Your tagged your thread with AppKit, which suggests NSDatePicker. But then you talk about iOS, and NSDatePicker isn’t available on that platform. Are you using UIDatePicker? Or SwiftUI?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I’m wondering about the purpose of those weird offset values, since they represent the offset in mean solar time at the longitude of those cities rather than official time zones. It’s not inconceivable that some bug exists somewhere in handling nonstandard time zone offsets like that.

It’s better to reply as a reply. See Quinn’s Top Ten DevForums Tips for this and other titbits.

UIDatePicker

OK. I retagged your thread accordingly.

it wasn't an issue before iOS18.

Unfortunately that doesn’t help us understand the root cause of this; time zones are complex enough that there’s plenty of scope for undefined behaviour.

Can you elaborate on what you mean by this?

But when it is -29359, the value for Seattle, which is in the same time zone (PST)

Seattle and SF are in the same time zone, so why would they have different timezoneOffset values?

Also, what does -29359 even mean? It translates to -8.1527… hours, which isn’t a meaningful time zone offset.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Seattle and SF are in the same time zone, so why would they have different timezoneOffset values? Also, what does -29359 even mean? It translates to -8.1527… hours, which isn’t a meaningful time zone offset.

Since you are curious, this is an app I started developing in 2011, and it was beleaguered with every imaginable edge case with regard to time zones and daylight saving time. My app is all about converting solar time to whatever time zone you want to look at sometime from, in whatever calendar, in any time past or present, which often involves crossing every possible arbitrary human-made boundary in time and space.

Being able to create a standardized time zone based on the location (converted to seconds from GMT), allowed me to do certain data conversions to get the day without having to worry about whether or not daylight saving was in effect at one calendar date but not another that the date picker might choose.

And it worked fine for many years until the latest iOS. Presumably Apple had a reason for introducing the ability to create time zones based on seconds from GMT, and I found it useful. So, I hope that answers your question.

This bug continues to plague my app and I get complaints almost daily from users since iOS 18 came out.

What's really strange though is that the bug appears to be in the way the Date Picker handles the calendar set to this time zone in the appearance of the picker. The month set as February appears as January but returns as February, so it is as if the visual month is one off.

It would be a lot less weird if it was the day that was one off, but it's the month!

My app is all about converting solar time to whatever time zone you want to look at sometime from

Cool. I’ve been doing this a long time and I’m still regularly surprised by the creative way Apple’s developers use our APIs.

Given your unique requirements, I see a couple of paths forward:

  • You could file a bug about the change in behaviour in iOS 18.

  • You could change the way you use date picker. More on that below.

Or you could do both (-:

If you do file a bug, please post your bug number, just for the record.


My idea for the second option is to pin the date picker’s time zone to GMT and then translate the dates by your custom offset on the way in and out. That way you’re always using the date picker in the simplest possible way, one that it should be able to cope with.

One tricky part of this is that you only want to do it when you’re using a custom time zone. If you’re using a standard time zone, it’d be best to let the date picker see that. That way it’ll handle the various edge cases for that time zone. For example, if the time zone observers daylight saving time, the date picker won’t let the user choose a time that doesn’t exist.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi Quinn, thanks for the reply and suggestions. I did submit a bug on December 6. It is FB16060266. Please let me know if I need to resubmit the bug.

I did submit a bug on December 6. It is FB16060266.

Thanks for that.

Please let me know if I need to resubmit the bug.

No, your current bug should be fine.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Bug in iOS 18 with NSTimeZone and DatePicker
 
 
Q