{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DeriveDataTypeable #-}
-- |
-- Module      : Data.Hourglass.Epoch
-- License     : BSD-style
-- Maintainer  : Vincent Hanquez <vincent@snarc.org>
-- Stability   : experimental
-- Portability : unknown
--
-- Epoch tracking
--
module Data.Hourglass.Epoch
    (
    -- * computer time tracking with various epoch
      ElapsedSince(..)
    , ElapsedSinceP(..)
    -- * Epoch
    , Epoch(..)
    -- ** standard and usual epochs
    , UnixEpoch(..)
    , WindowsEpoch(..)
    ) where

import Data.Data
import Control.DeepSeq
import Data.Hourglass.Types
import Data.Hourglass.Time

-- | A number of seconds elapsed since an epoch.
newtype ElapsedSince epoch = ElapsedSince Seconds
    deriving (Int -> ElapsedSince epoch -> ShowS
[ElapsedSince epoch] -> ShowS
ElapsedSince epoch -> String
(Int -> ElapsedSince epoch -> ShowS)
-> (ElapsedSince epoch -> String)
-> ([ElapsedSince epoch] -> ShowS)
-> Show (ElapsedSince epoch)
forall epoch. Int -> ElapsedSince epoch -> ShowS
forall epoch. [ElapsedSince epoch] -> ShowS
forall epoch. ElapsedSince epoch -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ElapsedSince epoch] -> ShowS
$cshowList :: forall epoch. [ElapsedSince epoch] -> ShowS
show :: ElapsedSince epoch -> String
$cshow :: forall epoch. ElapsedSince epoch -> String
showsPrec :: Int -> ElapsedSince epoch -> ShowS
$cshowsPrec :: forall epoch. Int -> ElapsedSince epoch -> ShowS
Show,ReadPrec [ElapsedSince epoch]
ReadPrec (ElapsedSince epoch)
Int -> ReadS (ElapsedSince epoch)
ReadS [ElapsedSince epoch]
(Int -> ReadS (ElapsedSince epoch))
-> ReadS [ElapsedSince epoch]
-> ReadPrec (ElapsedSince epoch)
-> ReadPrec [ElapsedSince epoch]
-> Read (ElapsedSince epoch)
forall epoch. ReadPrec [ElapsedSince epoch]
forall epoch. ReadPrec (ElapsedSince epoch)
forall epoch. Int -> ReadS (ElapsedSince epoch)
forall epoch. ReadS [ElapsedSince epoch]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ElapsedSince epoch]
$creadListPrec :: forall epoch. ReadPrec [ElapsedSince epoch]
readPrec :: ReadPrec (ElapsedSince epoch)
$creadPrec :: forall epoch. ReadPrec (ElapsedSince epoch)
readList :: ReadS [ElapsedSince epoch]
$creadList :: forall epoch. ReadS [ElapsedSince epoch]
readsPrec :: Int -> ReadS (ElapsedSince epoch)
$creadsPrec :: forall epoch. Int -> ReadS (ElapsedSince epoch)
Read,ElapsedSince epoch -> ElapsedSince epoch -> Bool
(ElapsedSince epoch -> ElapsedSince epoch -> Bool)
-> (ElapsedSince epoch -> ElapsedSince epoch -> Bool)
-> Eq (ElapsedSince epoch)
forall epoch. ElapsedSince epoch -> ElapsedSince epoch -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ElapsedSince epoch -> ElapsedSince epoch -> Bool
$c/= :: forall epoch. ElapsedSince epoch -> ElapsedSince epoch -> Bool
== :: ElapsedSince epoch -> ElapsedSince epoch -> Bool
$c== :: forall epoch. ElapsedSince epoch -> ElapsedSince epoch -> Bool
Eq,Eq (ElapsedSince epoch)
Eq (ElapsedSince epoch)
-> (ElapsedSince epoch -> ElapsedSince epoch -> Ordering)
-> (ElapsedSince epoch -> ElapsedSince epoch -> Bool)
-> (ElapsedSince epoch -> ElapsedSince epoch -> Bool)
-> (ElapsedSince epoch -> ElapsedSince epoch -> Bool)
-> (ElapsedSince epoch -> ElapsedSince epoch -> Bool)
-> (ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch)
-> (ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch)
-> Ord (ElapsedSince epoch)
ElapsedSince epoch -> ElapsedSince epoch -> Bool
ElapsedSince epoch -> ElapsedSince epoch -> Ordering
ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch
forall epoch. Eq (ElapsedSince epoch)
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall epoch. ElapsedSince epoch -> ElapsedSince epoch -> Bool
forall epoch. ElapsedSince epoch -> ElapsedSince epoch -> Ordering
forall epoch.
ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch
min :: ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch
$cmin :: forall epoch.
ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch
max :: ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch
$cmax :: forall epoch.
ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch
>= :: ElapsedSince epoch -> ElapsedSince epoch -> Bool
$c>= :: forall epoch. ElapsedSince epoch -> ElapsedSince epoch -> Bool
> :: ElapsedSince epoch -> ElapsedSince epoch -> Bool
$c> :: forall epoch. ElapsedSince epoch -> ElapsedSince epoch -> Bool
<= :: ElapsedSince epoch -> ElapsedSince epoch -> Bool
$c<= :: forall epoch. ElapsedSince epoch -> ElapsedSince epoch -> Bool
< :: ElapsedSince epoch -> ElapsedSince epoch -> Bool
$c< :: forall epoch. ElapsedSince epoch -> ElapsedSince epoch -> Bool
compare :: ElapsedSince epoch -> ElapsedSince epoch -> Ordering
$ccompare :: forall epoch. ElapsedSince epoch -> ElapsedSince epoch -> Ordering
$cp1Ord :: forall epoch. Eq (ElapsedSince epoch)
Ord,Integer -> ElapsedSince epoch
ElapsedSince epoch -> ElapsedSince epoch
ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch
(ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch)
-> (ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch)
-> (ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch)
-> (ElapsedSince epoch -> ElapsedSince epoch)
-> (ElapsedSince epoch -> ElapsedSince epoch)
-> (ElapsedSince epoch -> ElapsedSince epoch)
-> (Integer -> ElapsedSince epoch)
-> Num (ElapsedSince epoch)
forall epoch. Integer -> ElapsedSince epoch
forall epoch. ElapsedSince epoch -> ElapsedSince epoch
forall epoch.
ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> ElapsedSince epoch
$cfromInteger :: forall epoch. Integer -> ElapsedSince epoch
signum :: ElapsedSince epoch -> ElapsedSince epoch
$csignum :: forall epoch. ElapsedSince epoch -> ElapsedSince epoch
abs :: ElapsedSince epoch -> ElapsedSince epoch
$cabs :: forall epoch. ElapsedSince epoch -> ElapsedSince epoch
negate :: ElapsedSince epoch -> ElapsedSince epoch
$cnegate :: forall epoch. ElapsedSince epoch -> ElapsedSince epoch
* :: ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch
$c* :: forall epoch.
ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch
- :: ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch
$c- :: forall epoch.
ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch
+ :: ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch
$c+ :: forall epoch.
ElapsedSince epoch -> ElapsedSince epoch -> ElapsedSince epoch
Num,Typeable (ElapsedSince epoch)
DataType
Constr
Typeable (ElapsedSince epoch)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> ElapsedSince epoch
    -> c (ElapsedSince epoch))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (ElapsedSince epoch))
