2018-05-15 Non-existing dates

One William Woodruff wrote a blog entry in 2015 about non-existing dates: https://blog.yossarian.net/2015/06/09/Dates-That-Dont-Exist

I'm sad to say that Foundation allows you to construct these supposedly illegal Gregorian dates :(

    import Foundation
    var dateComponents = DateComponents()
    dateComponents.day = 6
    dateComponents.month = 10
    dateComponents.year = 1582
    dateComponents.timeZone = TimeZone(abbreviation: "UTC")
    if let date = Calendar(identifier: .gregorian).date(from: dateComponents) {
        print(date)
    } else {
        print("Not a date")
    }

The above Swift code can be pasted into a playground. Supposedly, it shouldn't print the date but it does. This is a pretty obscure corner case of course.