amplify-swift: AWSDateTime parsing fails (wrong format)
Describe the bug Datastore is unable to parse AWSDateTime fields.
To Reproduce Steps to reproduce the behavior:
- Create a model with a AWSDateTime field
- Fetch all data from server
- Models can’t be parsed…
DataStoreError: An error occurred syncing Message Caused by: DataStoreError: failed to process graphqlResponseData Caused by: APIError: failed to process graphqlResponseData Caused by: DataStoreError: Could not parse 2021-01-26T16:44Z as a Date using the ISO8601 format. Recovery suggestion: Check if the format used to parse the date is the correct one. Check TemporalFormat for all the options.
Expected behavior Got my models with the parsed dates
Environment(please complete the following information):
- Amplify Framework Version: 1.5.5
- Dependency Manager: Cocoapods
- Swift Version: 5.3
- CLI Version: 4.41.2
Device Information (please complete the following information):
- Device: all
- iOS Version: iOS14
Additional context
After forking the project and investigating, I can make this work by changing the short dateTimeFormat from yyyy-MM-dd'T'HH:mm to yyyy-MM-dd'T'HH:mmZZZZZ, but I’m not sure it won’t break parsing for other fields.
And BTW, the testShortDateTimeParsing testing this is wrong. It is tested with let datetime = try Temporal.DateTime(iso8601String: "2020-01-20T08:00:00Z") instead of let datetime = try Temporal.DateTime(iso8601String: "2020-01-20T08:00Z") (no seconds needed)
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 17 (8 by maintainers)
The Temporal.Date uses the format
yyyy-MM-ddZZZZZwhich is why you can see theZat the end. What matters is when the value is persisted to AppSync as anAWSDate, according to https://docs.aws.amazon.com/appsync/latest/devguide/scalars.htmlthe “Z” is optional and does not change the data, just represented with an optional timezone offset.