meilisearch-swift
meilisearch-swift copied to clipboard
Changes dates represented as strings to dates represented as a Date type
Description
In the task structure multiple fields represents dates but are typed as strings. It would be an improvement to change these dates to a Date type object and not a string,
Example can be found here:
https://github.com/meilisearch/meilisearch-swift/blob/ae7ad35829ebaedebc0dd050c05703207d55c819/Sources/MeiliSearch/Model/Task.swift#L34
Currently the decoder is not able to transform the returned date format by Meilisearch into a Date object in swift. See error:
▿ Swift.DecodingError.dataCorrupted
▿ dataCorrupted: Swift.DecodingError.Context
▿ codingPath: 1 element
- CodingKeys(stringValue: "duration", intValue: nil)
- debugDescription: "Date string does not match format expected by formatter."
- underlyingError: nil
Meilisearch is returned date the following way:
"enqueuedAt": "2021-08-10T14:29:17.000000Z",
Which per the specs is described like this (for example with enqueuedAt):
| enqueuedAt | string | Represent the date and time as `ISO-8601` format when the task has been enqueued |
I had a similar problem when upgrading the dart SDK: https://github.com/meilisearch/meilisearch-dart/blob/main/lib/src/client_impl.dart#L160 so I had to make a workaround in order to be able to serialize it. Not sure if helps 👯
For the moment there are two API in swift. One called Date that has a ISO8601Format(_:) method but only compatible with MacOS 12+
The other is called DateFormatter and I believe with this API it is easy