0

In my app, users can pick a "duration". I am using a UIDatePicker with datePickerMode set to time for this.

  • In order to pick 0-24h, I set the date picker locale to e.g. NL like explained here.
  • Because I want to show the picker in a list, I use compact for the preferredDatePickerStyle
  • In order to make it easier for the user to pick a duration, I set minuteInterval to 5

Now, when using this on a device that has 12h time display in the iOS settings, this causes the expanded date picker to only offer hours from 1-12, instead of 0-23.

Interestingly, this problem does not occur when the device is set to 24h time display or I am using any other value for the minuteInterval (e.g. 10) or I am using a different preferredDatePickerStyle (e.g. inline)

Is this an iOS bug and is there any workaround?

tipa
  • 369
  • 1
  • 5
  • 17
  • Are you sure you have set the picker style to compact? If you do then you will get a runtime exception stating that compact style is not supported with count down timer mode. Using the `.automatic` style works correctly for me on a device with 12 hour time preference (without needing to change the locale of the picker) – Paulw11 Apr 14 '21 at 11:15
  • I have set the datePickerMode to "time", not "countdown". When using "automatic" style, the pickers displays as "compact" and the problem is happening, just like when I set it to "compact" explicitly. – tipa Apr 14 '21 at 11:32
  • Looks like a bug to me, although forcing 24 hour time through a locale is a bit of a hack anyway. – Paulw11 Apr 14 '21 at 12:04
  • Agreed that it is hacky, but it worked pretty well, expect in this specific configuration with the minuteInterval set to 5 – tipa Apr 14 '21 at 14:25

0 Answers0