{-# OPTIONS_GHC -fno-warn-orphans #-}

module Polysemy.Time.Orphans where

import Data.Time (diffUTCTime, addUTCTime, NominalDiffTime, UTCTime)
import Torsor (Additive(..), Torsor(..))

instance Additive NominalDiffTime where
  zero :: NominalDiffTime
zero =
    NominalDiffTime
0
  invert :: NominalDiffTime -> NominalDiffTime
invert =
    Int -> NominalDiffTime
forall a. Enum a => Int -> a
toEnum (Int -> NominalDiffTime)
-> (NominalDiffTime -> Int) -> NominalDiffTime -> NominalDiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int
forall a. Num a => a -> a
negate (Int -> Int) -> (NominalDiffTime -> Int) -> NominalDiffTime -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NominalDiffTime -> Int
forall a. Enum a => a -> Int
fromEnum
  plus :: NominalDiffTime -> NominalDiffTime -> NominalDiffTime
plus =
    NominalDiffTime -> NominalDiffTime -> NominalDiffTime
forall a. Num a => a -> a -> a
(+)
  minus :: NominalDiffTime -> NominalDiffTime -> NominalDiffTime
minus =
    (-)

instance Torsor UTCTime NominalDiffTime where
  add :: NominalDiffTime -> UTCTime -> UTCTime
add NominalDiffTime
v UTCTime
p =
    NominalDiffTime -> UTCTime -> UTCTime
addUTCTime NominalDiffTime
v UTCTime
p
  difference :: UTCTime -> UTCTime -> NominalDiffTime
difference =
    UTCTime -> UTCTime -> NominalDiffTime
diffUTCTime