{-# LANGUAGE TypeApplications #-}

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

import           Data.Int
import           Data.Maybe
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 (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 = forall t. FormatTime t => TimeLocale -> String -> t -> String
DT.formatTime TimeLocale
DT.defaultTimeLocale (Maybe String -> String
DT.iso8601DateFormat (forall a. a -> Maybe a
Just String
"%H:%M:%SZ"))