-> (ElapsedSince epoch -> Constr)
-> (ElapsedSince epoch -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (ElapsedSince epoch)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (ElapsedSince epoch)))
-> ((forall b. Data b => b -> b)
    -> ElapsedSince epoch -> ElapsedSince epoch)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ElapsedSince epoch -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ElapsedSince epoch -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> ElapsedSince epoch -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ElapsedSince epoch -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> ElapsedSince epoch -> m (ElapsedSince epoch))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> ElapsedSince epoch -> m (ElapsedSince epoch))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> ElapsedSince epoch -> m (ElapsedSince epoch))
-> Data (ElapsedSince epoch)
ElapsedSince epoch -> DataType
ElapsedSince epoch -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (ElapsedSince epoch))
(forall b. Data b => b -> b)
-> ElapsedSince epoch -> ElapsedSince epoch
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ElapsedSince epoch
-> c (ElapsedSince epoch)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ElapsedSince epoch)
forall epoch. Data epoch => Typeable (ElapsedSince epoch)
forall epoch. Data epoch => ElapsedSince epoch -> DataType
forall epoch. Data epoch => ElapsedSince epoch -> Constr
forall epoch.
Data epoch =>
(forall b. Data b => b -> b)
-> ElapsedSince epoch -> ElapsedSince epoch
forall epoch u.
Data epoch =>
Int -> (forall d. Data d => d -> u) -> ElapsedSince epoch -> u
forall epoch u.
Data epoch =>
(forall d. Data d => d -> u) -> ElapsedSince epoch -> [u]
forall epoch r r'.
Data epoch =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSince epoch -> r
forall epoch r r'.
Data epoch =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSince epoch -> r
forall epoch (m :: * -> *).
(Data epoch, Monad m) =>
(forall d. Data d => d -> m d)
-> ElapsedSince epoch -> m (ElapsedSince epoch)
forall epoch (m :: * -> *).
(Data epoch, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> ElapsedSince epoch -> m (ElapsedSince epoch)
forall epoch (c :: * -> *).
Data epoch =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ElapsedSince epoch)
forall epoch (c :: * -> *).
Data epoch =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ElapsedSince epoch
-> c (ElapsedSince epoch)
forall epoch (t :: * -> *) (c :: * -> *).
(Data epoch, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ElapsedSince epoch))
forall epoch (t :: * -> * -> *) (c :: * -> *).
(Data epoch, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ElapsedSince epoch))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> ElapsedSince epoch -> u
forall u. (forall d. Data d => d -> u) -> ElapsedSince epoch -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSince epoch -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSince epoch -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ElapsedSince epoch -> m (ElapsedSince epoch)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ElapsedSince epoch -> m (ElapsedSince epoch)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ElapsedSince epoch)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ElapsedSince epoch
-> c (ElapsedSince epoch)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (ElapsedSince epoch))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ElapsedSince epoch))
$cElapsedSince :: Constr
$tElapsedSince :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> ElapsedSince epoch -> m (ElapsedSince epoch)
$cgmapMo :: forall epoch (m :: * -> *).
(Data epoch, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> ElapsedSince epoch -> m (ElapsedSince epoch)
gmapMp :: (forall d. Data d => d -> m d)
-> ElapsedSince epoch -> m (ElapsedSince epoch)
$cgmapMp :: forall epoch (m :: * -> *).
(Data epoch, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> ElapsedSince epoch -> m (ElapsedSince epoch)
gmapM :: (forall d. Data d => d -> m d)
-> ElapsedSince epoch -> m (ElapsedSince epoch)
$cgmapM :: forall epoch (m :: * -> *).
(Data epoch, Monad m) =>
(forall d. Data d => d -> m d)
-> ElapsedSince epoch -> m (ElapsedSince epoch)
gmapQi :: Int -> (forall d. Data d => d -> u) -> ElapsedSince epoch -> u
$cgmapQi :: forall epoch u.
Data epoch =>
Int -> (forall d. Data d => d -> u) -> ElapsedSince epoch -> u
gmapQ :: (forall d. Data d => d -> u) -> ElapsedSince epoch -> [u]
$cgmapQ :: forall epoch u.
Data epoch =>
(forall d. Data d => d -> u) -> ElapsedSince epoch -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSince epoch -> r
$cgmapQr :: forall epoch r r'.
Data epoch =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSince epoch -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSince epoch -> r
$cgmapQl :: forall epoch r r'.
Data epoch =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSince epoch -> r
gmapT :: (forall b. Data b => b -> b)
-> ElapsedSince epoch -> ElapsedSince epoch
$cgmapT :: forall epoch.
Data epoch =>
(forall b. Data b => b -> b)
-> ElapsedSince epoch -> ElapsedSince epoch
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ElapsedSince epoch))
$cdataCast2 :: forall epoch (t :: * -> * -> *) (c :: * -> *).
(Data epoch, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ElapsedSince epoch))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (ElapsedSince epoch))
$cdataCast1 :: forall epoch (t :: * -> *) (c :: * -> *).
(Data epoch, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ElapsedSince epoch))
dataTypeOf :: ElapsedSince epoch -> DataType
$cdataTypeOf :: forall epoch. Data epoch => ElapsedSince epoch -> DataType
toConstr :: ElapsedSince epoch -> Constr
$ctoConstr :: forall epoch. Data epoch => ElapsedSince epoch -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ElapsedSince epoch)
$cgunfold :: forall epoch (c :: * -> *).
Data epoch =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ElapsedSince epoch)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ElapsedSince epoch
-> c (ElapsedSince epoch)
$cgfoldl :: forall epoch (c :: * -> *).
Data epoch =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ElapsedSince epoch
-> c (ElapsedSince epoch)
$cp1Data :: forall epoch. Data epoch => Typeable (ElapsedSince epoch)
Data,Typeable,ElapsedSince epoch -> ()
(ElapsedSince epoch -> ()) -> NFData (ElapsedSince epoch)
forall epoch. ElapsedSince epoch -> ()
forall a. (a -> ()) -> NFData a
rnf :: ElapsedSince epoch -> ()
$crnf :: forall epoch. ElapsedSince epoch -> ()
NFData)

