{"action":"created","issue":{"url":"https://api.github.com/repos/contentful/contentful.swift/issues/188","repository_url":"https://api.github.com/repos/contentful/contentful.swift","labels_url":"https://api.github.com/repos/contentful/contentful.swift/issues/188/labels{/name}","comments_url":"https://api.github.com/repos/contentful/contentful.swift/issues/188/comments","events_url":"https://api.github.com/repos/contentful/contentful.swift/issues/188/events","html_url":"https://github.com/contentful/contentful.swift/issues/188","id":311955641,"number":188,"title":"Default date formatter fails to parse date in EntryDecodable models","user":{"login":"kedio","id":3375074,"avatar_url":"https://avatars0.githubusercontent.com/u/3375074?v=4","gravatar_id":"","url":"https://api.github.com/users/kedio","html_url":"https://github.com/kedio","followers_url":"https://api.github.com/users/kedio/followers","following_url":"https://api.github.com/users/kedio/following{/other_user}","gists_url":"https://api.github.com/users/kedio/gists{/gist_id}","starred_url":"https://api.github.com/users/kedio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kedio/subscriptions","organizations_url":"https://api.github.com/users/kedio/orgs","repos_url":"https://api.github.com/users/kedio/repos","events_url":"https://api.github.com/users/kedio/events{/privacy}","received_events_url":"https://api.github.com/users/kedio/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2018-04-06T12:23:45Z","updated_at":"2018-05-03T19:04:57Z","closed_at":"2018-04-11T09:26:18Z","author_association":"NONE","body":"<!--\r\nPlease follow the instructions below before filing a new issue.\r\n\r\nPlease ensure that you are at least on the newest minor version of the SDK.\r\nThe minor version is delineated in the following example with an `x`: `0.x.11`\r\n\r\nThere are many changes to the Swift language and Xcode that are not backwards compatible\r\nand versions of Swift < 3 and versions of Xcode < 8 are not supported by Contentful.\r\nSwift package manager is not yet supported.\r\n-->\r\n\r\n> - contentful.swift version number: 1.0.1\r\n> - Xcode version number: 9.3\r\n> - Target operating system(s) and version number(s)\r\n    - [X ] iOS: \r\n    - [ ] tvOS: \r\n    - [ ] watchOS:\r\n    - [ ] macOS:\r\n> - Package manager:\r\n    - [X ] Carthage\r\n    - [ ] Cocoapods\r\n\r\n<!-- Enter your issue details below this comment. -->\r\nWhen fetching entries which have a date in their model (using EntryDecodable), the default date formatter fails to parse the date.\r\n\r\nSo trying to `fetchMappedEntry` using this model.\r\n\r\n```\r\nfinal class ContentfulTournament: EntryDecodable, ResourceQueryable, Tournament {\r\n    static var contentTypeId = \"tournament\"\r\n    \r\n    let sys: Sys\r\n    let startDate: Date\r\n\r\n    required init(from decoder: Decoder) throws {\r\n        sys = try decoder.sys()\r\n        \r\n        let fields = try decoder.contentfulFieldsContainer(keyedBy: Fields.self)\r\n        startDate = try fields.decode(Date.self, forKey: .startDate)\r\n    }\r\n}\r\n\r\nextension ContentfulTournament {\r\n    enum Fields: String, CodingKey {\r\n        case startDate\r\n    }\r\n}\r\n```\r\n\r\nWould fail with error: \r\n```\r\nThe SDK was unable to parse the JSON: dataCorrupted(Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: \\\"Index 0\\\", intValue: 0), Fields(stringValue: \\\"startDate\\\", intValue: nil)], debugDescription: \\\"Date string does not match format expected by formatter.\\\", underlyingError: nil))\r\n```\r\n\r\nBut getting the date string and parsing it would give the expected result.\r\n\r\n```\r\nfinal class ContentfulTournament: EntryDecodable, ResourceQueryable, Tournament {\r\n    static var contentTypeId = \"tournament\"\r\n    \r\n    let sys: Sys\r\n    let startDate: Date\r\n\r\n    required init(from decoder: Decoder) throws {\r\n        sys = try decoder.sys()\r\n        \r\n        let fields = try decoder.contentfulFieldsContainer(keyedBy: Fields.self)\r\n        let startDateString = try fields.decode(String.self, forKey: .startDate)\r\n\r\n        let formatter = DateFormatter()\r\n        formatter.dateFormat = \"yyyy-MM-dd'T'HH:mmZ\"\r\n        startDate = formatter.date(from: startDateString)!\r\n    }\r\n}\r\n\r\nextension ContentfulTournament {\r\n    enum Fields: String, CodingKey {\r\n        case startDate\r\n    }\r\n}\r\n```\r\n\r\nThe date string recieved: `2018-05-05T08:30-03:00`\r\n\r\nShould this work out of the box?\r\nIs it possible to change the client date formatter?"},"comment":{"url":"https://api.github.com/repos/contentful/contentful.swift/issues/comments/386403357","html_url":"https://github.com/contentful/contentful.swift/issues/188#issuecomment-386403357","issue_url":"https://api.github.com/repos/contentful/contentful.swift/issues/188","id":386403357,"user":{"login":"kedio","id":3375074,"avatar_url":"https://avatars0.githubusercontent.com/u/3375074?v=4","gravatar_id":"","url":"https://api.github.com/users/kedio","html_url":"https://github.com/kedio","followers_url":"https://api.github.com/users/kedio/followers","following_url":"https://api.github.com/users/kedio/following{/other_user}","gists_url":"https://api.github.com/users/kedio/gists{/gist_id}","starred_url":"https://api.github.com/users/kedio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kedio/subscriptions","organizations_url":"https://api.github.com/users/kedio/orgs","repos_url":"https://api.github.com/users/kedio/repos","events_url":"https://api.github.com/users/kedio/events{/privacy}","received_events_url":"https://api.github.com/users/kedio/received_events","type":"User","site_admin":false},"created_at":"2018-05-03T19:04:57Z","updated_at":"2018-05-03T19:04:57Z","author_association":"NONE","body":"Hi @loudmouth , sorry for the delay I just had the chance to update to v2.0.1 and try the variableISO8601Strategy. I was able to decode my objects directly without any modifications to the decoder. Nice! \r\n\r\nBut I get unexpected results. It seems to be TimeZone related because I get the right date one day earlier when the time is set to 00:00. I dived a bit into the code and I think it may be related to this [part.](https://github.com/contentful/contentful.swift/blob/bcf2808cf2a51543fc3a755663b47d67c3a1b42e/Sources/Contentful/Date.swift#L58) \r\n\r\nThe loop will stop with the first successful format, but the least specific format (\"yyyy-MM-dd\") seems to be one of the first in the list so it will most likely parse the date using \"yyyy-MM-dd\" and discard the TimeZone value.\r\n\r\nLet me know what you think!"}}
{"actor":{"display_login":"kedio"}}