module Patrol.Type.Timestamp
  ( Timestamp
  , fromUtcTime
  , toUtcTime
  ) where

import qualified Data.Aeson as Aeson
import qualified Data.Time as Time

-- | <https://develop.sentry.dev/sdk/event-payloads/#required-attributes>
newtype Timestamp
  = Timestamp Time.UTCTime
  deriving (Timestamp -> Timestamp -> Bool
(Timestamp -> Timestamp -> Bool)
-> (Timestamp -> Timestamp -> Bool) -> Eq Timestamp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Timestamp -> Timestamp -> Bool
$c/= :: Timestamp -> Timestamp -> Bool
== :: Timestamp -> Timestamp -> Bool
$c== :: Timestamp -> Timestamp -> Bool
Eq, Int -> Timestamp -> ShowS
[Timestamp] -> ShowS
Timestamp -> String
(Int -> Timestamp -> ShowS)
-> (Timestamp -> String)
-> ([Timestamp] -> ShowS)
-> Show Timestamp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Timestamp] -> ShowS
$cshowList :: [Timestamp] -> ShowS
show :: Timestamp -> String
$cshow :: Timestamp -> String
showsPrec :: Int -> Timestamp -> ShowS
$cshowsPrec :: Int -> Timestamp -> ShowS
Show)

instance Aeson.ToJSON Timestamp where
  toJSON :: Timestamp -> Value
toJSON = String -> Value
forall a. ToJSON a => a -> Value
Aeson.toJSON (String -> Value) -> (Timestamp -> String) -> Timestamp -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeLocale -> String -> UTCTime -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
Time.formatTime TimeLocale
Time.defaultTimeLocale String
"%Y-%m-%dT%H:%M:%SZ" (UTCTime -> String)
-> (Timestamp -> UTCTime) -> Timestamp -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Timestamp -> UTCTime
toUtcTime

fromUtcTime :: Time.UTCTime -> Timestamp
fromUtcTime :: UTCTime -> Timestamp
fromUtcTime = UTCTime -> Timestamp
Timestamp

toUtcTime :: Timestamp -> Time.UTCTime
toUtcTime :: Timestamp -> UTCTime
toUtcTime (Timestamp UTCTime
x) = UTCTime
x