-- | A number of seconds and nanoseconds elapsed since an epoch.
data ElapsedSinceP epoch = ElapsedSinceP {-# UNPACK #-} !(ElapsedSince epoch)
                                         {-# UNPACK #-} !NanoSeconds
    deriving (Int -> ElapsedSinceP epoch -> ShowS
[ElapsedSinceP epoch] -> ShowS
ElapsedSinceP epoch -> String
(Int -> ElapsedSinceP epoch -> ShowS)
-> (ElapsedSinceP epoch -> String)
-> ([ElapsedSinceP epoch] -> ShowS)
-> Show (ElapsedSinceP epoch)
forall epoch. Int -> ElapsedSinceP epoch -> ShowS
forall epoch. [ElapsedSinceP epoch] -> ShowS
forall epoch. ElapsedSinceP epoch -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ElapsedSinceP epoch] -> ShowS
$cshowList :: forall epoch. [ElapsedSinceP epoch] -> ShowS
show :: ElapsedSinceP epoch -> String
$cshow :: forall epoch. ElapsedSinceP epoch -> String
showsPrec :: Int -> ElapsedSinceP epoch -> ShowS
$cshowsPrec :: forall epoch. Int -> ElapsedSinceP epoch -> ShowS
Show,ReadPrec [ElapsedSinceP epoch]
ReadPrec (ElapsedSinceP epoch)
Int -> ReadS (ElapsedSinceP epoch)
ReadS [ElapsedSinceP epoch]
(Int -> ReadS (ElapsedSinceP epoch))
-> ReadS [ElapsedSinceP epoch]
-> ReadPrec (ElapsedSinceP epoch)
-> ReadPrec [ElapsedSinceP epoch]
-> Read (ElapsedSinceP epoch)
forall epoch. ReadPrec [ElapsedSinceP epoch]
forall epoch. ReadPrec (ElapsedSinceP epoch)
forall epoch. Int -> ReadS (ElapsedSinceP epoch)
forall epoch. ReadS [ElapsedSinceP epoch]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ElapsedSinceP epoch]
$creadListPrec :: forall epoch. ReadPrec [ElapsedSinceP epoch]
readPrec :: ReadPrec (ElapsedSinceP epoch)
$creadPrec :: forall epoch. ReadPrec (ElapsedSinceP epoch)
readList :: ReadS [ElapsedSinceP epoch]
$creadList :: forall epoch. ReadS [ElapsedSinceP epoch]
readsPrec :: Int -> ReadS (ElapsedSinceP epoch)
$creadsPrec :: forall epoch. Int -> ReadS (ElapsedSinceP epoch)
Read,ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
(ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool)
-> (ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool)
-> Eq (ElapsedSinceP epoch)
forall epoch. ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
$c/= :: forall epoch. ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
== :: ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
$c== :: forall epoch. ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
Eq,Eq (ElapsedSinceP epoch)
Eq (ElapsedSinceP epoch)
-> (ElapsedSinceP epoch -> ElapsedSinceP epoch -> Ordering)
-> (ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool)
-> (ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool)
-> (ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool)
-> (ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool)
-> (ElapsedSinceP epoch
    -> ElapsedSinceP epoch -> ElapsedSinceP epoch)
-> (ElapsedSinceP epoch
    -> ElapsedSinceP epoch -> ElapsedSinceP epoch)
-> Ord (ElapsedSinceP epoch)
ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
ElapsedSinceP epoch -> ElapsedSinceP epoch -> Ordering
ElapsedSinceP epoch -> ElapsedSinceP epoch -> ElapsedSinceP epoch
forall epoch. Eq (ElapsedSinceP epoch)
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall epoch. ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
forall epoch.
ElapsedSinceP epoch -> ElapsedSinceP epoch -> Ordering
forall epoch.
ElapsedSinceP epoch -> ElapsedSinceP epoch -> ElapsedSinceP epoch
min :: ElapsedSinceP epoch -> ElapsedSinceP epoch -> ElapsedSinceP epoch
$cmin :: forall epoch.
ElapsedSinceP epoch -> ElapsedSinceP epoch -> ElapsedSinceP epoch
max :: ElapsedSinceP epoch -> ElapsedSinceP epoch -> ElapsedSinceP epoch
$cmax :: forall epoch.
ElapsedSinceP epoch -> ElapsedSinceP epoch -> ElapsedSinceP epoch
>= :: ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
$c>= :: forall epoch. ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
> :: ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
$c> :: forall epoch. ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
<= :: ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
$c<= :: forall epoch. ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
< :: ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
$c< :: forall epoch. ElapsedSinceP epoch -> ElapsedSinceP epoch -> Bool
compare :: ElapsedSinceP epoch -> ElapsedSinceP epoch -> Ordering
$ccompare :: forall epoch.
ElapsedSinceP epoch -> ElapsedSinceP epoch -> Ordering
$cp1Ord :: forall epoch. Eq (ElapsedSinceP epoch)
Ord,Typeable (ElapsedSinceP epoch)
DataType
Constr
Typeable (ElapsedSinceP epoch)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> ElapsedSinceP epoch
    -> c (ElapsedSinceP epoch))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (ElapsedSinceP epoch))
-> (ElapsedSinceP epoch -> Constr)
-> (ElapsedSinceP epoch -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (ElapsedSinceP epoch)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (ElapsedSinceP epoch)))
-> ((forall b. Data b => b -> b)
    -> ElapsedSinceP epoch -> ElapsedSinceP epoch)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ElapsedSinceP epoch -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ElapsedSinceP epoch -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> ElapsedSinceP epoch -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ElapsedSinceP epoch -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> ElapsedSinceP epoch -> m (ElapsedSinceP epoch))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> ElapsedSinceP epoch -> m (ElapsedSinceP epoch))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> ElapsedSinceP epoch -> m (ElapsedSinceP epoch))
-> Data (ElapsedSinceP epoch)
ElapsedSinceP epoch -> DataType
ElapsedSinceP epoch -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (ElapsedSinceP epoch))
(forall b. Data b => b -> b)
-> ElapsedSinceP epoch -> ElapsedSinceP epoch
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ElapsedSinceP epoch
-> c (ElapsedSinceP epoch)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ElapsedSinceP epoch)
forall epoch. Data epoch => Typeable (ElapsedSinceP epoch)
forall epoch. Data epoch => ElapsedSinceP epoch -> DataType
forall epoch. Data epoch => ElapsedSinceP epoch -> Constr
forall epoch.
Data epoch =>
(forall b. Data b => b -> b)
-> ElapsedSinceP epoch -> ElapsedSinceP epoch
forall epoch u.
Data epoch =>
Int -> (forall d. Data d => d -> u) -> ElapsedSinceP epoch -> u
forall epoch u.
Data epoch =>
(forall d. Data d => d -> u) -> ElapsedSinceP epoch -> [u]
forall epoch r r'.
Data epoch =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSinceP epoch -> r
forall epoch r r'.
Data epoch =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSinceP epoch -> r
forall epoch (m :: * -> *).
(Data epoch, Monad m) =>
(forall d. Data d => d -> m d)
-> ElapsedSinceP epoch -> m (ElapsedSinceP epoch)
forall epoch (m :: * -> *).
(Data epoch, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> ElapsedSinceP epoch -> m (ElapsedSinceP epoch)
forall epoch (c :: * -> *).
Data epoch =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ElapsedSinceP epoch)
forall epoch (c :: * -> *).
Data epoch =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ElapsedSinceP epoch
-> c (ElapsedSinceP epoch)
forall epoch (t :: * -> *) (c :: * -> *).
(Data epoch, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ElapsedSinceP epoch))
forall epoch (t :: * -> * -> *) (c :: * -> *).
(Data epoch, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ElapsedSinceP epoch))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> ElapsedSinceP epoch -> u
forall u.
(forall d. Data d => d -> u) -> ElapsedSinceP epoch -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSinceP epoch -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSinceP epoch -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ElapsedSinceP epoch -> m (ElapsedSinceP epoch)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ElapsedSinceP epoch -> m (ElapsedSinceP epoch)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ElapsedSinceP epoch)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ElapsedSinceP epoch
-> c (ElapsedSinceP epoch)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (ElapsedSinceP epoch))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ElapsedSinceP epoch))
$cElapsedSinceP :: Constr
$tElapsedSinceP :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> ElapsedSinceP epoch -> m (ElapsedSinceP epoch)
$cgmapMo :: forall epoch (m :: * -> *).
(Data epoch, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> ElapsedSinceP epoch -> m (ElapsedSinceP epoch)
gmapMp :: (forall d. Data d => d -> m d)
-> ElapsedSinceP epoch -> m (ElapsedSinceP epoch)
$cgmapMp :: forall epoch (m :: * -> *).
(Data epoch, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> ElapsedSinceP epoch -> m (ElapsedSinceP epoch)
gmapM :: (forall d. Data d => d -> m d)
-> ElapsedSinceP epoch -> m (ElapsedSinceP epoch)
$cgmapM :: forall epoch (m :: * -> *).
(Data epoch, Monad m) =>
(forall d. Data d => d -> m d)
-> ElapsedSinceP epoch -> m (ElapsedSinceP epoch)
gmapQi :: Int -> (forall d. Data d => d -> u) -> ElapsedSinceP epoch -> u
$cgmapQi :: forall epoch u.
Data epoch =>
Int -> (forall d. Data d => d -> u) -> ElapsedSinceP epoch -> u
gmapQ :: (forall d. Data d => d -> u) -> ElapsedSinceP epoch -> [u]
$cgmapQ :: forall epoch u.
Data epoch =>
(forall d. Data d => d -> u) -> ElapsedSinceP epoch -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSinceP epoch -> r
$cgmapQr :: forall epoch r r'.
Data epoch =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSinceP epoch -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSinceP epoch -> r
$cgmapQl :: forall epoch r r'.
Data epoch =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ElapsedSinceP epoch -> r
gmapT :: (forall b. Data b => b -> b)
-> ElapsedSinceP epoch -> ElapsedSinceP epoch
$cgmapT :: forall epoch.
Data epoch =>
(forall b. Data b => b -> b)
-> ElapsedSinceP epoch -> ElapsedSinceP epoch
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ElapsedSinceP epoch))
$cdataCast2 :: forall epoch (t :: * -> * -> *) (c :: * -> *).
(Data epoch, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ElapsedSinceP epoch))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (ElapsedSinceP epoch))
$cdataCast1 :: forall epoch (t :: * -> *) (c :: * -> *).
(Data epoch, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ElapsedSinceP epoch))
dataTypeOf :: ElapsedSinceP epoch -> DataType
$cdataTypeOf :: forall epoch. Data epoch => ElapsedSinceP epoch -> DataType
toConstr :: ElapsedSinceP epoch -> Constr
$ctoConstr :: forall epoch. Data epoch => ElapsedSinceP epoch -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ElapsedSinceP epoch)
$cgunfold :: forall epoch (c :: * -> *).
Data epoch =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ElapsedSinceP epoch)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ElapsedSinceP epoch
-> c (ElapsedSinceP epoch)
$cgfoldl :: forall epoch (c :: * -> *).
Data epoch =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ElapsedSinceP epoch
-> c (ElapsedSinceP epoch)
$cp1Data :: forall epoch. Data epoch => Typeable (ElapsedSinceP epoch)
Data,Typeable)

instance NFData (ElapsedSinceP e) where rnf :: ElapsedSinceP e -> ()
rnf ElapsedSinceP e
e = ElapsedSinceP e
e ElapsedSinceP e -> () -> ()
`seq` ()

instance Num (ElapsedSinceP e) where
    (ElapsedSinceP ElapsedSince e
e1 NanoSeconds
ns1) + :: ElapsedSinceP e -> ElapsedSinceP e -> ElapsedSinceP e
+ (ElapsedSinceP ElapsedSince e
e2 NanoSeconds
ns2) = ElapsedSince e -> NanoSeconds -> ElapsedSinceP e
forall epoch.
ElapsedSince epoch -> NanoSeconds -> ElapsedSinceP epoch
ElapsedSinceP (ElapsedSince e
e1ElapsedSince e -> ElapsedSince e -> ElapsedSince e
forall a. Num a => a -> a -> a
+ElapsedSince e
e2) (NanoSeconds
ns1NanoSeconds -> NanoSeconds -> NanoSeconds
forall a. Num a => a -> a -> a
+NanoSeconds
ns2)
    (ElapsedSinceP ElapsedSince e
e1 NanoSeconds
ns1) - :: ElapsedSinceP e -> ElapsedSinceP e -> ElapsedSinceP e
- (ElapsedSinceP ElapsedSince e
e2 NanoSeconds
ns2) = ElapsedSince e -> NanoSeconds -> ElapsedSinceP e
forall epoch.
ElapsedSince epoch -> NanoSeconds -> ElapsedSinceP epoch
ElapsedSinceP (ElapsedSince e
e1ElapsedSince e -> ElapsedSince e -> ElapsedSince e
forall a. Num a => a -> a -> a
-ElapsedSince e
e2) (NanoSeconds
ns1NanoSeconds -> NanoSeconds -> NanoSeconds
forall a. Num a => a -> a -> a
-NanoSeconds
ns2)
    (ElapsedSinceP ElapsedSince e
e1 NanoSeconds
ns1) * :: ElapsedSinceP e -> ElapsedSinceP e -> ElapsedSinceP e
* (ElapsedSinceP ElapsedSince e
e2 NanoSeconds
ns2) = ElapsedSince e -> NanoSeconds -> ElapsedSinceP e
forall epoch.
ElapsedSince epoch -> NanoSeconds -> ElapsedSinceP epoch
ElapsedSinceP (ElapsedSince e
e1ElapsedSince e -> ElapsedSince e -> ElapsedSince e
forall a. Num a => a -> a -> a
*ElapsedSince e
e2) (NanoSeconds
ns1NanoSeconds -> NanoSeconds -> NanoSeconds
forall a. Num a => a -> a -> a
*NanoSeconds
ns2)
    negate :: ElapsedSinceP e -> ElapsedSinceP e
