Date format "dd-MMM-yyyy" for September now Sept. Not Sep so converting causes nil

Viewed 1188

Updated iPad to iOS 15.4.

Now String to Date conversion using DateFormatter returns nil when stored month format "MMM" = Sep.

Works ok when MMM Month = Sept.

Did work in iOS 15.3 and earlier.

Issue is that I have dates created and stored as dd-Sep-2021.

    let dateFormat = "dd-MMM-yyyy"
    let dateFormatter = DateFormatter()
    dateFormatter.calendar = Calendar(identifier: .iso8601)
    dateFormatter.dateFormat = dateFormat
    let startDate = dateFormatter.date(from: appStartDate) //Returns nil if “11-Sep-2021” and crashes
    print(String(describing: startDate))

Did some investigation with this code and found that Sept works and Sep doesn't.

    let x = "-Sep-2021" // This returns nil
    //let x = "-Sept-2021" // This works
    var z: String = ""
    let i = 1...30
    for n in i {
        z = String(n) + x
        guard let y = dateFormatter.date(from: z) else {
            print(String(n)) // will print if nil
            continue
        }
        print(\(String(describing: y))) //will print if string converted to date
    }

All other 3 character month formats work.

Any idea if things have changed?

0 Answers
Related