module OpenTracing.Time (AsMicros(micros)) where

import Data.Int
import Data.Time.Clock
import Data.Time.Clock.POSIX
import Data.Word


class AsMicros a where
    micros :: Integral b => a -> b

instance AsMicros UTCTime where
    micros :: UTCTime -> b
micros = POSIXTime -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (POSIXTime -> b) -> (UTCTime -> POSIXTime) -> UTCTime -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (POSIXTime
1000000POSIXTime -> POSIXTime -> POSIXTime
forall a. Num a => a -> a -> a
*) (POSIXTime -> POSIXTime)
-> (UTCTime -> POSIXTime) -> UTCTime -> POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> POSIXTime
utcTimeToPOSIXSeconds
    {-# INLINE micros #-}

instance AsMicros NominalDiffTime where
    micros :: POSIXTime -> b
micros = POSIXTime -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (POSIXTime -> b) -> (POSIXTime -> POSIXTime) -> POSIXTime -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (POSIXTime
1000000POSIXTime -> POSIXTime -> POSIXTime
forall a. Num a => a -> a -> a
*)
    {-# INLINE micros #-}

{-# SPECIALIZE micros :: UTCTime         -> Int64  #-}
{-# SPECIALIZE micros :: UTCTime         -> Word64 #-}
{-# SPECIALIZE micros :: NominalDiffTime -> Int64  #-}
{-# SPECIALIZE micros :: NominalDiffTime -> Word64 #-}