{-# LANGUAGE TypeApplications #-}

module Hedgehog.Extras.Stock.Time
  ( showUTCTimeSeconds
  , formatIso8601
  ) where

import           Data.Int
import           Data.String
import           Data.Time.Clock (UTCTime)
import           Prelude (floor)
import           Text.Show

import qualified Data.Time.Clock.POSIX as DTC
import qualified Data.Time.Format as DT

-- | Show 'UTCTime' in seconds since epoch
showUTCTimeSeconds :: UTCTime -> String
showUTCTimeSeconds :: UTCTime -> String
showUTCTimeSeconds UTCTime
time = forall a. Show a => a -> String
show @Int64 (POSIXTime -> Int64
forall b. Integral b => POSIXTime -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor (UTCTime -> POSIXTime
DTC.utcTimeToPOSIXSeconds UTCTime
time))

-- | Format the given time as an ISO 8601 date-time string
formatIso8601 :: UTCTime -> String
formatIso8601 :: UTCTime -> String
formatIso8601 = TimeLocale -> String -> UTCTime -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
DT.formatTime TimeLocale
DT.defaultTimeLocale String
"%Y-%m-%dT%H:%M:%SZ"