Skip to content

Unable to decode date #3

@BalestraPatrick

Description

@BalestraPatrick

Hey there! In my PostgreSQL database I have two types of dates in the same column:

  • 2017-12-08 23:20:47.307779+01
  • 2017-09-29 02:00:00+02

One looks like to have milliseconds while the other one doesn't. Trying to decode this table from the database results in: FluentError.decodingError: The data couldn’t be read because it isn’t in the correct format. (Accessory nested model)

I tried digging into the FluentQuery codebase and I figured out that the following method returns nil:

override func date(from string: String) -> Date? {
        if let result = super.date(from: string) {
            return result
        }
        return OptionalFractionalSecondsDateFormatter.withoutSeconds.date(from: string)
    }

It seems that it's trying to decode the date with the withoutSeconds formatter and is failing. Do you know what's going on? Are you trying to decode the dates with both milliseconds and without to make sure it can be decoded correctly?
Thanks a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions