{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeOperators #-}
module Data.HodaTime.Pattern.CalendarDate
(
pd
,pD
,pR
,pmonthDay
,pyearMonth
,pyear
,pyyyy
,pyy
,pmonthNum
,pMM
,pMMM
,pMMMM
,pMMM'
,pMMMM'
,pMonthName
,pday
,pdd
,pdaySpace
,pddd
,pdddd
,pddd'
,pdddd'
,pDayName
)
where
import Data.HodaTime.Pattern.Internal
import Data.HodaTime.CalendarDateTime.Internal (HasDate, Month, MoY, IsCalendar, setMonthIndex, dayOfWeek, DoW)
import qualified Data.HodaTime.CalendarDateTime.Internal as CDT (day, setDay, month, year, setYear)
import qualified Data.Text as T
import qualified Data.Text.Lazy.Builder as TLB
import Text.Parsec (choice, try, (<?>))
import Formatting (later)
import Data.HodaTime.Locale.Internal (Locale(..))
pyear :: HasDate d => Int -> Pattern (d -> d) (d -> String) String
pyear :: forall d. HasDate d => Int -> Pattern (d -> d) (d -> String) String
pyear Int
w = (d -> Int)
-> (Int -> d -> d)
-> Parser Int String
-> ((d -> Int) -> Format String (d -> String))
-> String
-> Pattern (d -> d) (d -> String) String
forall s a.
(s -> a)
-> (a -> s -> s)
-> Parser a String
-> ((s -> a) -> Format String (s -> String))
-> String
-> Pattern (s -> s) (s -> String) String
pat_field d -> Int
forall d. HasDate d => d -> Int
CDT.year Int -> d -> d
forall d. HasDate d => Int -> d -> d
CDT.setYear (Int -> Int -> Int -> Int -> Parser Int String
pDigits Int
w Int
4 Int
0 Int
9999) (Int -> (d -> Int) -> Format String (d -> String)
forall b a r. Show b => Int -> (a -> b) -> Format r (a -> r)
f_shown_pad Int
w) String
"year: 0-9999"
pyyyy :: HasDate d => Pattern (d -> d) (d -> String) String
pyyyy :: forall d. HasDate d => Pattern (d -> d) (d -> String) String
pyyyy = Int -> Pattern (d -> d) (d -> String) String
forall d. HasDate d => Int -> Pattern (d -> d) (d -> String) String
pyear Int
4
pyy :: HasDate d => Pattern (d -> d) (d -> String) String
pyy :: forall d. HasDate d => Pattern (d -> d) (d -> String) String
pyy = Parser (d -> d) String
-> Format String (d -> String)
-> Pattern (d -> d) (d -> String) String
forall a b r. Parser a r -> Format r b -> Pattern a b r
Pattern Parser (d -> d) String
par Format String (d -> String)
forall {r}. Format r (d -> r)
fmt
where
par :: Parser (d -> d) String
par = Int -> d -> d
forall d. HasDate d => Int -> d -> d
expand (Int -> d -> d) -> Parser Int String -> Parser (d -> d) String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Int -> Int -> Int -> Parser Int String
pDigits Int
2 Int
2 Int
0 Int
99 Parser (d -> d) String -> String -> Parser (d -> d) String
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"year: two digits (century inferred)"
expand :: Int -> d -> d
expand Int
v d
d = Int -> d -> d
forall d. HasDate d => Int -> d -> d
CDT.setYear (Int -> Int -> Int
forall {a}. Integral a => a -> a -> a
fullYear (d -> Int
forall d. HasDate d => d -> Int
CDT.year d
d) Int
v) d
d
fmt :: Format r (d -> r)
fmt = Int -> (d -> Int) -> Format r (d -> r)
forall b a r. Show b => Int -> (a -> b) -> Format r (a -> r)
f_shown_pad Int
2 (\d
d -> d -> Int
forall d. HasDate d => d -> Int
CDT.year d
d Int -> Int -> Int
forall {a}. Integral a => a -> a -> a
`mod` Int
100)
fullYear :: a -> a -> a
fullYear a
t a
v = a
base a -> a -> a
forall a. Num a => a -> a -> a
+ a
k a -> a -> a
forall a. Num a => a -> a -> a
* a
100
where
base :: a
base = (a
t a -> a -> a
forall {a}. Integral a => a -> a -> a
`div` a
100) a -> a -> a
forall a. Num a => a -> a -> a
* a
100 a -> a -> a
forall a. Num a => a -> a -> a
+ a
v
k :: a
k = (a
t a -> a -> a
forall a. Num a => a -> a -> a
- a
base a -> a -> a
forall a. Num a => a -> a -> a
+ a
50) a -> a -> a
forall {a}. Integral a => a -> a -> a
`div` a
100
pmonthNum :: (HasDate d, Enum (MoY d)) => Int -> Pattern (d -> d) (d -> String) String
pmonthNum :: forall d.
(HasDate d, Enum (MoY d)) =>
Int -> Pattern (d -> d) (d -> String) String
pmonthNum Int
w = (d -> Int)
-> (Int -> d -> d)
-> Parser Int String
-> ((d -> Int) -> Format String (d -> String))
-> String
-> Pattern (d -> d) (d -> String) String
forall s a.
(s -> a)
-> (a -> s -> s)
-> Parser a String
-> ((s -> a) -> Format String (s -> String))
-> String
-> Pattern (s -> s) (s -> String) String
pat_field (MoY d -> Int
forall a. Enum a => a -> Int
fromEnum (MoY d -> Int) -> (d -> MoY d) -> d -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> MoY d
forall d. HasDate d => d -> MoY d
CDT.month) Int -> d -> d
forall d. HasDate d => Int -> d -> d
setMonthIndex (Int -> Int -> Int
forall a. Num a => a -> a -> a
subtract Int
1 (Int -> Int) -> Parser Int String -> Parser Int String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> Int -> Int -> Int -> Parser Int String
pDigits Int
w Int
2 Int
1 Int
12) (d -> Int) -> Format String (d -> String)
fmt String
"month: 1-12"
where
fmt :: (d -> Int) -> Format String (d -> String)
fmt d -> Int
x = Int -> (d -> Int) -> Format String (d -> String)
forall b a r. Show b => Int -> (a -> b) -> Format r (a -> r)
f_shown_pad Int
w (Int -> Int
forall a. Enum a => a -> a
succ (Int -> Int) -> (d -> Int) -> d -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> Int
x)
pMM :: (HasDate d, Enum (MoY d)) => Pattern (d -> d) (d -> String) String
pMM :: forall d.
(HasDate d, Enum (MoY d)) =>
Pattern (d -> d) (d -> String) String
pMM = Int -> Pattern (d -> d) (d -> String) String
forall d.
(HasDate d, Enum (MoY d)) =>
Int -> Pattern (d -> d) (d -> String) String
pmonthNum Int
2
pMMMM :: forall cal d c. (d ~ c cal, MoY d ~ Month cal, IsCalendar cal, HasDate d, Bounded (Month cal), Read (Month cal), Show (Month cal), Enum (Month cal)) => Pattern (d -> d) (d -> String) String
pMMMM :: forall cal d (c :: * -> *).
(d ~ c cal, MoY d ~ Month cal, IsCalendar cal, HasDate d,
Bounded (Month cal), Read (Month cal), Show (Month cal),
Enum (Month cal)) =>
Pattern (d -> d) (d -> String) String
pMMMM = (d -> Int)
-> (Int -> d -> d)
-> Parser Int String
-> ((d -> Int) -> Format String (d -> String))
-> String
-> Pattern (d -> d) (d -> String) String
forall s a.
(s -> a)
-> (a -> s -> s)
-> Parser a String
-> ((s -> a) -> Format String (s -> String))
-> String
-> Pattern (s -> s) (s -> String) String
pat_field (Month cal -> Int
forall a. Enum a => a -> Int
fromEnum (Month cal -> Int) -> (d -> Month cal) -> d -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> MoY d
d -> Month cal
forall d. HasDate d => d -> MoY d
CDT.month) Int -> d -> d
forall d. HasDate d => Int -> d -> d
setMonthIndex Parser Int String
p' (d -> Int) -> Format String (d -> String)
fmt' (String -> Pattern (d -> d) (d -> String) String)
-> String -> Pattern (d -> d) (d -> String) String
forall a b. (a -> b) -> a -> b
$ String
"month: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Month cal -> String
forall a. Show a => a -> String
show Month cal
fm String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"-" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Month cal -> String
forall a. Show a => a -> String
show Month cal
lm
where
fm :: Month cal
fm = Month cal
forall a. Bounded a => a
minBound :: Month cal
lm :: Month cal
lm = Month cal
forall a. Bounded a => a
maxBound :: Month cal
months :: ParsecT String () Identity String
months = [ParsecT String () Identity String]
-> ParsecT String () Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ([ParsecT String () Identity String]
-> ParsecT String () Identity String)
-> ([Month cal] -> [ParsecT String () Identity String])
-> [Month cal]
-> ParsecT String () Identity String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Month cal -> ParsecT String () Identity String)
-> [Month cal] -> [ParsecT String () Identity String]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () Identity String
-> ParsecT String () Identity String)
-> (Month cal -> ParsecT String () Identity String)
-> Month cal
-> ParsecT String () Identity String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ParsecT String () Identity String
caseInsensitiveString (String -> ParsecT String () Identity String)
-> (Month cal -> String)
-> Month cal
-> ParsecT String () Identity String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Month cal -> String
forall a. Show a => a -> String
show) ([Month cal] -> ParsecT String () Identity String)
-> [Month cal] -> ParsecT String () Identity String
forall a b. (a -> b) -> a -> b
$ [Month cal
fm..Month cal
lm]
p' :: Parser Int String
p' = (Month cal -> Int
forall a. Enum a => a -> Int
fromEnum :: Month cal -> Int) (Month cal -> Int) -> (String -> Month cal) -> String -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Month cal
forall a. Read a => String -> a
read (String -> Int)
-> ParsecT String () Identity String -> Parser Int String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT String () Identity String
months
fmt' :: (d -> Int) -> Format String (d -> String)
fmt' d -> Int
x = (d -> Builder) -> Format String (d -> String)
forall a r. (a -> Builder) -> Format r (a -> r)
later (Text -> Builder
TLB.fromText (Text -> Builder) -> (d -> Text) -> d -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Text) -> (d -> String) -> d -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Month cal -> String
forall a. Show a => a -> String
show (Month cal -> String) -> (d -> Month cal) -> d -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Month cal
forall a. Enum a => Int -> a
toEnum :: Int -> Month cal) (Int -> Month cal) -> (d -> Int) -> d -> Month cal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> Int
x)
pMMM :: forall cal d c. (d ~ c cal, MoY d ~ Month cal, IsCalendar cal, HasDate d, Bounded (Month cal), Show (Month cal), Enum (Month cal)) => Pattern (d -> d) (d -> String) String
pMMM :: forall cal d (c :: * -> *).
(d ~ c cal, MoY d ~ Month cal, IsCalendar cal, HasDate d,
Bounded (Month cal), Show (Month cal), Enum (Month cal)) =>
Pattern (d -> d) (d -> String) String
pMMM = (d -> Int)
-> (Int -> d -> d)
-> Parser Int String
-> ((d -> Int) -> Format String (d -> String))
-> String
-> Pattern (d -> d) (d -> String) String
forall s a.
(s -> a)
-> (a -> s -> s)
-> Parser a String
-> ((s -> a) -> Format String (s -> String))
-> String
-> Pattern (s -> s) (s -> String) String
pat_field (Month cal -> Int
forall a. Enum a => a -> Int
fromEnum (Month cal -> Int) -> (d -> Month cal) -> d -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> MoY d
d -> Month cal
forall d. HasDate d => d -> MoY d
CDT.month) Int -> d -> d
forall d. HasDate d => Int -> d -> d
setMonthIndex Parser Int String
p' (d -> Int) -> Format String (d -> String)
fmt' (String -> Pattern (d -> d) (d -> String) String)
-> String -> Pattern (d -> d) (d -> String) String
forall a b. (a -> b) -> a -> b
$ String
"month: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Month cal -> String
abbr Month cal
fm String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"-" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Month cal -> String
abbr Month cal
lm
where
fm :: Month cal
fm = Month cal
forall a. Bounded a => a
minBound :: Month cal
lm :: Month cal
lm = Month cal
forall a. Bounded a => a
maxBound :: Month cal
abbr :: Month cal -> String
abbr = Int -> String -> String
forall a. Int -> [a] -> [a]
take Int
3 (String -> String) -> (Month cal -> String) -> Month cal -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Month cal -> String
forall a. Show a => a -> String
show
p' :: Parser Int String
p' = [Parser Int String] -> Parser Int String
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ([Parser Int String] -> Parser Int String)
-> ([Month cal] -> [Parser Int String])
-> [Month cal]
-> Parser Int String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Month cal -> Parser Int String)
-> [Month cal] -> [Parser Int String]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Month cal
m -> Month cal -> Int
forall a. Enum a => a -> Int
fromEnum Month cal
m Int -> ParsecT String () Identity String -> Parser Int String
forall a b.
a -> ParsecT String () Identity b -> ParsecT String () Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (String -> ParsecT String () Identity String
caseInsensitiveString (Month cal -> String
abbr Month cal
m))) ([Month cal] -> Parser Int String)
-> [Month cal] -> Parser Int String
forall a b. (a -> b) -> a -> b
$ [Month cal
fm..Month cal
lm]
fmt' :: (d -> Int) -> Format String (d -> String)
fmt' d -> Int
x = (d -> Builder) -> Format String (d -> String)
forall a r. (a -> Builder) -> Format r (a -> r)
later (Text -> Builder
TLB.fromText (Text -> Builder) -> (d -> Text) -> d -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Text) -> (d -> String) -> d -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Month cal -> String
abbr (Month cal -> String) -> (d -> Month cal) -> d -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Month cal
forall a. Enum a => Int -> a
toEnum :: Int -> Month cal) (Int -> Month cal) -> (d -> Int) -> d -> Month cal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> Int
x)
pday :: HasDate d => Int -> Pattern (d -> d) (d -> String) String
pday :: forall d. HasDate d => Int -> Pattern (d -> d) (d -> String) String
pday Int
w = (d -> Int)
-> (Int -> d -> d)
-> Parser Int String
-> ((d -> Int) -> Format String (d -> String))
-> String
-> Pattern (d -> d) (d -> String) String
forall s a.
(s -> a)
-> (a -> s -> s)
-> Parser a String
-> ((s -> a) -> Format String (s -> String))
-> String
-> Pattern (s -> s) (s -> String) String
pat_field d -> Int
forall d. HasDate d => d -> Int
CDT.day Int -> d -> d
forall d. HasDate d => Int -> d -> d
CDT.setDay (Int -> Int -> Int -> Int -> Parser Int String
pDigits Int
w Int
2 Int
1 Int
31) (Int -> (d -> Int) -> Format String (d -> String)
forall b a r. Show b => Int -> (a -> b) -> Format r (a -> r)
f_shown_pad Int
w) String
"day: 1-31"
pdd :: HasDate d => Pattern (d -> d) (d -> String) String
pdd :: forall d. HasDate d => Pattern (d -> d) (d -> String) String
pdd = Int -> Pattern (d -> d) (d -> String) String
forall d. HasDate d => Int -> Pattern (d -> d) (d -> String) String
pday Int
2
pdaySpace :: HasDate d => Pattern (d -> d) (d -> String) String
pdaySpace :: forall d. HasDate d => Pattern (d -> d) (d -> String) String
pdaySpace = (d -> Int)
-> (Int -> d -> d)
-> Parser Int String
-> ((d -> Int) -> Format String (d -> String))
-> String
-> Pattern (d -> d) (d -> String) String
forall s a.
(s -> a)
-> (a -> s -> s)
-> Parser a String
-> ((s -> a) -> Format String (s -> String))
-> String
-> Pattern (s -> s) (s -> String) String
pat_field d -> Int
forall d. HasDate d => d -> Int
CDT.day Int -> d -> d
forall d. HasDate d => Int -> d -> d
CDT.setDay (Int -> Int -> Int -> Parser Int String
pDigitsSpace Int
2 Int
1 Int
31) (Int -> (d -> Int) -> Format String (d -> String)
forall b a r. Show b => Int -> (a -> b) -> Format r (a -> r)
f_shown_spad Int
2) String
"day: 1-31 (space padded)"
pddd :: forall d. (HasDate d, Show (DoW d), Enum (DoW d), Bounded (DoW d)) => Pattern (d -> d) (d -> String) String
pddd :: forall d.
(HasDate d, Show (DoW d), Enum (DoW d), Bounded (DoW d)) =>
Pattern (d -> d) (d -> String) String
pddd = Parser (d -> d) String
-> Format String (d -> String)
-> Pattern (d -> d) (d -> String) String
forall a b r. Parser a r -> Format r b -> Pattern a b r
Pattern Parser (d -> d) String
par Format String (d -> String)
fmt
where
names :: [DoW d]
names = [DoW d
forall a. Bounded a => a
minBound .. DoW d
forall a. Bounded a => a
maxBound] :: [DoW d]
abbr :: DoW d -> String
abbr = Int -> String -> String
forall a. Int -> [a] -> [a]
take Int
3 (String -> String) -> (DoW d -> String) -> DoW d -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DoW d -> String
forall a. Show a => a -> String
show
par :: Parser (d -> d) String
par = d -> d
forall a. a -> a
id (d -> d)
-> ParsecT String () Identity String -> Parser (d -> d) String
forall a b.
a -> ParsecT String () Identity b -> ParsecT String () Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ([ParsecT String () Identity String]
-> ParsecT String () Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ([ParsecT String () Identity String]
-> ParsecT String () Identity String)
-> ([DoW d] -> [ParsecT String () Identity String])
-> [DoW d]
-> ParsecT String () Identity String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DoW d -> ParsecT String () Identity String)
-> [DoW d] -> [ParsecT String () Identity String]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () Identity String
-> ParsecT String () Identity String)
-> (DoW d -> ParsecT String () Identity String)
-> DoW d
-> ParsecT String () Identity String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ParsecT String () Identity String
caseInsensitiveString (String -> ParsecT String () Identity String)
-> (DoW d -> String) -> DoW d -> ParsecT String () Identity String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DoW d -> String
abbr) ([DoW d] -> ParsecT String () Identity String)
-> [DoW d] -> ParsecT String () Identity String
forall a b. (a -> b) -> a -> b
$ [DoW d]
names)
fmt :: Format String (d -> String)
fmt = (d -> Builder) -> Format String (d -> String)
forall a r. (a -> Builder) -> Format r (a -> r)
later (Text -> Builder
TLB.fromText (Text -> Builder) -> (d -> Text) -> d -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Text) -> (d -> String) -> d -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DoW d -> String
abbr (DoW d -> String) -> (d -> DoW d) -> d -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> DoW d
forall d. HasDate d => d -> DoW d
dayOfWeek)
pdddd :: forall d. (HasDate d, Show (DoW d), Enum (DoW d), Bounded (DoW d)) => Pattern (d -> d) (d -> String) String
pdddd :: forall d.
(HasDate d, Show (DoW d), Enum (DoW d), Bounded (DoW d)) =>
Pattern (d -> d) (d -> String) String
pdddd = Parser (d -> d) String
-> Format String (d -> String)
-> Pattern (d -> d) (d -> String) String
forall a b r. Parser a r -> Format r b -> Pattern a b r
Pattern Parser (d -> d) String
par Format String (d -> String)
forall {r}. Format r (d -> r)
fmt
where
names :: [DoW d]
names = [DoW d
forall a. Bounded a => a
minBound .. DoW d
forall a. Bounded a => a
maxBound] :: [DoW d]
par :: Parser (d -> d) String
par = d -> d
forall a. a -> a
id (d -> d)
-> ParsecT String () Identity String -> Parser (d -> d) String
forall a b.
a -> ParsecT String () Identity b -> ParsecT String () Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ([ParsecT String () Identity String]
-> ParsecT String () Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ([ParsecT String () Identity String]
-> ParsecT String () Identity String)
-> ([DoW d] -> [ParsecT String () Identity String])
-> [DoW d]
-> ParsecT String () Identity String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DoW d -> ParsecT String () Identity String)
-> [DoW d] -> [ParsecT String () Identity String]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () Identity String
-> ParsecT String () Identity String)
-> (DoW d -> ParsecT String () Identity String)
-> DoW d
-> ParsecT String () Identity String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ParsecT String () Identity String
caseInsensitiveString (String -> ParsecT String () Identity String)
-> (DoW d -> String) -> DoW d -> ParsecT String () Identity String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DoW d -> String
forall a. Show a => a -> String
show) ([DoW d] -> ParsecT String () Identity String)
-> [DoW d] -> ParsecT String () Identity String
forall a b. (a -> b) -> a -> b
$ [DoW d]
names)
fmt :: Format r (d -> r)
fmt = (d -> Builder) -> Format r (d -> r)
forall a r. (a -> Builder) -> Format r (a -> r)
later (Text -> Builder
TLB.fromText (Text -> Builder) -> (d -> Text) -> d -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Text) -> (d -> String) -> d -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DoW d -> String
forall a. Show a => a -> String
show (DoW d -> String) -> (d -> DoW d) -> d -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> DoW d
forall d. HasDate d => d -> DoW d
dayOfWeek)
pd :: (HasDate d, Enum (MoY d)) => Pattern (d -> d) (d -> String) String
pd :: forall d.
(HasDate d, Enum (MoY d)) =>
Pattern (d -> d) (d -> String) String
pd = Pattern (d -> d) (d -> String) String
forall d. HasDate d => Pattern (d -> d) (d -> String) String
pdd Pattern (d -> d) (d -> String) String
-> Pattern Char String String
-> Pattern (d -> d) (d -> String) String
forall a b r c. Pattern a b r -> Pattern c r r -> Pattern a b r
<% Char -> Pattern Char String String
char Char
'/' Pattern (d -> d) (d -> String) String
-> Pattern (d -> d) (d -> String) String
-> Pattern (d -> d) (d -> String) String
forall a. Semigroup a => a -> a -> a
<> Pattern (d -> d) (d -> String) String
forall d.
(HasDate d, Enum (MoY d)) =>
Pattern (d -> d) (d -> String) String
pMM Pattern (d -> d) (d -> String) String
-> Pattern Char String String
-> Pattern (d -> d) (d -> String) String
forall a b r c. Pattern a b r -> Pattern c r r -> Pattern a b r
<% Char -> Pattern Char String String
char Char
'/' Pattern (d -> d) (d -> String) String
-> Pattern (d -> d) (d -> String) String
-> Pattern (d -> d) (d -> String) String
forall a. Semigroup a => a -> a -> a
<> Pattern (d -> d) (d -> String) String
forall d. HasDate d => Pattern (d -> d) (d -> String) String
pyyyy
pD :: (HasDate (c cal), MoY (c cal) ~ Month cal, IsCalendar cal, Bounded (Month cal), Read (Month cal), Show (Month cal), Enum (Month cal), Show (DoW (c cal)), Enum (DoW (c cal)), Bounded (DoW (c cal))) => Pattern (c cal -> c cal) (c cal -> String) String
pD :: forall (c :: * -> *) cal.
(HasDate (c cal), MoY (c cal) ~ Month cal, IsCalendar cal,
Bounded (Month cal), Read (Month cal), Show (Month cal),
Enum (Month cal), Show (DoW (c cal)), Enum (DoW (c cal)),
Bounded (DoW (c cal))) =>
Pattern (c cal -> c cal) (c cal -> String) String
pD = Pattern (c cal -> c cal) (c cal -> String) String
forall d.
(HasDate d, Show (DoW d), Enum (DoW d), Bounded (DoW d)) =>
Pattern (d -> d) (d -> String) String
pdddd Pattern (c cal -> c cal) (c cal -> String) String
-> Pattern String String String
-> Pattern (c cal -> c cal) (c cal -> String) String
forall a b r c. Pattern a b r -> Pattern c r r -> Pattern a b r
<% String -> Pattern String String String
string String
", " Pattern (c cal -> c cal) (c cal -> String) String
-> Pattern (c cal -> c cal) (c cal -> String) String
-> Pattern (c cal -> c cal) (c cal -> String) String
forall a. Semigroup a => a -> a -> a
<> Pattern (c cal -> c cal) (c cal -> String) String
forall d. HasDate d => Pattern (d -> d) (d -> String) String
pdd Pattern (c cal -> c cal) (c cal -> String) String
-> Pattern Char String String
-> Pattern (c cal -> c cal) (c cal -> String) String
forall a b r c. Pattern a b r -> Pattern c r r -> Pattern a b r
<% Char -> Pattern Char String String
char Char
' ' Pattern (c cal -> c cal) (c cal -> String) String
-> Pattern (c cal -> c cal) (c cal -> String) String
-> Pattern (c cal -> c cal) (c cal -> String) String
forall a. Semigroup a => a -> a -> a
<> Pattern (c cal -> c cal) (c cal -> String) String
forall cal d (c :: * -> *).
(d ~ c cal, MoY d ~ Month cal, IsCalendar cal, HasDate d,
Bounded (Month cal), Read (Month cal), Show (Month cal),
Enum (Month cal)) =>
Pattern (d -> d) (d -> String) String
pMMMM Pattern (c cal -> c cal) (c cal -> String) String
-> Pattern Char String String
-> Pattern (c cal -> c cal) (c cal -> String) String
forall a b r c. Pattern a b r -> Pattern c r r -> Pattern a b r
<% Char -> Pattern Char String String
char Char
' ' Pattern (c cal -> c cal) (c cal -> String) String
-> Pattern (c cal -> c cal) (c cal -> String) String
-> Pattern (c cal -> c cal) (c cal -> String) String
forall a. Semigroup a => a -> a -> a
<> Pattern (c cal -> c cal) (c cal -> String) String
forall d. HasDate d => Pattern (d -> d) (d -> String) String
pyyyy
pR :: (HasDate d, Enum (MoY d)) => Pattern (d -> d) (d -> String) String
pR :: forall d.
(HasDate d, Enum (MoY d)) =>
Pattern (d -> d) (d -> String) String
pR = Pattern (d -> d) (d -> String) String
forall d. HasDate d => Pattern (d -> d) (d -> String) String
pyyyy Pattern (d -> d) (d -> String) String
-> Pattern Char String String
-> Pattern (d -> d) (d -> String) String
forall a b r c. Pattern a b r -> Pattern c r r -> Pattern a b r
<% Char -> Pattern Char String String
char Char
'-' Pattern (d -> d) (d -> String) String
-> Pattern (d -> d) (d -> String) String
-> Pattern (d -> d) (d -> String) String
forall a. Semigroup a => a -> a -> a
<> Pattern (d -> d) (d -> String) String
forall d.
(HasDate d, Enum (MoY d)) =>
Pattern (d -> d) (d -> String) String
pMM Pattern (d -> d) (d -> String) String
-> Pattern Char String String
-> Pattern (d -> d) (d -> String) String
forall a b r c. Pattern a b r -> Pattern c r r -> Pattern a b r
<% Char -> Pattern Char String String
char Char
'-' Pattern (d -> d) (d -> String) String
-> Pattern (d -> d) (d -> String) String
-> Pattern (d -> d) (d -> String) String
forall a. Semigroup a => a -> a -> a
<> Pattern (d -> d) (d -> String) String
forall d. HasDate d => Pattern (d -> d) (d -> String) String
pdd
pmonthDay :: (HasDate (c cal), MoY (c cal) ~ Month cal, IsCalendar cal, Bounded (Month cal), Read (Month cal), Show (Month cal), Enum (Month cal)) => Pattern (c cal -> c cal) (c cal -> String) String
pmonthDay :: forall (c :: * -> *) cal.
(HasDate (c cal), MoY (c cal) ~ Month cal, IsCalendar cal,
Bounded (Month cal), Read (Month cal), Show (Month cal),
Enum (Month cal)) =>
Pattern (c cal -> c cal) (c cal -> String) String
pmonthDay = Pattern (c cal -> c cal) (c cal -> String) String
forall cal d (c :: * -> *).
(d ~ c cal, MoY d ~ Month cal, IsCalendar cal, HasDate d,
Bounded (Month cal), Read (Month cal), Show (Month cal),
Enum (Month cal)) =>
Pattern (d -> d) (d -> String) String
pMMMM Pattern (c cal -> c cal) (c cal -> String) String
-> Pattern Char String String
-> Pattern (c cal -> c cal) (c cal -> String) String
forall a b r c. Pattern a b r -> Pattern c r r -> Pattern a b r
<% Char -> Pattern Char String String
char Char
' ' Pattern (c cal -> c cal) (c cal -> String) String
-> Pattern (c cal -> c cal) (c cal -> String) String
-> Pattern (c cal -> c cal) (c cal -> String) String
forall a. Semigroup a => a -> a -> a
<> Pattern (c cal -> c cal) (c cal -> String) String
forall d. HasDate d => Pattern (d -> d) (d -> String) String
pdd
pyearMonth :: (HasDate (c cal), MoY (c cal) ~ Month cal, IsCalendar cal, Bounded (Month cal), Read (Month cal), Show (Month cal), Enum (Month cal)) => Pattern (c cal -> c cal) (c cal -> String) String
pyearMonth :: forall (c :: * -> *) cal.
(HasDate (c cal), MoY (c cal) ~ Month cal, IsCalendar cal,
Bounded (Month cal), Read (Month cal), Show (Month cal),
Enum (Month cal)) =>
Pattern (c cal -> c cal) (c cal -> String) String
pyearMonth = Pattern (c cal -> c cal) (c cal -> String) String
forall d. HasDate d => Pattern (d -> d) (d -> String) String
pyyyy Pattern (c cal -> c cal) (c cal -> String) String
-> Pattern Char String String
-> Pattern (c cal -> c cal) (c cal -> String) String
forall a b r c. Pattern a b r -> Pattern c r r -> Pattern a b r
<% Char -> Pattern Char String String
char Char
' ' Pattern (c cal -> c cal) (c cal -> String) String
-> Pattern (c cal -> c cal) (c cal -> String) String
-> Pattern (c cal -> c cal) (c cal -> String) String
forall a. Semigroup a => a -> a -> a
<> Pattern (c cal -> c cal) (c cal -> String) String
forall cal d (c :: * -> *).
(d ~ c cal, MoY d ~ Month cal, IsCalendar cal, HasDate d,
Bounded (Month cal), Read (Month cal), Show (Month cal),
Enum (Month cal)) =>
Pattern (d -> d) (d -> String) String
pMMMM
pMonthName :: (HasDate d, Enum (MoY d)) => [String] -> Pattern (d -> d) (d -> String) String
pMonthName :: forall d.
(HasDate d, Enum (MoY d)) =>
[String] -> Pattern (d -> d) (d -> String) String
pMonthName [String]
names = (d -> Int)
-> (Int -> d -> d)
-> Parser Int String
-> ((d -> Int) -> Format String (d -> String))
-> String
-> Pattern (d -> d) (d -> String) String
forall s a.
(s -> a)
-> (a -> s -> s)
-> Parser a String
-> ((s -> a) -> Format String (s -> String))
-> String
-> Pattern (s -> s) (s -> String) String
pat_field (MoY d -> Int
forall a. Enum a => a -> Int
fromEnum (MoY d -> Int) -> (d -> MoY d) -> d -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> MoY d
forall d. HasDate d => d -> MoY d
CDT.month) Int -> d -> d
forall d. HasDate d => Int -> d -> d
setMonthIndex Parser Int String
par (d -> Int) -> Format String (d -> String)
fmt String
"month name"
where
par :: Parser Int String
par = [Parser Int String] -> Parser Int String
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ([Parser Int String] -> Parser Int String)
-> ([(Int, String)] -> [Parser Int String])
-> [(Int, String)]
-> Parser Int String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Int, String) -> Parser Int String)
-> [(Int, String)] -> [Parser Int String]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Int
i, String
n) -> Int
i Int -> ParsecT String () Identity String -> Parser Int String
forall a b.
a -> ParsecT String () Identity b -> ParsecT String () Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (String -> ParsecT String () Identity String
caseInsensitiveString String
n)) ([(Int, String)] -> Parser Int String)
-> [(Int, String)] -> Parser Int String
forall a b. (a -> b) -> a -> b
$ [Int] -> [String] -> [(Int, String)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0 :: Int ..] [String]
names
fmt :: (d -> Int) -> Format String (d -> String)
fmt d -> Int
x = (d -> Builder) -> Format String (d -> String)
forall a r. (a -> Builder) -> Format r (a -> r)
later (Text -> Builder
TLB.fromText (Text -> Builder) -> (d -> Text) -> d -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Text) -> (d -> String) -> d -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([String]
names [String] -> Int -> String
forall a. HasCallStack => [a] -> Int -> a
!!) (Int -> String) -> (d -> Int) -> d -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> Int
x)
pDayName :: (HasDate d, Enum (DoW d)) => [String] -> Pattern (d -> d) (d -> String) String
pDayName :: forall d.
(HasDate d, Enum (DoW d)) =>
[String] -> Pattern (d -> d) (d -> String) String
pDayName [String]
names = Parser (d -> d) String
-> Format String (d -> String)
-> Pattern (d -> d) (d -> String) String
forall a b r. Parser a r -> Format r b -> Pattern a b r
Pattern Parser (d -> d) String
par Format String (d -> String)
fmt
where
par :: Parser (d -> d) String
par = d -> d
forall a. a -> a
id (d -> d)
-> ParsecT String () Identity String -> Parser (d -> d) String
forall a b.
a -> ParsecT String () Identity b -> ParsecT String () Identity a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ([ParsecT String () Identity String]
-> ParsecT String () Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ([ParsecT String () Identity String]
-> ParsecT String () Identity String)
-> ([String] -> [ParsecT String () Identity String])
-> [String]
-> ParsecT String () Identity String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> ParsecT String () Identity String)
-> [String] -> [ParsecT String () Identity String]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT String () Identity String
-> ParsecT String () Identity String)
-> (String -> ParsecT String () Identity String)
-> String
-> ParsecT String () Identity String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ParsecT String () Identity String
caseInsensitiveString) ([String] -> ParsecT String () Identity String)
-> [String] -> ParsecT String () Identity String
forall a b. (a -> b) -> a -> b
$ [String]
names)
fmt :: Format String (d -> String)
fmt = (d -> Builder) -> Format String (d -> String)
forall a r. (a -> Builder) -> Format r (a -> r)
later (Text -> Builder
TLB.fromText (Text -> Builder) -> (d -> Text) -> d -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Text) -> (d -> String) -> d -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([String]
names [String] -> Int -> String
forall a. HasCallStack => [a] -> Int -> a
!!) (Int -> String) -> (d -> Int) -> d -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DoW d -> Int
forall a. Enum a => a -> Int
fromEnum (DoW d -> Int) -> (d -> DoW d) -> d -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> DoW d
forall d. HasDate d => d -> DoW d
dayOfWeek)
pMMMM' :: (HasDate d, Enum (MoY d)) => Locale -> Pattern (d -> d) (d -> String) String
pMMMM' :: forall d.
(HasDate d, Enum (MoY d)) =>
Locale -> Pattern (d -> d) (d -> String) String
pMMMM' = [String] -> Pattern (d -> d) (d -> String) String
forall d.
(HasDate d, Enum (MoY d)) =>
[String] -> Pattern (d -> d) (d -> String) String
pMonthName ([String] -> Pattern (d -> d) (d -> String) String)
-> (Locale -> [String])
-> Locale
-> Pattern (d -> d) (d -> String) String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Locale -> [String]
monthNames
pMMM' :: (HasDate d, Enum (MoY d)) => Locale -> Pattern (d -> d) (d -> String) String
pMMM' :: forall d.
(HasDate d, Enum (MoY d)) =>
Locale -> Pattern (d -> d) (d -> String) String
pMMM' = [String] -> Pattern (d -> d) (d -> String) String
forall d.
(HasDate d, Enum (MoY d)) =>
[String] -> Pattern (d -> d) (d -> String) String
pMonthName ([String] -> Pattern (d -> d) (d -> String) String)
-> (Locale -> [String])
-> Locale
-> Pattern (d -> d) (d -> String) String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Locale -> [String]
monthNamesShort
pdddd' :: (HasDate d, Enum (DoW d)) => Locale -> Pattern (d -> d) (d -> String) String
pdddd' :: forall d.
(HasDate d, Enum (DoW d)) =>
Locale -> Pattern (d -> d) (d -> String) String
pdddd' = [String] -> Pattern (d -> d) (d -> String) String
forall d.
(HasDate d, Enum (DoW d)) =>
[String] -> Pattern (d -> d) (d -> String) String
pDayName ([String] -> Pattern (d -> d) (d -> String) String)
-> (Locale -> [String])
-> Locale
-> Pattern (d -> d) (d -> String) String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Locale -> [String]
dayNames
pddd' :: (HasDate d, Enum (DoW d)) => Locale -> Pattern (d -> d) (d -> String) String
pddd' :: forall d.
(HasDate d, Enum (DoW d)) =>
Locale -> Pattern (d -> d) (d -> String) String
pddd' = [String] -> Pattern (d -> d) (d -> String) String
forall d.
(HasDate d, Enum (DoW d)) =>
[String] -> Pattern (d -> d) (d -> String) String
pDayName ([String] -> Pattern (d -> d) (d -> String) String)
-> (Locale -> [String])
-> Locale
-> Pattern (d -> d) (d -> String) String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Locale -> [String]
dayNamesShort