ADDatePicker icon indicating copy to clipboard operation
ADDatePicker copied to clipboard

Error if iOS device preferred device language other than English

Open mkelitz opened this issue 7 years ago • 3 comments

Error if iOS device preferred device language other than English.

Easy t test, just switch language from device Settings > General > Language & Region > Make any other language first on Preferred Language order.

Date picker will report error "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value!" in CalendarHelper.swift "return date!" line 89

mkelitz avatar Jan 21 '19 16:01 mkelitz

Changing BDate.swift getMonths() class to the following fixes the issue

class func getMonths() -> [String]{ //return ["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"] let formatter = DateFormatter() let monthComponents = formatter.shortMonthSymbols return monthComponents! }

As it uses localised month short strings to visualise month in picker and uses same values to parse date from string in CalendarHelper.swift (let date = dateFormatter.date(from: "(currentMonth)/(currentDay)/(currentYear)"))

At least it works for me in Basque and Spanish

mkelitz avatar Jan 21 '19 17:01 mkelitz

In addition to the fix, now the months are shown in the language used by the user in the device (and not only in English like before)

mkelitz avatar Jan 21 '19 17:01 mkelitz

Hello @mkelitz The following fix will do the trick. Change the array to ["01", "02", "03"...."12"]. The date will still be recognizable & usable.

AgileFlex avatar Apr 02 '20 06:04 AgileFlex