@@ -311,7 +311,7 @@ instance PersistField UTCTime where
311311 in
312312 case NonEmpty. nonEmpty (reads s) of
313313 Nothing ->
314- case parse8601 s <|> parsePretty s of
314+ case parse8601 s <|> parse8601NoTimezone s <|> parsePretty s <|> parsePrettyNoTimezone s of
315315 Nothing -> Left $ fromPersistValueParseError " UTCTime" x
316316 Just x' -> Right x'
317317 Just matches ->
@@ -323,12 +323,20 @@ instance PersistField UTCTime where
323323 Right $ fst $ NonEmpty. last matches
324324 where
325325#if MIN_VERSION_time(1,5,0)
326+ -- Note: consider using `Data.Time.Format.ISO8601` iso8601ParseM when bumping
327+ -- lower "time" package bound to >=1.9; this function require the timezone "Z",
328+ -- so best suitable when e.g. dropping support non-canonial "notimezone" and "pretty" parse variants
329+ -- in persistent 3.0.
326330 parseTime' = parseTimeM True defaultTimeLocale
327331#else
328332 parseTime' = parseTime defaultTimeLocale
329333#endif
330- parse8601 = parseTime' " %FT%T%Q"
331- parsePretty = parseTime' " %F %T%Q"
334+ parse8601 = parseTime' " %FT%T%QZ"
335+ parsePretty = parseTime' " %F %T%QZ"
336+ -- Before 2.13.3.1 persistent-sqlite was missing the timezone "Z" for UTC,
337+ -- which was only implicit, so these functions ensure backwards-compatibility.
338+ parse8601NoTimezone = parseTime' " %FT%T%Q"
339+ parsePrettyNoTimezone = parseTime' " %F %T%Q"
332340 fromPersistValue x@ (PersistByteString s) =
333341 case reads $ unpack s of
334342 (d, _): _ -> Right d
0 commit comments