Files
simplex-chat/src/Simplex/Chat/Util.hs
JRoberts 84d2c408ce core: optimize chat loading time - faster chat previews queries (item_status index for chat stats), fix live file transfers queries (#1630)
* core: optimize get chat previews queries (item_status index for chat stats)

* cleanup

* optimize chat loading time

* cleanup

* schema

Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
2022-12-23 18:37:02 +04:00

28 lines
694 B
Haskell

{-# LANGUAGE NumericUnderscores #-}
module Simplex.Chat.Util
( diffInMicros,
diffInSeconds,
week,
)
where
import Data.Fixed (Fixed (MkFixed), Pico)
import Data.Time (NominalDiffTime, nominalDiffTimeToSeconds)
import Data.Time.Clock (UTCTime, diffUTCTime)
diffInSeconds :: UTCTime -> UTCTime -> Int
diffInSeconds a b = (`div` 1000000_000000) $ diffInPicos a b
diffInMicros :: UTCTime -> UTCTime -> Int
diffInMicros a b = (`div` 1000000) $ diffInPicos a b
diffInPicos :: UTCTime -> UTCTime -> Int
diffInPicos a b = fromInteger . fromPico . nominalDiffTimeToSeconds $ diffUTCTime a b
fromPico :: Pico -> Integer
fromPico (MkFixed i) = i
week :: NominalDiffTime
week = 7 * 86400