mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-04 00:26:15 +00:00
* 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>
28 lines
694 B
Haskell
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
|