@@ -15,7 +15,7 @@ module Database.Persist.Class.PersistField
1515 ) where
1616
1717import Database.Persist.Types.Base
18- import Data.Time (Day (.. ), TimeOfDay , UTCTime )
18+ import Data.Time (Day (.. ), TimeOfDay , UTCTime , parseTime )
1919#ifdef HIGH_PRECISION_DATE
2020import Data.Time.Clock.POSIX (posixSecondsToUTCTime )
2121#endif
@@ -48,6 +48,12 @@ import qualified Data.Map as M
4848import qualified Data.Text.Encoding as TE
4949import qualified Data.Vector as V
5050
51+ #if MIN_VERSION_time(1,5,0)
52+ import Data.Time (defaultTimeLocale )
53+ #else
54+ import System.Locale (defaultTimeLocale )
55+ #endif
56+
5157-- | A value which can be marshalled to and from a 'PersistValue'.
5258class PersistField a where
5359 toPersistValue :: a -> PersistValue
@@ -221,7 +227,12 @@ instance PersistField UTCTime where
221227 fromPersistValue x@ (PersistText t) =
222228 case reads $ T. unpack t of
223229 (d, _): _ -> Right d
224- _ -> Left $ T. pack $ " Expected UTCTime, received " ++ show x
230+ _ ->
231+ case parse8601 $ T. unpack t of
232+ Nothing -> Left $ T. pack $ " Expected UTCTime, received " ++ show x
233+ Just x -> Right x
234+ where
235+ parse8601 = parseTime defaultTimeLocale " %FT%T%Q"
225236 fromPersistValue x@ (PersistByteString s) =
226237 case reads $ unpack s of
227238 (d, _): _ -> Right d
0 commit comments