module Kairos.Types.Date
(
Internal.Date (MkDate, MkDateString),
Internal.parseDateString,
Internal.unDateString,
Internal.unDate,
Internal.year,
Internal.month,
Internal.day,
_DateString,
)
where
import Data.Text (Text)
import Kairos.Types.Date.Internal (Date (MkDate, MkDateString))
import Kairos.Types.Date.Internal qualified as Internal
import Optics.Core (ReversedPrism', prism, re)
_DateString :: ReversedPrism' Date Text
_DateString :: ReversedPrism' Date Text
_DateString = Optic A_Prism NoIx Text Text Date Date
-> Optic (ReversedOptic A_Prism) NoIx Date Date Text Text
forall (is :: IxList) s t a b.
AcceptsEmptyIndices "re" is =>
Optic A_Prism is s t a b
-> Optic (ReversedOptic A_Prism) is b a t s
forall k (is :: IxList) s t a b.
(ReversibleOptic k, AcceptsEmptyIndices "re" is) =>
Optic k is s t a b -> Optic (ReversedOptic k) is b a t s
re (Optic A_Prism NoIx Text Text Date Date
-> Optic (ReversedOptic A_Prism) NoIx Date Date Text Text)
-> Optic A_Prism NoIx Text Text Date Date
-> Optic (ReversedOptic A_Prism) NoIx Date Date Text Text
forall a b. (a -> b) -> a -> b
$ (Date -> Text)
-> (Text -> Either Text Date)
-> Optic A_Prism NoIx Text Text Date Date
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism Date -> Text
Internal.unDateString Text -> Either Text Date
setter
where
setter :: Text -> Either Text Date
setter Text
t = case Text -> Maybe Date
forall (f :: * -> *). MonadFail f => Text -> f Date
Internal.parseDateString Text
t of
Maybe Date
Nothing -> Text -> Either Text Date
forall a b. a -> Either a b
Left Text
t
Just Date
d -> Date -> Either Text Date
forall a b. b -> Either a b
Right Date
d
{-# INLINE _DateString #-}