{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveLift #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

-- |
-- Module      : Test.Amazonka.TH
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : provisional
-- Portability : non-portable (GHC extensions)
module Test.Amazonka.TH where

import Amazonka.Core
import Amazonka.Lens (view)
import Data.Time (Day (..), DiffTime, UTCTime (..))
import Language.Haskell.TH
import Language.Haskell.TH.Syntax

mkTime :: Text -> Q Exp
mkTime :: Text -> Q Exp
mkTime Text
x =
  case Text -> Either String ISO8601
forall a. FromText a => Text -> Either String a
fromText Text
x :: Either String ISO8601 of
    Left String
e -> String -> Q Exp
forall a. HasCallStack => String -> a
error (String -> String
forall a. Show a => a -> String
show String
e)
    Right ISO8601
t -> [|view _Time t|]

deriving instance Lift (Time a)

deriving instance Lift UTCTime

deriving instance Lift Day

-- DiffTime's constructor is not exported, so use a manual instance.
--
-- Note: An entire valid instance must be duplicated inside CPP to
-- otherwise the ormolu formatter will erroneously rewrite it.
#if MIN_VERSION_template_haskell(2,16,0)
instance Lift DiffTime where
  liftTyped :: DiffTime -> Q (TExp DiffTime)
liftTyped DiffTime
x = [||toEnum $$(liftTyped (fromEnum x))||]
#else
instance Lift DiffTime where
  lift x = [|toEnum $(lift (fromEnum x))|]
#endif