-- |Diff Combinator, Internal
module Polysemy.Time.Diff where

import Torsor (Torsor, difference)

import Polysemy.Time.Class.Instant (Instant, dateTime)
import Polysemy.Time.Data.TimeUnit (TimeUnit, convert)

-- |Subtract two arbitrary values that can be converted to an 'Instant'.
diff ::
   dt u i1 i2 .
  TimeUnit u =>
  Torsor dt u =>
  Instant i1 dt =>
  Instant i2 dt =>
  i1 ->
  i2 ->
  u
diff :: forall dt u i1 i2.
(TimeUnit u, Torsor dt u, Instant i1 dt, Instant i2 dt) =>
i1 -> i2 -> u
diff i1
i1 i2
i2 =
  u -> u
forall a b. (TimeUnit a, TimeUnit b) => a -> b
convert (dt -> dt -> u
forall p v. Torsor p v => p -> p -> v
difference (i1 -> dt
forall i dt. Instant i dt => i -> dt
dateTime i1
i1) (i2 -> dt
forall i dt. Instant i dt => i -> dt
dateTime i2
i2))