Skip to content

Commit f7b4f86

Browse files
author
Julian Ospald
committed
Change DB representation of POSIXTime
1 parent 6eed46d commit f7b4f86

File tree

1 file changed

+13
-4
lines changed
  • lib/core/src/Cardano/Wallet/DB/Sqlite

1 file changed

+13
-4
lines changed

lib/core/src/Cardano/Wallet/DB/Sqlite/Types.hs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ import Data.Text.Encoding
8888
( decodeUtf8, encodeUtf8 )
8989
import Data.Time.Clock.POSIX
9090
( POSIXTime, posixSecondsToUTCTime, utcTimeToPOSIXSeconds )
91+
import Data.Time.Format
92+
( defaultTimeLocale, formatTime, iso8601DateFormat, parseTimeM )
9193
import Data.Word
9294
( Word32, Word64 )
9395
import Data.Word.Odd
@@ -665,9 +667,16 @@ instance PersistFieldSql DerivationPrefix where
665667
-- Other
666668

667669
instance PersistField POSIXTime where
668-
toPersistValue = PersistUTCTime . posixSecondsToUTCTime
669-
fromPersistValue (PersistUTCTime utc) = Right . utcTimeToPOSIXSeconds $ utc
670-
fromPersistValue _ = Left "Could not convert to unknown construtctor POSIX seconds"
670+
toPersistValue =
671+
PersistText
672+
. T.pack
673+
. formatTime defaultTimeLocale (iso8601DateFormat (Just "%H:%M:%S"))
674+
. posixSecondsToUTCTime
675+
fromPersistValue (PersistText time) =
676+
fmap utcTimeToPOSIXSeconds $
677+
parseTimeM True defaultTimeLocale
678+
(iso8601DateFormat (Just "%H:%M:%S")) (T.unpack time)
679+
fromPersistValue _ = Left "Could not convert to unknown constructor POSIX seconds"
671680

672681
instance PersistFieldSql POSIXTime where
673-
sqlType _ = sqlType (Proxy @Word64)
682+
sqlType _ = sqlType (Proxy @Text)

0 commit comments

Comments
 (0)