amplify-swift: AWSDateTime parsing fails (wrong format)

Describe the bug Datastore is unable to parse AWSDateTime fields.

To Reproduce Steps to reproduce the behavior:

  1. Create a model with a AWSDateTime field
  2. Fetch all data from server
  3. 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)

Most upvoted comments

I should probably open another issue for this but haven’t put in the time to thoroughly vet what is going on. When schema type is AWSDate, iOS serializes that to yyyy-MM-ddZ. Other platforms leave off the Z. Is the Z even valid for date-only iso8601 format?

The Temporal.Date uses the format yyyy-MM-ddZZZZZ which is why you can see the Z at the end. What matters is when the value is persisted to AppSync as an AWSDate, according to https://docs.aws.amazon.com/appsync/latest/devguide/scalars.html

The AWSDate, AWSTime, and AWSDateTime scalars can optionally include a time zone offset. For example, the values 1970-01-01Z, 1970-01-01-07:00, and 1970-01-01+05:30 are all valid for AWSDate. The time zone offset must be either Z (UTC) or an offset in hours and minutes (and, optionally, seconds). For example, ±hh:mm:ss. The seconds field in the time zone offset is considered valid even though it’s not part of the ISO 8601 standard.

the “Z” is optional and does not change the data, just represented with an optional timezone offset.