For a client of mine I'm working with really old dates like for example:
- 0572-06-17
- 1000-06-17
When I convert the string to a date it has a weird timezone. Example:
extension String {
func yearMonthDayDate() -> Date? {
return DateFormatter.yearMonthDayFormatter.date(from: self)
}
}
extension DateFormatter {
static let yearMonthDayFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.timeZone = .current
dateFormatter.dateFormat = "yyyy-MM-dd"
dateFormatter.locale = .current
return dateFormatter
}()
}
extension Date {
func zonedDate() -> String {
let dateFormatter = DateFormatter()
dateFormatter.timeZone = .current
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssXXX"
dateFormatter.locale = .current
return dateFormatter.string(from: self)
}
}
print("1000-06-17".yearMonthDayDate()!.zonedDate())
1000-06-17T00:00:00+00:17
Like you can see the timezone is +00:17. Why is this weird timezone showing up?