negate (ElapsedSinceP ElapsedSince e
e NanoSeconds
ns) = ElapsedSince e -> NanoSeconds -> ElapsedSinceP e
forall epoch.
ElapsedSince epoch -> NanoSeconds -> ElapsedSinceP epoch
ElapsedSinceP (ElapsedSince e -> ElapsedSince e
forall a. Num a => a -> a
negate ElapsedSince e
e) NanoSeconds
ns
    abs :: ElapsedSinceP e -> ElapsedSinceP e
abs (ElapsedSinceP ElapsedSince e
e NanoSeconds
ns)    = ElapsedSince e -> NanoSeconds -> ElapsedSinceP e
forall epoch.
ElapsedSince epoch -> NanoSeconds -> ElapsedSinceP epoch
ElapsedSinceP (ElapsedSince e -> ElapsedSince e
forall a. Num a => a -> a
abs ElapsedSince e
e) NanoSeconds
ns
    signum :: ElapsedSinceP e -> ElapsedSinceP e
signum (ElapsedSinceP ElapsedSince e
e NanoSeconds
ns) = ElapsedSince e -> NanoSeconds -> ElapsedSinceP e
forall epoch.
ElapsedSince epoch -> NanoSeconds -> ElapsedSinceP epoch
ElapsedSinceP (ElapsedSince e -> ElapsedSince e
forall a. Num a => a -> a
signum ElapsedSince e
e) NanoSeconds
ns
    fromInteger :: Integer -> ElapsedSinceP e
fromInteger Integer
i          = ElapsedSince e -> NanoSeconds -> ElapsedSinceP e
forall epoch.
ElapsedSince epoch -> NanoSeconds -> ElapsedSinceP epoch
ElapsedSinceP (Seconds -> ElapsedSince e
forall epoch. Seconds -> ElapsedSince epoch
ElapsedSince (Integer -> Seconds
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i)) NanoSeconds
0

-- FIXME instance Real (ElapsedSinceP e)

-- | epoch related.
--
-- We use the well known Unix epoch as the
-- reference timezone for doing conversion between epochs.
--
-- Each methods of this typeclass should not use the actual value,
-- but only get the information needed from the type itself.
class Epoch epoch where
    -- | The name of this epoch
    epochName :: epoch -> String

    -- | number of seconds of difference with 1st January 1970.
    --
    -- a negative number means that this epoch start before
    -- the unix epoch.
    epochDiffToUnix :: epoch -> Seconds

