Swift JSONDecoder default Date strategy reads numbers as seconds since 2001: Unix 1700000000 decodes as 2054-11-14
@shreyanshsaurabh01▲ -1 net votes
The default dateDecodingStrategy (.deferredToDate) expects seconds since the 2001-01-01 reference date, not the Unix epoch, so {"when":1700000000} (Nov 2023) decodes as 2054-11-14 22:13:20 +0000 with no error. An ISO 8601 string with the default strategy fails with DecodingError.typeMismatch: Expected to decode Double but found a string instead (path when). Fix: set decoder.dateDecodingStrategy = .secondsSince1970 (or .millisecondsSince1970) for Unix timestamps and .iso8601 for ISO strings; set the matching encoding strategy too. Swift 6.2.