{-# LANGUAGE UndecidableInstances #-}
module Kairos.Types.TimeFormat
( TimeFormat (..),
defaultTimeFormats,
hm,
hm12h,
hmTZ,
hmTZ12h,
rfc822,
)
where
import Control.DeepSeq (NFData)
import Data.List.NonEmpty (NonEmpty ((:|)))
import Data.String (IsString)
import Data.Text (Text)
import GHC.Generics (Generic)
import Optics.Core (An_Iso, LabelOptic (labelOptic), iso)
newtype TimeFormat = MkTimeFormat
{TimeFormat -> Text
unTimeFormat :: Text}
deriving stock
(
TimeFormat -> TimeFormat -> Bool
(TimeFormat -> TimeFormat -> Bool)
-> (TimeFormat -> TimeFormat -> Bool) -> Eq TimeFormat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TimeFormat -> TimeFormat -> Bool
== :: TimeFormat -> TimeFormat -> Bool
$c/= :: TimeFormat -> TimeFormat -> Bool
/= :: TimeFormat -> TimeFormat -> Bool
Eq,
(forall x. TimeFormat -> Rep TimeFormat x)
-> (forall x. Rep TimeFormat x -> TimeFormat) -> Generic TimeFormat
forall x. Rep TimeFormat x -> TimeFormat
forall x. TimeFormat -> Rep TimeFormat x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. TimeFormat -> Rep TimeFormat x
from :: forall x. TimeFormat -> Rep TimeFormat x
$cto :: forall x. Rep TimeFormat x -> TimeFormat
to :: forall x. Rep TimeFormat x -> TimeFormat
Generic,
Int -> TimeFormat -> ShowS
[TimeFormat] -> ShowS
TimeFormat -> String
(Int -> TimeFormat -> ShowS)
-> (TimeFormat -> String)
-> ([TimeFormat] -> ShowS)
-> Show TimeFormat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TimeFormat -> ShowS
showsPrec :: Int -> TimeFormat -> ShowS
$cshow :: TimeFormat -> String
show :: TimeFormat -> String
$cshowList :: [TimeFormat] -> ShowS
showList :: [TimeFormat] -> ShowS
Show
)
deriving anyclass
(
TimeFormat -> ()
(TimeFormat -> ()) -> NFData TimeFormat
forall a. (a -> ()) -> NFData a
$crnf :: TimeFormat -> ()
rnf :: TimeFormat -> ()
NFData
)
deriving
(
Semigroup TimeFormat
TimeFormat
Semigroup TimeFormat =>
TimeFormat
-> (TimeFormat -> TimeFormat -> TimeFormat)
-> ([TimeFormat] -> TimeFormat)
-> Monoid TimeFormat
[TimeFormat] -> TimeFormat
TimeFormat -> TimeFormat -> TimeFormat
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
$cmempty :: TimeFormat
mempty :: TimeFormat
$cmappend :: TimeFormat -> TimeFormat -> TimeFormat
mappend :: TimeFormat -> TimeFormat -> TimeFormat
$cmconcat :: [TimeFormat] -> TimeFormat
mconcat :: [TimeFormat] -> TimeFormat
Monoid,
String -> TimeFormat
(String -> TimeFormat) -> IsString TimeFormat
forall a. (String -> a) -> IsString a
$cfromString :: String -> TimeFormat
fromString :: String -> TimeFormat
IsString,
NonEmpty TimeFormat -> TimeFormat
TimeFormat -> TimeFormat -> TimeFormat
(TimeFormat -> TimeFormat -> TimeFormat)
-> (NonEmpty TimeFormat -> TimeFormat)
-> (forall b. Integral b => b -> TimeFormat -> TimeFormat)
-> Semigroup TimeFormat
forall b. Integral b => b -> TimeFormat -> TimeFormat
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: TimeFormat -> TimeFormat -> TimeFormat
<> :: TimeFormat -> TimeFormat -> TimeFormat
$csconcat :: NonEmpty TimeFormat -> TimeFormat
sconcat :: NonEmpty TimeFormat -> TimeFormat
$cstimes :: forall b. Integral b => b -> TimeFormat -> TimeFormat
stimes :: forall b. Integral b => b -> TimeFormat -> TimeFormat
Semigroup
)
via Text
instance
(k ~ An_Iso, a ~ Text, b ~ Text) =>
LabelOptic "unTimeFormat" k TimeFormat TimeFormat a b
where
labelOptic :: Optic k NoIx TimeFormat TimeFormat a b
labelOptic = (TimeFormat -> a)
-> (b -> TimeFormat) -> Iso TimeFormat TimeFormat a b
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (\(MkTimeFormat Text
f) -> a
Text
f) b -> TimeFormat
Text -> TimeFormat
MkTimeFormat
{-# INLINE labelOptic #-}
defaultTimeFormats :: NonEmpty TimeFormat
defaultTimeFormats :: NonEmpty TimeFormat
defaultTimeFormats =
TimeFormat
hm
TimeFormat -> [TimeFormat] -> NonEmpty TimeFormat
forall a. a -> [a] -> NonEmpty a
:| [ TimeFormat
hmNoColon,
TimeFormat
"%-I:%M %P",
TimeFormat
"%-I:%M%P",
TimeFormat
"%-I %P",
TimeFormat
"%-I%P"
]
hm :: TimeFormat
hm :: TimeFormat
hm = TimeFormat
"%H:%M"
{-# INLINE hm #-}
hmNoColon :: TimeFormat
hmNoColon :: TimeFormat
hmNoColon = TimeFormat
"%H%M"
{-# INLINE hmNoColon #-}
hm12h :: TimeFormat
hm12h :: TimeFormat
hm12h = TimeFormat
"%I:%M %P"
{-# INLINE hm12h #-}
hmTZ :: TimeFormat
hmTZ :: TimeFormat
hmTZ = TimeFormat
"%H:%M %Z"
{-# INLINE hmTZ #-}
hmTZ12h :: TimeFormat
hmTZ12h :: TimeFormat
hmTZ12h = TimeFormat
"%I:%M %P %Z"
{-# INLINE hmTZ12h #-}
rfc822 :: TimeFormat
rfc822 :: TimeFormat
rfc822 = TimeFormat
"%a, %_d %b %Y %H:%M:%S %Z"
{-# INLINE rfc822 #-}