-- | Unix Epoch, starting 1st January 1970
data UnixEpoch = UnixEpoch
    deriving (Int -> UnixEpoch -> ShowS
[UnixEpoch] -> ShowS
UnixEpoch -> String
(Int -> UnixEpoch -> ShowS)
-> (UnixEpoch -> String)
-> ([UnixEpoch] -> ShowS)
-> Show UnixEpoch
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UnixEpoch] -> ShowS
$cshowList :: [UnixEpoch] -> ShowS
show :: UnixEpoch -> String
$cshow :: UnixEpoch -> String
showsPrec :: Int -> UnixEpoch -> ShowS
$cshowsPrec :: Int -> UnixEpoch -> ShowS
Show,UnixEpoch -> UnixEpoch -> Bool
(UnixEpoch -> UnixEpoch -> Bool)
-> (UnixEpoch -> UnixEpoch -> Bool) -> Eq UnixEpoch
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UnixEpoch -> UnixEpoch -> Bool
$c/= :: UnixEpoch -> UnixEpoch -> Bool
== :: UnixEpoch -> UnixEpoch -> Bool
$c== :: UnixEpoch -> UnixEpoch -> Bool
Eq)

instance Epoch UnixEpoch where
    epochName :: UnixEpoch -> String
epochName UnixEpoch
_ = String
"unix"
    epochDiffToUnix :: UnixEpoch -> Seconds
epochDiffToUnix UnixEpoch
_ = Seconds
0

-- | Windows Epoch, starting 1st January 1601
data WindowsEpoch = WindowsEpoch
    deriving (Int -> WindowsEpoch -> ShowS
[WindowsEpoch] -> ShowS
WindowsEpoch -> String
(Int -> WindowsEpoch -> ShowS)
-> (WindowsEpoch -> String)
-> ([WindowsEpoch] -> ShowS)
-> Show WindowsEpoch
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WindowsEpoch] -> ShowS
$cshowList :: [WindowsEpoch] -> ShowS
show :: WindowsEpoch -> String
$cshow :: WindowsEpoch -> String
showsPrec :: Int -> WindowsEpoch -> ShowS
$cshowsPrec :: Int -> WindowsEpoch -> ShowS
Show,WindowsEpoch -> WindowsEpoch -> Bool
(WindowsEpoch -> WindowsEpoch -> Bool)
-> (WindowsEpoch -> WindowsEpoch -> Bool) -> Eq WindowsEpoch
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WindowsEpoch -> WindowsEpoch -> Bool
$c/= :: WindowsEpoch -> WindowsEpoch -> Bool
== :: WindowsEpoch -> WindowsEpoch -> Bool
$c== :: WindowsEpoch -> WindowsEpoch -> Bool
Eq)

instance Epoch WindowsEpoch where
    epochName :: WindowsEpoch -> String
epochName WindowsEpoch
_ = String
"windows"
    epochDiffToUnix :: WindowsEpoch -> Seconds
epochDiffToUnix WindowsEpoch
_ = -Seconds
11644473600

instance Epoch epoch => Timeable (ElapsedSince epoch) where
    timeGetElapsedP :: ElapsedSince epoch -> ElapsedP
timeGetElapsedP ElapsedSince epoch
es = Elapsed -> NanoSeconds -> ElapsedP
ElapsedP (Seconds -> Elapsed
Elapsed Seconds
e) NanoSeconds
0
      where ElapsedSince Seconds
e = ElapsedSince epoch -> ElapsedSince UnixEpoch
forall e1 e2.
(Epoch e1, Epoch e2) =>
ElapsedSince e1 -> ElapsedSince e2
convertEpoch ElapsedSince epoch
es :: ElapsedSince UnixEpoch
    timeGetElapsed :: ElapsedSince epoch -> Elapsed
timeGetElapsed   ElapsedSince epoch
es = Seconds -> Elapsed
Elapsed Seconds
e
      where ElapsedSince Seconds
e = ElapsedSince epoch -> ElapsedSince UnixEpoch
forall e1 e2.
(Epoch e1, Epoch e2) =>
ElapsedSince e1 -> ElapsedSince e2
convertEpoch ElapsedSince epoch
es :: ElapsedSince UnixEpoch
    timeGetNanoSeconds :: ElapsedSince epoch -> NanoSeconds
timeGetNanoSeconds ElapsedSince epoch
_ = NanoSeconds
0

instance Epoch epoch => Time (ElapsedSince epoch) where
    timeFromElapsedP :: ElapsedP -> ElapsedSince epoch
timeFromElapsedP (ElapsedP (Elapsed Seconds
e) NanoSeconds
_) =
        ElapsedSince UnixEpoch -> ElapsedSince epoch
forall e1 e2.
(Epoch e1, Epoch e2) =>
ElapsedSince e1 -> ElapsedSince e2
convertEpoch (Seconds -> ElapsedSince UnixEpoch
forall epoch. Seconds -> ElapsedSince epoch
ElapsedSince Seconds
e :: ElapsedSince UnixEpoch)

instance Epoch epoch => Timeable (ElapsedSinceP epoch) where
    timeGetElapsedP :: ElapsedSinceP epoch -> ElapsedP
timeGetElapsedP ElapsedSinceP epoch
es = Elapsed -> NanoSeconds -> ElapsedP
ElapsedP (Seconds -> Elapsed
Elapsed Seconds
e) NanoSeconds
ns
      where ElapsedSinceP (ElapsedSince Seconds
e) NanoSeconds
ns = ElapsedSinceP epoch -> ElapsedSinceP UnixEpoch
forall e1 e2.
(Epoch e1, Epoch e2) =>
ElapsedSinceP e1 -> ElapsedSinceP e2
convertEpochP ElapsedSinceP epoch
es :: ElapsedSinceP UnixEpoch
    timeGetNanoSeconds :: ElapsedSinceP epoch -> NanoSeconds
