Skip to content

Commit

Permalink
Ensuring Time is nominally equivalent to UTCTime for Data.Coerce usage
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanhay committed May 16, 2018
1 parent f62da99 commit 896f019
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions core/src/Network/AWS/Data/Time.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
Expand Down Expand Up @@ -74,27 +73,19 @@ deriving instance Typeable 'BasicFormat
deriving instance Typeable 'AWSFormat
deriving instance Typeable 'POSIXFormat

data Time :: Format -> * where
Time :: UTCTime -> Time a
deriving (Data, Typeable, Generic)

deriving instance Eq (Time a)
deriving instance Ord (Time a)
deriving instance Read (Time a)
deriving instance Show (Time a)

instance NFData (Time a)
newtype Time (a :: Format) = Time { fromTime :: UTCTime }
deriving (Show, Read, Eq, Ord, Data, Typeable, Generic, NFData)

instance Hashable (Time a) where
hashWithSalt salt (Time (UTCTime (ModifiedJulianDay d) t)) =
salt `hashWithSalt` d
`hashWithSalt` toRational t

_Time :: Iso' (Time a) UTCTime
_Time = iso (\(Time t) -> t) Time
_Time = iso fromTime Time

convert :: Time a -> Time b
convert (Time t) = Time t
convert = Time . fromTime

type RFC822 = Time 'RFC822Format
type ISO8601 = Time 'ISO8601Format
Expand Down

0 comments on commit 896f019

Please sign in to comment.