timeGetNanoSeconds (ElapsedSinceP ElapsedSince epoch
_ NanoSeconds
ns) = NanoSeconds
ns
instance Epoch epoch => Time (ElapsedSinceP epoch) where
    timeFromElapsedP :: ElapsedP -> ElapsedSinceP epoch
timeFromElapsedP (ElapsedP (Elapsed Seconds
e) NanoSeconds
ns) = ElapsedSinceP UnixEpoch -> ElapsedSinceP epoch
forall e1 e2.
(Epoch e1, Epoch e2) =>
ElapsedSinceP e1 -> ElapsedSinceP e2
convertEpochP (ElapsedSince UnixEpoch -> NanoSeconds -> ElapsedSinceP UnixEpoch
forall epoch.
ElapsedSince epoch -> NanoSeconds -> ElapsedSinceP epoch
ElapsedSinceP (Seconds -> ElapsedSince UnixEpoch
forall epoch. Seconds -> ElapsedSince epoch
ElapsedSince Seconds
e) NanoSeconds
ns :: ElapsedSinceP UnixEpoch)

-- | Convert Elapsed seconds to another epoch with explicit epochs specified
convertEpochWith :: (Epoch e1, Epoch e2) => (e1,e2) -> ElapsedSince e1 -> ElapsedSince e2
convertEpochWith :: (e1, e2) -> ElapsedSince e1 -> ElapsedSince e2
convertEpochWith (e1
e1,e2
e2) (ElapsedSince Seconds
s1) = Seconds -> ElapsedSince e2
forall epoch. Seconds -> ElapsedSince epoch
ElapsedSince (Seconds
s1 Seconds -> Seconds -> Seconds
forall a. Num a => a -> a -> a
+ Seconds
diff)
  where diff :: Seconds
diff = Seconds
d1 Seconds -> Seconds -> Seconds
forall a. Num a => a -> a -> a
- Seconds
d2
        d1 :: Seconds
d1 = e1 -> Seconds
forall epoch. Epoch epoch => epoch -> Seconds
epochDiffToUnix e1
e1
        d2 :: Seconds
d2 = e2 -> Seconds
forall epoch. Epoch epoch => epoch -> Seconds
epochDiffToUnix e2
e2

-- | Convert Elapsed seconds to another epoch.
--
-- the actual epochs need to be known somehow by the context, otherwise this function
-- will yield a compilation errors as the epoch are not chosen.
--
-- If you want to force specific epoch conversion, use convertEpochWith
convertEpoch :: (Epoch e1, Epoch e2) => ElapsedSince e1 -> ElapsedSince e2
convertEpoch :: ElapsedSince e1 -> ElapsedSince e2
convertEpoch = (e1, e2) -> ElapsedSince e1 -> ElapsedSince e2
forall e1 e2.
(Epoch e1, Epoch e2) =>
(e1, e2) -> ElapsedSince e1 -> ElapsedSince e2
convertEpochWith (e1
forall a. HasCallStack => a
undefined, e2
forall a. HasCallStack => a
undefined)

-- | Convert Precise Elapsed seconds to another epoch with explicit epochs specified
convertEpochPWith :: (Epoch e1, Epoch e2) => (e1,e2) -> ElapsedSinceP e1 -> ElapsedSinceP e2
convertEpochPWith :: (e1, e2) -> ElapsedSinceP e1 -> ElapsedSinceP e2
convertEpochPWith (e1, e2)
es (ElapsedSinceP ElapsedSince e1
e1 NanoSeconds
n1) = ElapsedSince e2 -> NanoSeconds -> ElapsedSinceP e2
forall epoch.
ElapsedSince epoch -> NanoSeconds -> ElapsedSinceP epoch
ElapsedSinceP ((e1, e2) -> ElapsedSince e1 -> ElapsedSince e2
forall e1 e2.
(Epoch e1, Epoch e2) =>
(e1, e2) -> ElapsedSince e1 -> ElapsedSince e2
convertEpochWith (e1, e2)
es ElapsedSince e1
e1) NanoSeconds
n1

-- | Convert Elapsed seconds to another epoch.
--
-- the actual epochs need to be known somehow by the context, otherwise this function
-- will yield a compilation errors as the epoch are not chosen.
--
-- If you want to force specific epoch conversion, use convertEpochWith
convertEpochP :: (Epoch e1, Epoch e2) => ElapsedSinceP e1 -> ElapsedSinceP e2
convertEpochP :: ElapsedSinceP e1 -> ElapsedSinceP e2
convertEpochP = (e1, e2) -> ElapsedSinceP e1 -> ElapsedSinceP e2
forall e1 e2.
(Epoch e1, Epoch e2) =>
(e1, e2) -> ElapsedSinceP e1 -> ElapsedSinceP e2
convertEpochPWith (e1
forall a. HasCallStack => a
undefined, e2
forall a. HasCallStack => a
undefined)