{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

-- |
-- Module: Data.Time.Format.Internal
-- Copyright: Copyright © 2021 Kadena LLC.
--                      © 2013−2014 Liyang HU Liyang HU
-- License: MIT
-- Maintainer: Lars Kuhtz <lars@kadena.io>
-- Stability: experimental
--
-- The code in this module is derived from various modules of the thyme package,
-- which is copyright (c) 2013 Liyang HU and distributed under a BSD3 license.
--
module Data.Time.Format.Internal
( formatTime
, parseTime
, readTime
, readsTime
) where

import Control.Applicative
import Control.Monad.State.Strict

import Data.Aeson (FromJSON(..), ToJSON(..), withText, Value(String))
import Data.Attoparsec.ByteString.Char8 (Parser, Result, IResult (..))
import qualified Data.Attoparsec.ByteString.Char8 as P
import Data.Bits
import qualified Data.ByteString.Builder as B
import qualified Data.ByteString.Char8 as S
import qualified Data.ByteString.Lazy as L
import Data.Char
import Data.Int
import qualified Data.Text as T
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import qualified Data.Vector.Unboxed as VU
import Data.VectorSpace

import Lens.Micro

-- internal modules

import Data.Time.Internal
import Data.Time.Format.Locale

-- -------------------------------------------------------------------------- --
-- Lens Utils (from microlens-mtl)

infix 4 .=

(.=) :: MonadState s m => ASetter s s a b -> b -> m ()
ASetter s s a b
l .= :: ASetter s s a b -> b -> m ()
.= b
x = (s -> s) -> m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (ASetter s s a b
l ASetter s s a b -> b -> s -> s
forall s t a b. ASetter s t a b -> b -> s -> t
.~ b
x)
{-# INLINE (.=) #-}

assign :: MonadState s m => ASetter s s a b -> b -> m ()
assign :: ASetter s s a b -> b -> m ()
assign ASetter s s a b
l b
x = ASetter s s a b
l ASetter s s a b -> b -> m ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= b
x
{-# INLINE assign #-}

-- -------------------------------------------------------------------------- --
-- Misc Utils

shows02 :: Int -> ShowS
shows02 :: Int -> ShowS
shows02 Int
n = if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
10 then (:) Char
'0' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
n else Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
n
{-# INLINE shows02 #-}

shows_2 :: Int -> ShowS
shows_2 :: Int -> ShowS
shows_2 Int
n = if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
10 then (:) Char
' ' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
n else Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
n
{-# INLINE shows_2 #-}

shows03 :: Int -> ShowS
shows03 :: Int -> ShowS
shows03 Int
n
    | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
10 = [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) [Char]
"00" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
n
    | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
100 = [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) [Char]
"0" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
n
    | Bool
otherwise = Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
n
{-# INLINE shows03 #-}

showsYear :: Int -> ShowS
showsYear :: Int -> ShowS
showsYear n :: Int
n@(Int -> Int
forall a. Num a => a -> a
abs -> Int
u)
    | Int
u Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
10 = ShowS
neg ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) [Char]
"000" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
u
    | Int
u Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
100 = ShowS
neg ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) [Char]
"00" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
u
    | Int
u Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
1000 = ShowS
neg ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) [Char]
"0" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
u
    | Bool
otherwise = ShowS
neg ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
forall a. Show a => a -> ShowS
shows Int
u
  where
    neg :: ShowS
neg = if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 then (:) Char
'-' else ShowS
forall a. a -> a
id
{-# INLINE showsYear #-}

fills06 :: Micros -> ShowS
fills06 :: Micros -> ShowS
fills06 Micros
n
    | Micros
n Micros -> Micros -> Bool
forall a. Ord a => a -> a -> Bool
< Micros
10 = [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) [Char]
"00000"
    | Micros
n Micros -> Micros -> Bool
forall a. Ord a => a -> a -> Bool
< Micros
100 = [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) [Char]
"0000"
    | Micros
n Micros -> Micros -> Bool
forall a. Ord a => a -> a -> Bool
< Micros
1000 = [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) [Char]
"000"
    | Micros
n Micros -> Micros -> Bool
forall a. Ord a => a -> a -> Bool
< Micros
10000 = [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) [Char]
"00"
    | Micros
n Micros -> Micros -> Bool
forall a. Ord a => a -> a -> Bool
< Micros
100000 = [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) [Char]
"0"
    | Bool
otherwise = ShowS
forall a. a -> a
id
{-# INLINE fills06 #-}

drops0 :: Micros -> ShowS
drops0 :: Micros -> ShowS
drops0 Micros
n = case Micros -> Micros -> (Micros, Micros)
forall a. Integral a => a -> a -> (a, a)
divMod Micros
n Micros
10 of
    (Micros
q, Micros
0) -> Micros -> ShowS
drops0 Micros
q
    (Micros, Micros)
_ -> Micros -> ShowS
forall a. Show a => a -> ShowS
shows Micros
n
{-# INLINE drops0 #-}

-- -------------------------------------------------------------------------- --
-- Misc Types

-- Unbounded
type UnboundedInt = Int

type Minutes = UnboundedInt
type Days = UnboundedInt
type Year = UnboundedInt
type Century = UnboundedInt

-- Bounded
type BoundedInt = Int

type Hour = BoundedInt
type Minute = BoundedInt
type Second = BoundedInt
type Month = BoundedInt
type DayOfMonth = BoundedInt
type DayOfYear = BoundedInt
type DayOfWeek = BoundedInt
type WeekOfYear = BoundedInt

-- -------------------------------------------------------------------------- --
-- Year Month Day

data YearMonthDay = YearMonthDay
    { YearMonthDay -> Int
_ymdYear :: {-# UNPACK #-} !Year
    , YearMonthDay -> Int
_ymdMonth :: {-# UNPACK #-} !Month
    , YearMonthDay -> Int
_ymdDay :: {-# UNPACK #-} !DayOfMonth
    }

ymdFromOrdinal :: OrdinalDate -> YearMonthDay
ymdFromOrdinal :: OrdinalDate -> YearMonthDay
ymdFromOrdinal (OrdinalDate Int
y Int
yd) = Int -> Int -> Int -> YearMonthDay
YearMonthDay Int
y Int
m Int
d
  where
    MonthDay Int
m Int
d = Bool -> Int -> MonthDay
monthDaysFromDayOfYear (Int -> Bool
isLeapYear Int
y) Int
yd
{-# INLINEABLE ymdFromOrdinal #-}

ymdToOrdinal :: YearMonthDay -> OrdinalDate
ymdToOrdinal :: YearMonthDay -> OrdinalDate
ymdToOrdinal (YearMonthDay Int
y Int
m Int
d) = Int -> Int -> OrdinalDate
OrdinalDate Int
y (Int -> OrdinalDate) -> Int -> OrdinalDate
forall a b. (a -> b) -> a -> b
$
    Bool -> MonthDay -> Int
monthDaysToDayOfYear (Int -> Bool
isLeapYear Int
y) (Int -> Int -> MonthDay
MonthDay Int
m Int
d)

{-# INLINEABLE ymdToOrdinal #-}

toGregorian :: YearMonthDay -> ModifiedJulianDay
toGregorian :: YearMonthDay -> ModifiedJulianDay
toGregorian = OrdinalDate -> ModifiedJulianDay
fromOrdinalDate (OrdinalDate -> ModifiedJulianDay)
-> (YearMonthDay -> OrdinalDate)
-> YearMonthDay
-> ModifiedJulianDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. YearMonthDay -> OrdinalDate
ymdToOrdinal
{-# INLINEABLE toGregorian #-}

-- -------------------------------------------------------------------------- --
-- Ordinal Dates

data OrdinalDate = OrdinalDate
    { OrdinalDate -> Int
_odYear :: {-# UNPACK #-} !Year
    , OrdinalDate -> Int
_odDay :: {-# UNPACK #-} !DayOfYear
    }

-- | Gregorian leap year?
isLeapYear :: Year -> Bool
isLeapYear :: Int -> Bool
isLeapYear Int
y = Int
y Int -> Int -> Int
forall a. Bits a => a -> a -> a
.&. Int
3 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 Bool -> Bool -> Bool
&& (Int
r100 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
0 Bool -> Bool -> Bool
|| Int
q100 Int -> Int -> Int
forall a. Bits a => a -> a -> a
.&. Int
3 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0)
  where
    (Int
q100, Int
r100) = Int
y Int -> Int -> (Int, Int)
forall a. Integral a => a -> a -> (a, a)
`quotRem` Int
100

toOrdinalDate :: ModifiedJulianDay -> OrdinalDate
toOrdinalDate :: ModifiedJulianDay -> OrdinalDate
toOrdinalDate (ModifiedJulianDay Int
mjd)
    | Int
dayB0 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = case Int -> OrdinalDate
toOrdB0 Int
dayInQC of
        OrdinalDate Int
y Int
yd -> Int -> Int -> OrdinalDate
OrdinalDate (Int
y Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
quadCent Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
400) Int
yd
    | Bool
otherwise = Int -> OrdinalDate
toOrdB0 Int
dayB0
  where
    dayB0 :: Int
dayB0 = Int
mjd Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
678575
    (Int
quadCent, Int
dayInQC) = Int
dayB0 Int -> Int -> (Int, Int)
forall a. Integral a => a -> a -> (a, a)
`divMod` Int
146097

    -- Input: days since 1-1-1. Precondition: has to be positive!
    toOrdB0 :: Int -> OrdinalDate
toOrdB0 Int
dB0 = OrdinalDate
res
      where
        (Int
y0, Int
r) = (Int
400 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
dB0) Int -> Int -> (Int, Int)
forall a. Integral a => a -> a -> (a, a)
`quotRem` Int
146097
        d0 :: Int
d0 = Int -> Int -> Int
forall a. (Integral a, Bits a) => a -> a -> a
dayInYear Int
y0 Int
dB0
        d1 :: Int
d1 = Int -> Int -> Int
forall a. (Integral a, Bits a) => a -> a -> a
dayInYear (Int
y0 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int
dB0
        res :: OrdinalDate
res = if Int
r Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
146097 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
600 Bool -> Bool -> Bool
&& Int
d1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
                then Int -> Int -> OrdinalDate
OrdinalDate (Int
y0 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int
d1
                else Int -> Int -> OrdinalDate
OrdinalDate (Int
y0 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int
d0
    {-# INLINE toOrdB0 #-}

    -- Input: (year - 1) (day as days since 1-1-1)
    -- Precondition: year is positive!
    dayInYear :: a -> a -> a
dayInYear a
y0 a
dB0 = a
dB0 a -> a -> a
forall a. Num a => a -> a -> a
- a
365 a -> a -> a
forall a. Num a => a -> a -> a
* a
y0 a -> a -> a
forall a. Num a => a -> a -> a
- a
leaps a -> a -> a
forall a. Num a => a -> a -> a
+ a
1
      where
        leaps :: a
leaps = a
y0 a -> Int -> a
forall a. Bits a => a -> Int -> a
`shiftR` Int
2 a -> a -> a
forall a. Num a => a -> a -> a
- a
centuries a -> a -> a
forall a. Num a => a -> a -> a
+ a
centuries a -> Int -> a
forall a. Bits a => a -> Int -> a
`shiftR` Int
2
        centuries :: a
centuries = a
y0 a -> a -> a
forall a. Integral a => a -> a -> a
`quot` a
100
    {-# INLINE dayInYear #-}
{-# INLINEABLE toOrdinalDate #-}


fromOrdinalDate :: OrdinalDate -> ModifiedJulianDay
fromOrdinalDate :: OrdinalDate -> ModifiedJulianDay
fromOrdinalDate (OrdinalDate Int
year Int
yd) = Int -> ModifiedJulianDay
ModifiedJulianDay Int
mjd
  where
    years :: Int
years = Int
year Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
    centuries :: Int
centuries = Int
years Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
100
    leaps :: Int
leaps = Int
years Int -> Int -> Int
forall a. Bits a => a -> Int -> a
`shiftR` Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
centuries Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
centuries Int -> Int -> Int
forall a. Bits a => a -> Int -> a
`shiftR` Int
2
    mjd :: Int
mjd = Int
365 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
years Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
leaps Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
678576
        Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> Int -> Int -> Int
forall c. Ord c => c -> c -> c -> c
clip Int
1 (if Int -> Bool
isLeapYear Int
year then Int
366 else Int
365) Int
yd
    clip :: c -> c -> c -> c
clip c
a c
b = c -> c -> c
forall a. Ord a => a -> a -> a
max c
a (c -> c) -> (c -> c) -> c -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> c -> c
forall a. Ord a => a -> a -> a
min c
b
{-# INLINEABLE fromOrdinalDate #-}

-- -------------------------------------------------------------------------- --
-- Months

monthLengths :: VU.Vector Days
monthLengths :: Vector Int
monthLengths     = [Int] -> Vector Int
forall a. Unbox a => [a] -> Vector a
VU.fromList [Int
31,Int
28,Int
31,Int
30,Int
31,Int
30,Int
31,Int
31,Int
30,Int
31,Int
30,Int
31]
{-# NOINLINE monthLengths #-}

monthLengthsLeap :: VU.Vector Days
monthLengthsLeap :: Vector Int
monthLengthsLeap = [Int] -> Vector Int
forall a. Unbox a => [a] -> Vector a
VU.fromList [Int
31,Int
29,Int
31,Int
30,Int
31,Int
30,Int
31,Int
31,Int
30,Int
31,Int
30,Int
31]
{-# NOINLINE monthLengthsLeap #-}

monthDays :: VU.Vector ({-Month-}Int8, {-DayOfMonth-}Int8)
monthDays :: Vector (Int8, Int8)
monthDays = Int -> (Int -> (Int8, Int8)) -> Vector (Int8, Int8)
forall a. Unbox a => Int -> (Int -> a) -> Vector a
VU.generate Int
365 Int -> (Int8, Int8)
forall a b. (Num a, Num b) => Int -> (a, b)
go
  where
    dom01 :: Vector Int
dom01 = (Int -> Int -> Int) -> Int -> Vector Int -> Vector Int
forall a b.
(Unbox a, Unbox b) =>
(a -> b -> a) -> a -> Vector b -> Vector a
VU.prescanl' Int -> Int -> Int
forall a. Num a => a -> a -> a
(+) Int
0 Vector Int
monthLengths
    go :: Int -> (a, b)
go Int
yd = (Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
m, Int -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
d)
      where
        m :: Int
m = Int -> (Int -> Int) -> Maybe Int -> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
12 Int -> Int
forall a. a -> a
id (Maybe Int -> Int) -> Maybe Int -> Int
forall a b. (a -> b) -> a -> b
$ (Int -> Bool) -> Vector Int -> Maybe Int
forall a. Unbox a => (a -> Bool) -> Vector a -> Maybe Int
VU.findIndex (Int
yd Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<) Vector Int
dom01
        d :: Int
d = Int -> Int
forall a. Enum a => a -> a
succ Int
yd Int -> Int -> Int
forall a. Num a => a -> a -> a
- Vector Int -> Int -> Int
forall a. Unbox a => Vector a -> Int -> a
VU.unsafeIndex Vector Int
dom01 (Int -> Int
forall a. Enum a => a -> a
pred Int
m)
{-# NOINLINE monthDays #-}

monthDaysLeap :: VU.Vector ({-Month-}Int8, {-DayOfMonth-}Int8)
monthDaysLeap :: Vector (Int8, Int8)
monthDaysLeap = Int -> (Int -> (Int8, Int8)) -> Vector (Int8, Int8)
forall a. Unbox a => Int -> (Int -> a) -> Vector a
VU.generate Int
366 Int -> (Int8, Int8)
forall a b. (Num a, Num b) => Int -> (a, b)
go
  where
    dom01 :: Vector Int
dom01 = (Int -> Int -> Int) -> Int -> Vector Int -> Vector Int
forall a b.
(Unbox a, Unbox b) =>
(a -> b -> a) -> a -> Vector b -> Vector a
VU.prescanl' Int -> Int -> Int
forall a. Num a => a -> a -> a
(+) Int
0 Vector Int
monthLengthsLeap
    go :: Int -> (a, b)
go Int
yd = (Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
m, Int -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
d)
      where
        m :: Int
m = Int -> (Int -> Int) -> Maybe Int -> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
12 Int -> Int
forall a. a -> a
id (Maybe Int -> Int) -> Maybe Int -> Int
forall a b. (a -> b) -> a -> b
$ (Int -> Bool) -> Vector Int -> Maybe Int
forall a. Unbox a => (a -> Bool) -> Vector a -> Maybe Int
VU.findIndex (Int
yd Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<) Vector Int
dom01
        d :: Int
d = Int -> Int
forall a. Enum a => a -> a
succ Int
yd Int -> Int -> Int
forall a. Num a => a -> a -> a
- Vector Int -> Int -> Int
forall a. Unbox a => Vector a -> Int -> a
VU.unsafeIndex Vector Int
dom01 (Int -> Int
forall a. Enum a => a -> a
pred Int
m)
{-# NOINLINE monthDaysLeap #-}

data MonthDay = MonthDay
    { MonthDay -> Int
_mdMonth :: {-# UNPACK #-} !Month
    , MonthDay -> Int
_mdDay :: {-# UNPACK #-} !DayOfMonth
    }

monthDaysFromDayOfYear :: Bool -> DayOfYear -> MonthDay
monthDaysFromDayOfYear :: Bool -> Int -> MonthDay
monthDaysFromDayOfYear Bool
leap Int
yd = Int -> Int -> MonthDay
MonthDay Int
m Int
d
  where
    i :: Int
i = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> (Int -> Int) -> Int -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
lastDay (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int -> Int
forall a. Enum a => a -> a
pred Int
yd
    (Int8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> Int
m, Int8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> Int
d) = Vector (Int8, Int8) -> Int -> (Int8, Int8)
forall a. Unbox a => Vector a -> Int -> a
VU.unsafeIndex Vector (Int8, Int8)
table Int
i
    (Int
lastDay, Vector (Int8, Int8)
table) = if Bool
leap
      then (Int
365, Vector (Int8, Int8)
monthDaysLeap)
      else (Int
364, Vector (Int8, Int8)
monthDays)
{-# INLINE monthDaysFromDayOfYear #-}

monthDaysToDayOfYear :: Bool -> MonthDay -> DayOfYear
monthDaysToDayOfYear :: Bool -> MonthDay -> Int
monthDaysToDayOfYear Bool
leap (MonthDay Int
month Int
mday) = Int -> Int -> Int
forall a. Integral a => a -> a -> a
div (Int
367 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
362) Int
12 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
d
  where
    m :: Int
m = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 (Int -> Int) -> (Int -> Int) -> Int -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
12 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
month
    l :: Int
l = Vector Int -> Int -> Int
forall a. Unbox a => Vector a -> Int -> a
VU.unsafeIndex Vector Int
lengths (Int -> Int
forall a. Enum a => a -> a
pred Int
m)
    d :: Int
d = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 (Int -> Int) -> (Int -> Int) -> Int -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
l (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
mday
    k :: Int
k = if Int
m Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
2 then Int
0 else Int
ok

    (Vector Int
lengths, Int
ok) = if Bool
leap
      then (Vector Int
monthLengthsLeap, -Int
1)
      else (Vector Int
monthLengths, -Int
2)
{-# INLINE monthDaysToDayOfYear #-}

-- -------------------------------------------------------------------------- --
-- Week Date

data WeekDate = WeekDate
    { WeekDate -> Int
_wdYear :: {-# UNPACK #-} !Year
    , WeekDate -> Int
_wdWeek :: {-# UNPACK #-} !WeekOfYear
    , WeekDate -> Int
_wdDay :: {-# UNPACK #-} !DayOfWeek
    }

toWeekDate :: ModifiedJulianDay -> WeekDate
toWeekDate :: ModifiedJulianDay -> WeekDate
toWeekDate = (ModifiedJulianDay -> ModifiedJulianDay -> WeekDate)
-> ModifiedJulianDay -> WeekDate
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (OrdinalDate -> ModifiedJulianDay -> WeekDate
toWeekOrdinal (OrdinalDate -> ModifiedJulianDay -> WeekDate)
-> (ModifiedJulianDay -> OrdinalDate)
-> ModifiedJulianDay
-> ModifiedJulianDay
-> WeekDate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModifiedJulianDay -> OrdinalDate
toOrdinalDate)
{-# INLINEABLE toWeekDate #-}

fromWeekDate :: WeekDate -> ModifiedJulianDay
fromWeekDate :: WeekDate -> ModifiedJulianDay
fromWeekDate wd :: WeekDate
wd@(WeekDate Int
y Int
_ Int
_) = Int -> WeekDate -> ModifiedJulianDay
fromWeekLast (Int -> Int
lastWeekOfYear Int
y) WeekDate
wd
{-# INLINEABLE fromWeekDate #-}

toWeekOrdinal :: OrdinalDate -> ModifiedJulianDay -> WeekDate
toWeekOrdinal :: OrdinalDate -> ModifiedJulianDay -> WeekDate
toWeekOrdinal (OrdinalDate Int
y0 Int
yd) (ModifiedJulianDay Int
mjd) =
    Int -> Int -> Int -> WeekDate
WeekDate Int
y1 (Int
w1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Int
d7mod Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
  where
    -- pilfered and refactored; no idea what foo and bar mean
    d :: Int
d = Int
mjd Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2
    (Int
d7div, Int
d7mod) = Int -> Int -> (Int, Int)
forall a. Integral a => a -> a -> (a, a)
divMod Int
d Int
7

    -- foo :: Year -> {-WeekOfYear-1-}Int
    foo :: Int -> Int
foo Int
y = ModifiedJulianDay -> Int
bar (ModifiedJulianDay -> Int) -> ModifiedJulianDay -> Int
forall a b. (a -> b) -> a -> b
$ OrdinalDate -> ModifiedJulianDay
fromOrdinalDate (OrdinalDate -> ModifiedJulianDay)
-> OrdinalDate -> ModifiedJulianDay
forall a b. (a -> b) -> a -> b
$ Int -> Int -> OrdinalDate
OrdinalDate Int
y Int
6

    -- bar :: ModifiedJulianDay -> {-WeekOfYear-1-}Int
    bar :: ModifiedJulianDay -> Int
bar (ModifiedJulianDay Int
k) = Int
d7div Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int -> Int -> Int
forall a. Integral a => a -> a -> a
div Int
k Int
7

    w0 :: Int
w0 = ModifiedJulianDay -> Int
bar (ModifiedJulianDay -> Int) -> ModifiedJulianDay -> Int
forall a b. (a -> b) -> a -> b
$ Int -> ModifiedJulianDay
ModifiedJulianDay (Int
d Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
yd Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4)
    (Int
y1, Int
w1) = case Int
w0 of
        -1 -> (Int
y0 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1, Int -> Int
foo (Int
y0 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1))
        Int
52 | Int -> Int
foo (Int
y0 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 -> (Int
y0 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1, Int
0)
        Int
_ -> (Int
y0, Int
w0)
{-# INLINE toWeekOrdinal #-}

lastWeekOfYear :: Year -> WeekOfYear
lastWeekOfYear :: Int -> Int
lastWeekOfYear Int
y = if WeekDate -> Int
_wdWeek WeekDate
wd Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
53 then Int
53 else Int
52
  where
    wd :: WeekDate
wd = ModifiedJulianDay -> WeekDate
toWeekDate (ModifiedJulianDay -> WeekDate) -> ModifiedJulianDay -> WeekDate
forall a b. (a -> b) -> a -> b
$ OrdinalDate -> ModifiedJulianDay
fromOrdinalDate (OrdinalDate -> ModifiedJulianDay)
-> OrdinalDate -> ModifiedJulianDay
forall a b. (a -> b) -> a -> b
$ Int -> Int -> OrdinalDate
OrdinalDate Int
y Int
365
{-# INLINE lastWeekOfYear #-}

fromWeekLast :: WeekOfYear -> WeekDate -> ModifiedJulianDay
fromWeekLast :: Int -> WeekDate -> ModifiedJulianDay
fromWeekLast Int
wMax (WeekDate Int
y Int
w Int
d) = Int -> ModifiedJulianDay
ModifiedJulianDay Int
mjd
  where
    -- pilfered and refactored
    ModifiedJulianDay Int
k = OrdinalDate -> ModifiedJulianDay
fromOrdinalDate (OrdinalDate -> ModifiedJulianDay)
-> OrdinalDate -> ModifiedJulianDay
forall a b. (a -> b) -> a -> b
$ Int -> Int -> OrdinalDate
OrdinalDate Int
y Int
6
    mjd :: Int
mjd = Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
k Int
7 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
10 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> Int -> Int -> Int
forall c. Ord c => c -> c -> c -> c
clip Int
1 Int
7 Int
d Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> Int -> Int -> Int
forall c. Ord c => c -> c -> c -> c
clip Int
1 Int
wMax Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
7
    clip :: c -> c -> c -> c
clip c
a c
b = c -> c -> c
forall a. Ord a => a -> a -> a
max c
a (c -> c) -> (c -> c) -> c -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> c -> c
forall a. Ord a => a -> a -> a
min c
b
{-# INLINE fromWeekLast #-}

-- -------------------------------------------------------------------------- --
-- Sunday Weeks

-- | Weeks numbered from 0 to 53, starting with the first Sunday of the year
-- as the first day of week 1. The last week of a given year and week 0 of
-- the next both refer to the same week, but not all 'DayOfWeek' are valid.
-- 'Year' coincides with that of 'gregorian'.
--
data SundayWeek = SundayWeek
    { SundayWeek -> Int
_swYear :: {-# UNPACK #-} !Year
    , SundayWeek -> Int
_swWeek :: {-# UNPACK #-} !WeekOfYear
    , SundayWeek -> Int
_swDay :: {-# UNPACK #-} !DayOfWeek
    }

fromSundayWeek :: SundayWeek -> ModifiedJulianDay
fromSundayWeek :: SundayWeek -> ModifiedJulianDay
fromSundayWeek (SundayWeek Int
y Int
w Int
d) = Int -> ModifiedJulianDay
ModifiedJulianDay (Int
firstDay Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
yd)
  where
    ModifiedJulianDay Int
firstDay = OrdinalDate -> ModifiedJulianDay
fromOrdinalDate (OrdinalDate -> ModifiedJulianDay)
-> OrdinalDate -> ModifiedJulianDay
forall a b. (a -> b) -> a -> b
$ Int -> Int -> OrdinalDate
OrdinalDate Int
y Int
1
    -- following are all 0-based year days
    firstSunday :: Int
firstSunday = Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod (Int
4 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
firstDay) Int
7
    yd :: Int
yd = Int
firstSunday Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
7 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
d
{-# INLINEABLE fromSundayWeek #-}

toSundayOrdinal :: OrdinalDate -> ModifiedJulianDay -> SundayWeek
toSundayOrdinal :: OrdinalDate -> ModifiedJulianDay -> SundayWeek
toSundayOrdinal (OrdinalDate Int
y Int
yd) (ModifiedJulianDay Int
mjd) =
    Int -> Int -> Int -> SundayWeek
SundayWeek Int
y (Int
d7div Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int -> Int -> Int
forall a. Integral a => a -> a -> a
div Int
k Int
7) Int
d7mod
  where
    d :: Int
d = Int
mjd Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3
    k :: Int
k = Int
d Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
yd
    (Int
d7div, Int
d7mod) = Int -> Int -> (Int, Int)
forall a. Integral a => a -> a -> (a, a)
divMod Int
d Int
7
{-# INLINE toSundayOrdinal #-}

-- -------------------------------------------------------------------------- --
-- Monaday Weeks

-- | Weeks numbered from 0 to 53, starting with the first Monday of the year
-- as the first day of week 1. The last week of a given year and week 0 of
-- the next both refer to the same week, but not all 'DayOfWeek' are valid.
-- 'Year' coincides with that of 'gregorian'.
--
data MondayWeek = MondayWeek
    { MondayWeek -> Int
_mwYear :: {-# UNPACK #-} !Year
    , MondayWeek -> Int
_mwWeek :: {-# UNPACK #-} !WeekOfYear
    , MondayWeek -> Int
_mwDay :: {-# UNPACK #-} !DayOfWeek
    }

fromMondayWeek :: MondayWeek -> ModifiedJulianDay
fromMondayWeek :: MondayWeek -> ModifiedJulianDay
fromMondayWeek (MondayWeek Int
y Int
w Int
d) = Int -> ModifiedJulianDay
ModifiedJulianDay (Int
firstDay Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
yd)
  where
    ModifiedJulianDay Int
firstDay = OrdinalDate -> ModifiedJulianDay
fromOrdinalDate (OrdinalDate -> ModifiedJulianDay)
-> OrdinalDate -> ModifiedJulianDay
forall a b. (a -> b) -> a -> b
$ Int -> Int -> OrdinalDate
OrdinalDate Int
y Int
1
    -- following are all 0-based year days
    firstMonday :: Int
firstMonday = Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod (Int
5 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
firstDay) Int
7
    yd :: Int
yd = Int
firstMonday Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
7 Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
d Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
{-# INLINEABLE fromMondayWeek #-}

toMondayOrdinal :: OrdinalDate -> ModifiedJulianDay -> MondayWeek
toMondayOrdinal :: OrdinalDate -> ModifiedJulianDay -> MondayWeek
toMondayOrdinal (OrdinalDate Int
y Int
yd) (ModifiedJulianDay Int
mjd) =
    Int -> Int -> Int -> MondayWeek
MondayWeek Int
y (Int
d7div Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int -> Int -> Int
forall a. Integral a => a -> a -> a
div Int
k Int
7) (Int
d7mod Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
  where
    d :: Int
d = Int
mjd Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2
    k :: Int
k = Int
d Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
yd
    (Int
d7div, Int
d7mod) = Int -> Int -> (Int, Int)
forall a. Integral a => a -> a -> (a, a)
divMod Int
d Int
7
{-# INLINE toMondayOrdinal #-}

-- -------------------------------------------------------------------------- --
-- Time Of Day

data TimeOfDay = TimeOfDay
    { TimeOfDay -> Int
_todHour :: {-# UNPACK #-} !Hour
    , TimeOfDay -> Int
_todMin :: {-# UNPACK #-} !Minute
    , TimeOfDay -> NominalDiffTime
_todSec :: {-# UNPACK #-} !NominalDiffTime
    }

timeOfDayFromNominalDiffTime :: NominalDiffTime -> TimeOfDay
timeOfDayFromNominalDiffTime :: NominalDiffTime -> TimeOfDay
timeOfDayFromNominalDiffTime (NominalDiffTime Micros
t) = Int -> Int -> NominalDiffTime -> TimeOfDay
TimeOfDay
    (Micros -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Micros
h) (Micros -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Micros
m) (Micros -> NominalDiffTime
NominalDiffTime Micros
s)
  where
    (Micros
h, Micros
ms) = Micros -> Micros -> (Micros, Micros)
forall a. Integral a => a -> a -> (a, a)
quotRem Micros
t Micros
3600000000
    (Micros
m, Micros
s) = Micros -> Micros -> (Micros, Micros)
forall a. Integral a => a -> a -> (a, a)
quotRem Micros
ms Micros
60000000
{-# INLINEABLE timeOfDayFromNominalDiffTime #-}

-- -------------------------------------------------------------------------- --
-- Format Time

class FormatTime t where
    showsTime :: t -> (Char -> ShowS) -> Char -> ShowS

formatTime :: (FormatTime t) => String -> t -> String
formatTime :: [Char] -> t -> [Char]
formatTime [Char]
spec t
t = [Char] -> t -> ShowS
forall t. FormatTime t => [Char] -> t -> ShowS
formatTimeS [Char]
spec t
t [Char]
""
{-# INLINEABLE formatTime #-}

formatTimeS :: (FormatTime t) => String -> t -> ShowS
formatTimeS :: [Char] -> t -> ShowS
formatTimeS [Char]
spec t
t = [Char] -> ShowS
go [Char]
spec
  where
    -- leave unrecognised codes as they are
    format :: Char -> ShowS
format = t -> (Char -> ShowS) -> Char -> ShowS
forall t. FormatTime t => t -> (Char -> ShowS) -> Char -> ShowS
showsTime t
t (\Char
c [Char]
s -> Char
'%' Char -> ShowS
forall a. a -> [a] -> [a]
: Char
c Char -> ShowS
forall a. a -> [a] -> [a]
: [Char]
s)
    go :: [Char] -> ShowS
go [Char]
s = case [Char]
s of
        Char
'%' : Char
c : [Char]
rest -> case Char
c of
            -- aggregate
            Char
'c' -> [Char] -> ShowS
go (TimeLocale -> [Char]
dateTimeFmt TimeLocale
l [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
rest)
            Char
'r' -> [Char] -> ShowS
go (TimeLocale -> [Char]
time12Fmt TimeLocale
l [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
rest)
            Char
'X' -> [Char] -> ShowS
go (TimeLocale -> [Char]
timeFmt TimeLocale
l [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
rest)
            Char
'x' -> [Char] -> ShowS
go (TimeLocale -> [Char]
dateFmt TimeLocale
l [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
rest)
            -- modifier (whatever)
            Char
'-' -> [Char] -> ShowS
go (Char
'%' Char -> ShowS
forall a. a -> [a] -> [a]
: [Char]
rest)
            Char
'_' -> [Char] -> ShowS
go (Char
'%' Char -> ShowS
forall a. a -> [a] -> [a]
: [Char]
rest)
            Char
'0' -> [Char] -> ShowS
go (Char
'%' Char -> ShowS
forall a. a -> [a] -> [a]
: [Char]
rest)
            Char
'^' -> [Char] -> ShowS
go (Char
'%' Char -> ShowS
forall a. a -> [a] -> [a]
: [Char]
rest)
            Char
'#' -> [Char] -> ShowS
go (Char
'%' Char -> ShowS
forall a. a -> [a] -> [a]
: [Char]
rest)
            -- escape (why would anyone need %t and %n?)
            Char
'%' -> (:) Char
'%' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
go [Char]
rest
            -- default
            Char
_ -> Char -> ShowS
format Char
c ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
go [Char]
rest
        Char
c : [Char]
rest -> (:) Char
c ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
go [Char]
rest
        [] -> ShowS
forall a. a -> a
id
      where
        l :: TimeLocale
l = TimeLocale
defaultTimeLocale
{-# INLINEABLE formatTimeS #-}

instance FormatTime TimeOfDay where
    showsTime :: TimeOfDay -> (Char -> ShowS) -> Char -> ShowS
showsTime (TimeOfDay Int
h Int
m (NominalDiffTime Micros
s)) = \ Char -> ShowS
def Char
c -> case Char
c of
        -- aggregate
        Char
'R' -> Int -> ShowS
shows02 Int
h ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:) Char
':' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
shows02 Int
m
        Char
'T' -> Int -> ShowS
shows02 Int
h ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:) Char
':' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
shows02 Int
m ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:) Char
':' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
shows02 Int
si
        -- AM/PM
        Char
'P' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) ([Char] -> ShowS) -> [Char] -> ShowS
forall a b. (a -> b) -> a -> b
$ Char -> Char
toLower (Char -> Char) -> ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> if Int
h Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
12 then ([Char], [Char]) -> [Char]
forall a b. (a, b) -> a
fst ([Char], [Char])
amPm else ([Char], [Char]) -> [Char]
forall a b. (a, b) -> b
snd ([Char], [Char])
amPm
        Char
'p' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) ([Char] -> ShowS) -> [Char] -> ShowS
forall a b. (a -> b) -> a -> b
$ if Int
h Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
12 then ([Char], [Char]) -> [Char]
forall a b. (a, b) -> a
fst ([Char], [Char])
amPm else ([Char], [Char]) -> [Char]
forall a b. (a, b) -> b
snd ([Char], [Char])
amPm
        -- Hour
        Char
'H' -> Int -> ShowS
shows02 Int
h
        Char
'I' -> Int -> ShowS
shows02 (Int -> ShowS) -> Int -> ShowS
forall a b. (a -> b) -> a -> b
$ Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod (Int
h Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int
12
        Char
'k' -> Int -> ShowS
shows_2 Int
h
        Char
'l' -> Int -> ShowS
shows_2 (Int -> ShowS) -> Int -> ShowS
forall a b. (a -> b) -> a -> b
$ Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod (Int
h Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int
12
        -- Minute
        Char
'M' -> Int -> ShowS
shows02 Int
m
        -- Second
        Char
'S' -> Int -> ShowS
shows02 Int
si

        -- TODO: Unsupported by Pact
        Char
'q' -> Micros -> ShowS
fills06 Micros
su ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Micros -> ShowS
forall a. Show a => a -> ShowS
shows Micros
su ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) [Char]
"000000"

        Char
'v' -> Micros -> ShowS
fills06 Micros
su ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Micros -> ShowS
forall a. Show a => a -> ShowS
shows Micros
su
        Char
'Q' -> if Micros
su Micros -> Micros -> Bool
forall a. Eq a => a -> a -> Bool
== Micros
0 then ShowS
forall a. a -> a
id else (:) Char
'.' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Micros -> ShowS
fills06 Micros
su ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Micros -> ShowS
drops0 Micros
su
        -- default
        Char
_ -> Char -> ShowS
def Char
c
      where
        (Micros -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral -> Int
si, Micros
su) = Micros -> Micros -> (Micros, Micros)
forall a. Integral a => a -> a -> (a, a)
quotRem Micros
s Micros
1000000
        TimeLocale {[Char]
[([Char], [Char])]
([Char], [Char])
amPm :: TimeLocale -> ([Char], [Char])
months :: TimeLocale -> [([Char], [Char])]
wDays :: TimeLocale -> [([Char], [Char])]
time12Fmt :: [Char]
timeFmt :: [Char]
dateFmt :: [Char]
dateTimeFmt :: [Char]
months :: [([Char], [Char])]
wDays :: [([Char], [Char])]
amPm :: ([Char], [Char])
dateFmt :: TimeLocale -> [Char]
timeFmt :: TimeLocale -> [Char]
time12Fmt :: TimeLocale -> [Char]
dateTimeFmt :: TimeLocale -> [Char]
..} = TimeLocale
defaultTimeLocale
    {-# INLINEABLE showsTime #-}

instance FormatTime SundayWeek where
    showsTime :: SundayWeek -> (Char -> ShowS) -> Char -> ShowS
showsTime (SundayWeek Int
y Int
w Int
d) = \ Char -> ShowS
def Char
c -> case Char
c of
        -- Year
        Char
'Y' -> Int -> ShowS
showsYear Int
y
        Char
'y' -> Int -> ShowS
shows02 (Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
y Int
100)
        Char
'C' -> Int -> ShowS
shows02 (Int -> Int -> Int
forall a. Integral a => a -> a -> a
div Int
y Int
100)
        -- WeekOfYear
        Char
'U' -> Int -> ShowS
shows02 Int
w
        -- DayOfWeek
        Char
'u' -> Int -> ShowS
forall a. Show a => a -> ShowS
shows (Int -> ShowS) -> Int -> ShowS
forall a b. (a -> b) -> a -> b
$ if Int
d Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
7 else Int
d
        Char
'w' -> Int -> ShowS
forall a. Show a => a -> ShowS
shows (Int -> ShowS) -> Int -> ShowS
forall a b. (a -> b) -> a -> b
$ if Int
d Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
7 then Int
0 else Int
d
        Char
'A' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) ([Char] -> ShowS)
-> (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char], [Char]) -> [Char]
forall a b. (a, b) -> a
fst (([Char], [Char]) -> ShowS) -> ([Char], [Char]) -> ShowS
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])]
wDays [([Char], [Char])] -> Int -> ([Char], [Char])
forall a. [a] -> Int -> a
!! Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
d Int
7
        Char
'a' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) ([Char] -> ShowS)
-> (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char], [Char]) -> [Char]
forall a b. (a, b) -> b
snd (([Char], [Char]) -> ShowS) -> ([Char], [Char]) -> ShowS
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])]
wDays [([Char], [Char])] -> Int -> ([Char], [Char])
forall a. [a] -> Int -> a
!! Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
d Int
7
        -- default
        Char
_ -> Char -> ShowS
def Char
c
      where
        TimeLocale {[Char]
[([Char], [Char])]
([Char], [Char])
time12Fmt :: [Char]
timeFmt :: [Char]
dateFmt :: [Char]
dateTimeFmt :: [Char]
amPm :: ([Char], [Char])
months :: [([Char], [Char])]
wDays :: [([Char], [Char])]
amPm :: TimeLocale -> ([Char], [Char])
months :: TimeLocale -> [([Char], [Char])]
wDays :: TimeLocale -> [([Char], [Char])]
dateFmt :: TimeLocale -> [Char]
timeFmt :: TimeLocale -> [Char]
time12Fmt :: TimeLocale -> [Char]
dateTimeFmt :: TimeLocale -> [Char]
..} = TimeLocale
defaultTimeLocale
    {-# INLINEABLE showsTime #-}

instance FormatTime MondayWeek where
    showsTime :: MondayWeek -> (Char -> ShowS) -> Char -> ShowS
showsTime (MondayWeek Int
y Int
w Int
d) = \ Char -> ShowS
def Char
c -> case Char
c of
        -- Year
        Char
'Y' -> Int -> ShowS
showsYear Int
y
        Char
'y' -> Int -> ShowS
shows02 (Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
y Int
100)
        Char
'C' -> Int -> ShowS
shows02 (Int -> Int -> Int
forall a. Integral a => a -> a -> a
div Int
y Int
100)
        -- WeekOfYear
        Char
'W' -> Int -> ShowS
shows02 Int
w
        -- DayOfWeek
        Char
'u' -> Int -> ShowS
forall a. Show a => a -> ShowS
shows (Int -> ShowS) -> Int -> ShowS
forall a b. (a -> b) -> a -> b
$ if Int
d Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
7 else Int
d
        Char
'w' -> Int -> ShowS
forall a. Show a => a -> ShowS
shows (Int -> ShowS) -> Int -> ShowS
forall a b. (a -> b) -> a -> b
$ if Int
d Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
7 then Int
0 else Int
d
        Char
'A' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) ([Char] -> ShowS)
-> (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char], [Char]) -> [Char]
forall a b. (a, b) -> a
fst (([Char], [Char]) -> ShowS) -> ([Char], [Char]) -> ShowS
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])]
wDays [([Char], [Char])] -> Int -> ([Char], [Char])
forall a. [a] -> Int -> a
!! Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
d Int
7
        Char
'a' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) ([Char] -> ShowS)
-> (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char], [Char]) -> [Char]
forall a b. (a, b) -> b
snd (([Char], [Char]) -> ShowS) -> ([Char], [Char]) -> ShowS
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])]
wDays [([Char], [Char])] -> Int -> ([Char], [Char])
forall a. [a] -> Int -> a
!! Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
d Int
7
        -- default
        Char
_ -> Char -> ShowS
def Char
c
      where
        TimeLocale {[Char]
[([Char], [Char])]
([Char], [Char])
time12Fmt :: [Char]
timeFmt :: [Char]
dateFmt :: [Char]
dateTimeFmt :: [Char]
amPm :: ([Char], [Char])
months :: [([Char], [Char])]
wDays :: [([Char], [Char])]
amPm :: TimeLocale -> ([Char], [Char])
months :: TimeLocale -> [([Char], [Char])]
wDays :: TimeLocale -> [([Char], [Char])]
dateFmt :: TimeLocale -> [Char]
timeFmt :: TimeLocale -> [Char]
time12Fmt :: TimeLocale -> [Char]
dateTimeFmt :: TimeLocale -> [Char]
..} = TimeLocale
defaultTimeLocale
    {-# INLINEABLE showsTime #-}

instance FormatTime WeekDate where
    showsTime :: WeekDate -> (Char -> ShowS) -> Char -> ShowS
showsTime (WeekDate Int
y Int
w Int
d) = \ Char -> ShowS
def Char
c -> case Char
c of
        -- Year
        Char
'G' -> Int -> ShowS
showsYear Int
y
        Char
'g' -> Int -> ShowS
shows02 (Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
y Int
100)
        Char
'f' -> Int -> ShowS
shows02 (Int -> Int -> Int
forall a. Integral a => a -> a -> a
div Int
y Int
100)
        -- WeekOfYear
        Char
'V' -> Int -> ShowS
shows02 Int
w
        -- DayOfWeek
        Char
'u' -> Int -> ShowS
forall a. Show a => a -> ShowS
shows (Int -> ShowS) -> Int -> ShowS
forall a b. (a -> b) -> a -> b
$ if Int
d Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
7 else Int
d
        Char
'w' -> Int -> ShowS
forall a. Show a => a -> ShowS
shows (Int -> ShowS) -> Int -> ShowS
forall a b. (a -> b) -> a -> b
$ if Int
d Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
7 then Int
0 else Int
d
        Char
'A' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) ([Char] -> ShowS)
-> (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char], [Char]) -> [Char]
forall a b. (a, b) -> a
fst (([Char], [Char]) -> ShowS) -> ([Char], [Char]) -> ShowS
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])]
wDays [([Char], [Char])] -> Int -> ([Char], [Char])
forall a. [a] -> Int -> a
!! Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
d Int
7
        Char
'a' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) ([Char] -> ShowS)
-> (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char], [Char]) -> [Char]
forall a b. (a, b) -> b
snd (([Char], [Char]) -> ShowS) -> ([Char], [Char]) -> ShowS
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])]
wDays [([Char], [Char])] -> Int -> ([Char], [Char])
forall a. [a] -> Int -> a
!! Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
d Int
7
        -- default
        Char
_ -> Char -> ShowS
def Char
c
      where
        TimeLocale {[Char]
[([Char], [Char])]
([Char], [Char])
time12Fmt :: [Char]
timeFmt :: [Char]
dateFmt :: [Char]
dateTimeFmt :: [Char]
amPm :: ([Char], [Char])
months :: [([Char], [Char])]
wDays :: [([Char], [Char])]
amPm :: TimeLocale -> ([Char], [Char])
months :: TimeLocale -> [([Char], [Char])]
wDays :: TimeLocale -> [([Char], [Char])]
dateFmt :: TimeLocale -> [Char]
timeFmt :: TimeLocale -> [Char]
time12Fmt :: TimeLocale -> [Char]
dateTimeFmt :: TimeLocale -> [Char]
..} = TimeLocale
defaultTimeLocale
    {-# INLINEABLE showsTime #-}

instance FormatTime YearMonthDay where
    showsTime :: YearMonthDay -> (Char -> ShowS) -> Char -> ShowS
showsTime (YearMonthDay Int
y Int
m Int
d) Char -> ShowS
def Char
c = case Char
c of
        -- aggregate
        Char
'D' -> Int -> ShowS
shows02 Int
m ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:) Char
'/' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
shows02 Int
d ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:) Char
'/' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
shows02 (Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
y Int
100)
        Char
'F' -> Int -> ShowS
showsYear Int
y ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:) Char
'-' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
shows02 Int
m ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:) Char
'-' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShowS
shows02 Int
d
        -- Year
        Char
'Y' -> Int -> ShowS
showsYear Int
y
        Char
'y' -> Int -> ShowS
shows02 (Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
y Int
100)
        Char
'C' -> Int -> ShowS
shows02 (Int -> Int -> Int
forall a. Integral a => a -> a -> a
div Int
y Int
100)
        -- Month
        Char
'B' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) ([Char] -> ShowS)
-> (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char], [Char]) -> [Char]
forall a b. (a, b) -> a
fst (([Char], [Char]) -> ShowS) -> ([Char], [Char]) -> ShowS
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])]
months [([Char], [Char])] -> Int -> ([Char], [Char])
forall a. [a] -> Int -> a
!! (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
        Char
'b' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) ([Char] -> ShowS)
-> (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char], [Char]) -> [Char]
forall a b. (a, b) -> b
snd (([Char], [Char]) -> ShowS) -> ([Char], [Char]) -> ShowS
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])]
months [([Char], [Char])] -> Int -> ([Char], [Char])
forall a. [a] -> Int -> a
!! (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
        Char
'h' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) ([Char] -> ShowS)
-> (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char], [Char]) -> [Char]
forall a b. (a, b) -> b
snd (([Char], [Char]) -> ShowS) -> ([Char], [Char]) -> ShowS
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])]
months [([Char], [Char])] -> Int -> ([Char], [Char])
forall a. [a] -> Int -> a
!! (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
        Char
'm' -> Int -> ShowS
shows02 Int
m
        -- DayOfMonth
        Char
'd' -> Int -> ShowS
shows02 Int
d
        Char
'e' -> Int -> ShowS
shows_2 Int
d
        -- default
        Char
_ -> Char -> ShowS
def Char
c
      where
        TimeLocale {[Char]
[([Char], [Char])]
([Char], [Char])
time12Fmt :: [Char]
timeFmt :: [Char]
dateFmt :: [Char]
dateTimeFmt :: [Char]
amPm :: ([Char], [Char])
wDays :: [([Char], [Char])]
months :: [([Char], [Char])]
amPm :: TimeLocale -> ([Char], [Char])
months :: TimeLocale -> [([Char], [Char])]
wDays :: TimeLocale -> [([Char], [Char])]
dateFmt :: TimeLocale -> [Char]
timeFmt :: TimeLocale -> [Char]
time12Fmt :: TimeLocale -> [Char]
dateTimeFmt :: TimeLocale -> [Char]
..} = TimeLocale
defaultTimeLocale
    {-# INLINEABLE showsTime #-}

instance FormatTime MonthDay where
    showsTime :: MonthDay -> (Char -> ShowS) -> Char -> ShowS
showsTime (MonthDay Int
m Int
d) Char -> ShowS
def Char
c = case Char
c of
        -- Month
        Char
'B' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) ([Char] -> ShowS)
-> (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char], [Char]) -> [Char]
forall a b. (a, b) -> a
fst (([Char], [Char]) -> ShowS) -> ([Char], [Char]) -> ShowS
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])]
months [([Char], [Char])] -> Int -> ([Char], [Char])
forall a. [a] -> Int -> a
!! (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
        Char
'b' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) ([Char] -> ShowS)
-> (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char], [Char]) -> [Char]
forall a b. (a, b) -> b
snd (([Char], [Char]) -> ShowS) -> ([Char], [Char]) -> ShowS
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])]
months [([Char], [Char])] -> Int -> ([Char], [Char])
forall a. [a] -> Int -> a
!! (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
        Char
'h' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) ([Char] -> ShowS)
-> (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char], [Char]) -> [Char]
forall a b. (a, b) -> b
snd (([Char], [Char]) -> ShowS) -> ([Char], [Char]) -> ShowS
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])]
months [([Char], [Char])] -> Int -> ([Char], [Char])
forall a. [a] -> Int -> a
!! (Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
        Char
'm' -> Int -> ShowS
shows02 Int
m
        -- DayOfMonth
        Char
'd' -> Int -> ShowS
shows02 Int
d
        Char
'e' -> Int -> ShowS
shows_2 Int
d
        -- default
        Char
_ -> Char -> ShowS
def Char
c
      where
        TimeLocale {[Char]
[([Char], [Char])]
([Char], [Char])
time12Fmt :: [Char]
timeFmt :: [Char]
dateFmt :: [Char]
dateTimeFmt :: [Char]
amPm :: ([Char], [Char])
wDays :: [([Char], [Char])]
months :: [([Char], [Char])]
amPm :: TimeLocale -> ([Char], [Char])
months :: TimeLocale -> [([Char], [Char])]
wDays :: TimeLocale -> [([Char], [Char])]
dateFmt :: TimeLocale -> [Char]
timeFmt :: TimeLocale -> [Char]
time12Fmt :: TimeLocale -> [Char]
dateTimeFmt :: TimeLocale -> [Char]
..} = TimeLocale
defaultTimeLocale
    {-# INLINEABLE showsTime #-}

instance FormatTime OrdinalDate where
    showsTime :: OrdinalDate -> (Char -> ShowS) -> Char -> ShowS
showsTime (OrdinalDate Int
y Int
d) Char -> ShowS
def Char
c = case Char
c of
        -- Year
        Char
'Y' -> Int -> ShowS
showsYear Int
y
        Char
'y' -> Int -> ShowS
shows02 (Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
y Int
100)
        Char
'C' -> Int -> ShowS
shows02 (Int -> Int -> Int
forall a. Integral a => a -> a -> a
div Int
y Int
100)
        -- DayOfYear
        Char
'j' -> Int -> ShowS
shows03 Int
d
        -- default
        Char
_ -> Char -> ShowS
def Char
c
    {-# INLINEABLE showsTime #-}

-- | Format Date that is represented as 'ModifiedJulianDay'
--
instance FormatTime ModifiedJulianDay where
    showsTime :: ModifiedJulianDay -> (Char -> ShowS) -> Char -> ShowS
showsTime d :: ModifiedJulianDay
d@(ModifiedJulianDay -> OrdinalDate
toOrdinalDate -> OrdinalDate
ordinal)
        = OrdinalDate -> (Char -> ShowS) -> Char -> ShowS
forall t. FormatTime t => t -> (Char -> ShowS) -> Char -> ShowS
showsTime OrdinalDate
ordinal
        ((Char -> ShowS) -> Char -> ShowS)
-> ((Char -> ShowS) -> Char -> ShowS)
-> (Char -> ShowS)
-> Char
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. YearMonthDay -> (Char -> ShowS) -> Char -> ShowS
forall t. FormatTime t => t -> (Char -> ShowS) -> Char -> ShowS
showsTime (OrdinalDate -> YearMonthDay
ymdFromOrdinal OrdinalDate
ordinal)
        ((Char -> ShowS) -> Char -> ShowS)
-> ((Char -> ShowS) -> Char -> ShowS)
-> (Char -> ShowS)
-> Char
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WeekDate -> (Char -> ShowS) -> Char -> ShowS
forall t. FormatTime t => t -> (Char -> ShowS) -> Char -> ShowS
showsTime (OrdinalDate -> ModifiedJulianDay -> WeekDate
toWeekOrdinal OrdinalDate
ordinal ModifiedJulianDay
d)
        ((Char -> ShowS) -> Char -> ShowS)
-> ((Char -> ShowS) -> Char -> ShowS)
-> (Char -> ShowS)
-> Char
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SundayWeek -> (Char -> ShowS) -> Char -> ShowS
forall t. FormatTime t => t -> (Char -> ShowS) -> Char -> ShowS
showsTime (OrdinalDate -> ModifiedJulianDay -> SundayWeek
toSundayOrdinal OrdinalDate
ordinal ModifiedJulianDay
d)
        ((Char -> ShowS) -> Char -> ShowS)
-> ((Char -> ShowS) -> Char -> ShowS)
-> (Char -> ShowS)
-> Char
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MondayWeek -> (Char -> ShowS) -> Char -> ShowS
forall t. FormatTime t => t -> (Char -> ShowS) -> Char -> ShowS
showsTime (OrdinalDate -> ModifiedJulianDay -> MondayWeek
toMondayOrdinal OrdinalDate
ordinal ModifiedJulianDay
d)
    {-# INLINEABLE showsTime #-}

instance FormatTime ModifiedJulianDate where
    showsTime :: ModifiedJulianDate -> (Char -> ShowS) -> Char -> ShowS
showsTime (ModifiedJulianDate ModifiedJulianDay
d NominalDiffTime
dt) =
        ModifiedJulianDay -> (Char -> ShowS) -> Char -> ShowS
forall t. FormatTime t => t -> (Char -> ShowS) -> Char -> ShowS
showsTime ModifiedJulianDay
d ((Char -> ShowS) -> Char -> ShowS)
-> ((Char -> ShowS) -> Char -> ShowS)
-> (Char -> ShowS)
-> Char
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeOfDay -> (Char -> ShowS) -> Char -> ShowS
forall t. FormatTime t => t -> (Char -> ShowS) -> Char -> ShowS
showsTime (NominalDiffTime -> TimeOfDay
timeOfDayFromNominalDiffTime NominalDiffTime
dt)
    {-# INLINEABLE showsTime #-}

instance FormatTime UTCTime where
    showsTime :: UTCTime -> (Char -> ShowS) -> Char -> ShowS
showsTime UTCTime
t Char -> ShowS
def Char
c = case Char
c of
        Char
's' -> Micros -> ShowS
forall a. Show a => a -> ShowS
shows (Micros -> ShowS)
-> ((Micros, Micros) -> Micros) -> (Micros, Micros) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Micros, Micros) -> Micros
forall a b. (a, b) -> a
fst ((Micros, Micros) -> ShowS) -> (Micros, Micros) -> ShowS
forall a b. (a -> b) -> a -> b
$ Micros -> Micros -> (Micros, Micros)
forall a. Integral a => a -> a -> (a, a)
quotRem (UTCTime -> Micros
toPosixTimestampMicros UTCTime
t) Micros
1000000
        Char
_ -> (ModifiedJulianDate -> (Char -> ShowS) -> Char -> ShowS
forall t. FormatTime t => t -> (Char -> ShowS) -> Char -> ShowS
showsTime (UTCTime -> ModifiedJulianDate
toModifiedJulianDate UTCTime
t) ((Char -> ShowS) -> Char -> ShowS)
-> ((Char -> ShowS) -> Char -> ShowS)
-> (Char -> ShowS)
-> Char
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> ShowS) -> Char -> ShowS
formatUtcZone) Char -> ShowS
def Char
c
    {-# INLINEABLE showsTime #-}

-- | Pact only supports UTC
--
formatUtcZone :: (Char -> ShowS) -> Char -> ShowS
formatUtcZone :: (Char -> ShowS) -> Char -> ShowS
formatUtcZone Char -> ShowS
def Char
c = case Char
c of
    Char
'z' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) [Char]
"+0000"
    Char
'N' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) [Char]
"+00:00"
    Char
'Z' -> [Char] -> ShowS
forall a. [a] -> [a] -> [a]
(++) [Char]
"UTC"
    Char
_ -> Char -> ShowS
def Char
c
{-# INLINEABLE formatUtcZone #-}

-- -------------------------------------------------------------------------- --
-- Parser Utils

utf8Char :: Char -> S.ByteString
utf8Char :: Char -> ByteString
utf8Char = ByteString -> ByteString
L.toStrict (ByteString -> ByteString)
-> (Char -> ByteString) -> Char -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
B.toLazyByteString (Builder -> ByteString) -> (Char -> Builder) -> Char -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Builder
B.charUtf8
{-# INLINE utf8Char #-}

utf8String :: String -> S.ByteString
utf8String :: [Char] -> ByteString
utf8String = ByteString -> ByteString
L.toStrict (ByteString -> ByteString)
-> ([Char] -> ByteString) -> [Char] -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
B.toLazyByteString (Builder -> ByteString)
-> ([Char] -> Builder) -> [Char] -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Builder
B.stringUtf8
{-# INLINE utf8String #-}

parserToReadS :: Parser a -> ReadS a
parserToReadS :: Parser a -> ReadS a
parserToReadS = (ByteString -> Result a) -> ReadS a
forall a. (ByteString -> Result a) -> ReadS a
go ((ByteString -> Result a) -> ReadS a)
-> (Parser a -> ByteString -> Result a) -> Parser a -> ReadS a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser a -> ByteString -> Result a
forall a. Parser a -> ByteString -> Result a
P.parse
  where
    go :: (S.ByteString -> Result a) -> ReadS a
    go :: (ByteString -> Result a) -> ReadS a
go ByteString -> Result a
k (Int -> [Char] -> ([Char], [Char])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
32 -> ([Char]
h, [Char]
t)) = case ByteString -> Result a
k ([Char] -> ByteString
utf8String [Char]
h) of
        -- `date -R | wc -c` is 32 characters
        Fail ByteString
rest [[Char]]
cxts [Char]
msg -> ReadS a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ReadS a -> ReadS a
forall a b. (a -> b) -> a -> b
$ [[Char]] -> [Char]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [ [Char]
"parserToReadS: ", [Char]
msg
            , [Char]
"; remaining: ", ShowS
forall a. Show a => a -> [Char]
show (ByteString -> [Char]
utf8Decode ByteString
rest), [Char]
"; stack: ", [[Char]] -> [Char]
forall a. Show a => a -> [Char]
show [[Char]]
cxts ]
        Partial ByteString -> Result a
k' -> (ByteString -> Result a) -> ReadS a
forall a. (ByteString -> Result a) -> ReadS a
go ByteString -> Result a
k' [Char]
t
        Done ByteString
rest a
a -> (a, [Char]) -> [(a, [Char])]
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, ByteString -> [Char]
utf8Decode ByteString
rest [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
t)
    {-# INLINEABLE go #-}

    utf8Decode :: S.ByteString -> String
    utf8Decode :: ByteString -> [Char]
utf8Decode = Text -> [Char]
Text.unpack (Text -> [Char]) -> (ByteString -> Text) -> ByteString -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
Text.decodeUtf8
    {-# INLINE utf8Decode #-}
{-# INLINEABLE parserToReadS #-}

indexOfCI :: [String] -> Parser Int
indexOfCI :: [[Char]] -> Parser Int
indexOfCI = [Parser Int] -> Parser Int
forall (f :: * -> *) a. Alternative f => [f a] -> f a
P.choice ([Parser Int] -> Parser Int)
-> ([[Char]] -> [Parser Int]) -> [[Char]] -> Parser Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> [Char] -> Parser Int) -> [Int] -> [[Char]] -> [Parser Int]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Int
i [Char]
s -> Int
i Int -> Parser ByteString () -> Parser Int
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [Char] -> Parser ByteString ()
stringCI [Char]
s) [Int
0..]
{-# INLINE indexOfCI #-}

-- | Case-insensitive UTF-8 ByteString parser
--
-- Matches one character at a time. Slow.
--
stringCI :: String -> Parser ()
stringCI :: [Char] -> Parser ByteString ()
stringCI = (Parser ByteString () -> Char -> Parser ByteString ())
-> Parser ByteString () -> [Char] -> Parser ByteString ()
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (\Parser ByteString ()
p Char
c -> Parser ByteString ()
p Parser ByteString ()
-> Parser ByteString () -> Parser ByteString ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Char -> Parser ByteString ()
charCI Char
c) (() -> Parser ByteString ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
{-# INLINE stringCI #-}

-- | Case-insensitive UTF-8 ByteString parser
--
-- We can't easily perform upper/lower case conversion on the input, so
-- instead we accept either one of @toUpper c@ and @toLower c@.
--
charCI :: Char -> Parser ()
charCI :: Char -> Parser ByteString ()
charCI Char
c = if Char
u Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
l then Char -> Parser ByteString ()
charU8 Char
c else Char -> Parser ByteString ()
charU8 Char
l Parser ByteString ()
-> Parser ByteString () -> Parser ByteString ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Char -> Parser ByteString ()
charU8 Char
u
  where
    l :: Char
l = Char -> Char
toLower Char
c
    u :: Char
u = Char -> Char
toUpper Char
c
{-# INLINE charCI #-}

charU8 :: Char -> Parser ()
charU8 :: Char -> Parser ByteString ()
charU8 Char
c = () () -> Parser ByteString ByteString -> Parser ByteString ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ByteString -> Parser ByteString ByteString
P.string (Char -> ByteString
utf8Char Char
c)
{-# INLINE charU8 #-}

-- | Number may be prefixed with '-'
--
negative :: (Integral n) => Parser n -> Parser n
negative :: Parser n -> Parser n
negative Parser n
p = (n -> n) -> n -> n
forall a b. (a -> b) -> a -> b
($) ((n -> n) -> n -> n)
-> Parser ByteString (n -> n) -> Parser ByteString (n -> n)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (n -> n
forall a. Num a => a -> a
negate (n -> n) -> Parser ByteString Char -> Parser ByteString (n -> n)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser ByteString Char
P.char Char
'-' Parser ByteString (n -> n)
-> Parser ByteString (n -> n) -> Parser ByteString (n -> n)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (n -> n) -> Parser ByteString (n -> n)
forall (f :: * -> *) a. Applicative f => a -> f a
pure n -> n
forall a. a -> a
id) Parser ByteString (n -> n) -> Parser n -> Parser n
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser n
p
{-# INLINE negative #-}

-- | Fixed-length 0-padded decimal
--
dec0 :: Int -> Parser Int
dec0 :: Int -> Parser Int
dec0 Int
n = ([Char] -> Parser Int)
-> (Int -> Parser Int) -> Either [Char] Int -> Parser Int
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either [Char] -> Parser Int
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail Int -> Parser Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Either [Char] Int -> Parser Int)
-> (ByteString -> Either [Char] Int) -> ByteString -> Parser Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser Int -> ByteString -> Either [Char] Int
forall a. Parser a -> ByteString -> Either [Char] a
P.parseOnly Parser Int
forall a. Integral a => Parser a
P.decimal (ByteString -> Parser Int)
-> Parser ByteString ByteString -> Parser Int
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int -> Parser ByteString ByteString
P.take Int
n
{-# INLINE dec0 #-}

-- | Fixed-length space-padded decimal
--
dec_ :: Int -> Parser Int
dec_ :: Int -> Parser Int
dec_ Int
n = Int -> Parser ByteString ByteString
P.take Int
n Parser ByteString ByteString
-> (ByteString -> Parser Int) -> Parser Int
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ([Char] -> Parser Int)
-> (Int -> Parser Int) -> Either [Char] Int -> Parser Int
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either [Char] -> Parser Int
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail Int -> Parser Int
forall (m :: * -> *) a. Monad m => a -> m a
return
    (Either [Char] Int -> Parser Int)
-> (ByteString -> Either [Char] Int) -> ByteString -> Parser Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser Int -> ByteString -> Either [Char] Int
forall a. Parser a -> ByteString -> Either [Char] a
P.parseOnly Parser Int
forall a. Integral a => Parser a
P.decimal
    (ByteString -> Either [Char] Int)
-> (ByteString -> ByteString) -> ByteString -> Either [Char] Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> ByteString -> ByteString
S.dropWhile Char -> Bool
isSpace
{-# INLINE dec_ #-}

-- -------------------------------------------------------------------------- --
-- Time Zones

data TimeZone = TimeZone
    { TimeZone -> Int
_timeZoneMinutes :: {-# UNPACK #-} !Minutes
    , TimeZone -> Bool
_timeZoneSummerOnly :: !Bool
    , TimeZone -> [Char]
_timeZoneName :: String
    }

timeZoneMinutes :: Lens' TimeZone Minutes
timeZoneMinutes :: (Int -> f Int) -> TimeZone -> f TimeZone
timeZoneMinutes = (TimeZone -> Int)
-> (TimeZone -> Int -> TimeZone) -> Lens TimeZone TimeZone Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TimeZone -> Int
_timeZoneMinutes ((TimeZone -> Int -> TimeZone) -> Lens TimeZone TimeZone Int Int)
-> (TimeZone -> Int -> TimeZone) -> Lens TimeZone TimeZone Int Int
forall a b. (a -> b) -> a -> b
$ \TimeZone
a Int
b -> TimeZone
a { _timeZoneMinutes :: Int
_timeZoneMinutes = Int
b }
{-# INLINE timeZoneMinutes #-}

utc :: TimeZone
utc :: TimeZone
utc = Int -> Bool -> [Char] -> TimeZone
TimeZone Int
0 Bool
False [Char]
"UTC"

timeZoneOffset :: TimeZone -> NominalDiffTime
timeZoneOffset :: TimeZone -> NominalDiffTime
timeZoneOffset = Micros -> NominalDiffTime
fromMicroseconds (Micros -> NominalDiffTime)
-> (TimeZone -> Micros) -> TimeZone -> NominalDiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Micros
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Micros) -> (TimeZone -> Int) -> TimeZone -> Micros
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Int
forall a. Num a => a -> a -> a
(*) Int
60000000 (Int -> Int) -> (TimeZone -> Int) -> TimeZone -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int
forall a. Num a => a -> a
negate (Int -> Int) -> (TimeZone -> Int) -> TimeZone -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeZone -> Int
_timeZoneMinutes
{-# INLINE timeZoneOffset #-}

-- -------------------------------------------------------------------------- --
-- Parse String into a Time Parse Value

data TimeFlag
    = PostMeridiem
    | TwelveHour
    | HasCentury
    | IsPOSIXTime
    | IsOrdinalDate
    | IsGregorian
    | IsWeekDate
    | IsSundayWeek
    | IsMondayWeek
    deriving (Int -> TimeFlag
TimeFlag -> Int
TimeFlag -> [TimeFlag]
TimeFlag -> TimeFlag
TimeFlag -> TimeFlag -> [TimeFlag]
TimeFlag -> TimeFlag -> TimeFlag -> [TimeFlag]
(TimeFlag -> TimeFlag)
-> (TimeFlag -> TimeFlag)
-> (Int -> TimeFlag)
-> (TimeFlag -> Int)
-> (TimeFlag -> [TimeFlag])
-> (TimeFlag -> TimeFlag -> [TimeFlag])
-> (TimeFlag -> TimeFlag -> [TimeFlag])
-> (TimeFlag -> TimeFlag -> TimeFlag -> [TimeFlag])
-> Enum TimeFlag
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: TimeFlag -> TimeFlag -> TimeFlag -> [TimeFlag]
$cenumFromThenTo :: TimeFlag -> TimeFlag -> TimeFlag -> [TimeFlag]
enumFromTo :: TimeFlag -> TimeFlag -> [TimeFlag]
$cenumFromTo :: TimeFlag -> TimeFlag -> [TimeFlag]
enumFromThen :: TimeFlag -> TimeFlag -> [TimeFlag]
$cenumFromThen :: TimeFlag -> TimeFlag -> [TimeFlag]
enumFrom :: TimeFlag -> [TimeFlag]
$cenumFrom :: TimeFlag -> [TimeFlag]
fromEnum :: TimeFlag -> Int
$cfromEnum :: TimeFlag -> Int
toEnum :: Int -> TimeFlag
$ctoEnum :: Int -> TimeFlag
pred :: TimeFlag -> TimeFlag
$cpred :: TimeFlag -> TimeFlag
succ :: TimeFlag -> TimeFlag
$csucc :: TimeFlag -> TimeFlag
Enum, Int -> TimeFlag -> ShowS
[TimeFlag] -> ShowS
TimeFlag -> [Char]
(Int -> TimeFlag -> ShowS)
-> (TimeFlag -> [Char]) -> ([TimeFlag] -> ShowS) -> Show TimeFlag
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [TimeFlag] -> ShowS
$cshowList :: [TimeFlag] -> ShowS
show :: TimeFlag -> [Char]
$cshow :: TimeFlag -> [Char]
showsPrec :: Int -> TimeFlag -> ShowS
$cshowsPrec :: Int -> TimeFlag -> ShowS
Show)

data TimeParse = TimeParse
    { TimeParse -> Int
_tpCentury :: {-# UNPACK #-} !Century
    , TimeParse -> Int
_tpCenturyYear :: {-# UNPACK #-} !Int{-YearOfCentury-}
    , TimeParse -> Int
_tpMonth :: {-# UNPACK #-} !Month
    , TimeParse -> Int
_tpWeekOfYear :: {-# UNPACK #-} !WeekOfYear
    , TimeParse -> Int
_tpDayOfMonth :: {-# UNPACK #-} !DayOfMonth
    , TimeParse -> Int
_tpDayOfYear :: {-# UNPACK #-} !DayOfYear
    , TimeParse -> Int
_tpDayOfWeek :: {-# UNPACK #-} !DayOfWeek
    , TimeParse -> Int
_tpFlags :: {-# UNPACK #-} !Int{-BitSet TimeFlag-}
    , TimeParse -> Int
_tpHour :: {-# UNPACK #-} !Hour
    , TimeParse -> Int
_tpMinute :: {-# UNPACK #-} !Minute
    , TimeParse -> Int
_tpSecond :: {-# UNPACK #-} !Second
    , TimeParse -> NominalDiffTime
_tpSecFrac :: {-# UNPACK #-} !NominalDiffTime
    , TimeParse -> NominalDiffTime
_tpPOSIXTime :: {-# UNPACK #-} !NominalDiffTime
    , TimeParse -> TimeZone
_tpTimeZone :: !TimeZone
    }

flag :: TimeFlag -> Lens' TimeParse Bool
flag :: TimeFlag -> Lens' TimeParse Bool
flag (TimeFlag -> Int
forall a. Enum a => a -> Int
fromEnum -> Int
f) = (Int -> f Int) -> TimeParse -> f TimeParse
Lens' TimeParse Int
tpFlags ((Int -> f Int) -> TimeParse -> f TimeParse)
-> ((Bool -> f Bool) -> Int -> f Int)
-> (Bool -> f Bool)
-> TimeParse
-> f TimeParse
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Bool) -> (Int -> Bool -> Int) -> Lens Int Int Bool Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens
    (Int -> Int -> Bool
forall a. Bits a => a -> Int -> Bool
`testBit` Int
f) (\ Int
n Bool
b -> (if Bool
b then Int -> Int -> Int
forall a. Bits a => a -> Int -> a
setBit else Int -> Int -> Int
forall a. Bits a => a -> Int -> a
clearBit) Int
n Int
f)
{-# INLINE flag #-}

tpYear :: TimeParse -> Year
tpYear :: TimeParse -> Int
tpYear TimeParse
tp = TimeParse -> Int
_tpCenturyYear TimeParse
tp Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
100 Int -> Int -> Int
forall a. Num a => a -> a -> a
* if TimeParse
tp TimeParse -> Getting Bool TimeParse Bool -> Bool
forall s a. s -> Getting a s a -> a
^. TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
HasCentury
  then TimeParse -> Int
_tpCentury TimeParse
tp
  else if TimeParse -> Int
_tpCenturyYear TimeParse
tp Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
69
    then Int
20
    else Int
19
{-# INLINE tpYear #-}

-- | Time 'Parser' for UTF-8 encoded 'ByteString's.
--
-- Attoparsec easily beats any 'String' parser out there, but we do have to
-- be careful to convert the input to UTF-8 'ByteString's.
--
timeParser :: String -> Parser TimeParse
timeParser :: [Char] -> Parser TimeParse
timeParser = (StateT TimeParse Parser () -> TimeParse -> Parser TimeParse)
-> TimeParse -> StateT TimeParse Parser () -> Parser TimeParse
forall a b c. (a -> b -> c) -> b -> a -> c
flip StateT TimeParse Parser () -> TimeParse -> Parser TimeParse
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m s
execStateT TimeParse
unixEpoch (StateT TimeParse Parser () -> Parser TimeParse)
-> ([Char] -> StateT TimeParse Parser ())
-> [Char]
-> Parser TimeParse
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> StateT TimeParse Parser ()
go
  where

    go :: String -> StateT TimeParse Parser ()
    go :: [Char] -> StateT TimeParse Parser ()
go [Char]
spec = case [Char]
spec of
        Char
'%' : Char
cspec : [Char]
rspec -> case Char
cspec of
            -- aggregate
            Char
'c' -> [Char] -> StateT TimeParse Parser ()
go (TimeLocale -> [Char]
dateTimeFmt TimeLocale
l [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
rspec)
            Char
'r' -> [Char] -> StateT TimeParse Parser ()
go (TimeLocale -> [Char]
time12Fmt TimeLocale
l [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
rspec)
            Char
'X' -> [Char] -> StateT TimeParse Parser ()
go (TimeLocale -> [Char]
timeFmt TimeLocale
l [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
rspec)
            Char
'x' -> [Char] -> StateT TimeParse Parser ()
go (TimeLocale -> [Char]
dateFmt TimeLocale
l [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
rspec)
            Char
'R' -> [Char] -> StateT TimeParse Parser ()
go ([Char]
"%H:%M" [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
rspec)
            Char
'T' -> [Char] -> StateT TimeParse Parser ()
go ([Char]
"%H:%M:%S" [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
rspec)
            Char
'D' -> [Char] -> StateT TimeParse Parser ()
go ([Char]
"%m/%d/%y" [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
rspec)
            Char
'F' -> [Char] -> StateT TimeParse Parser ()
go ([Char]
"%Y-%m-%d" [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
rspec)
            -- AM/PM
            Char
'P' -> StateT TimeParse Parser ()
dayHalf
            Char
'p' -> StateT TimeParse Parser ()
dayHalf
            -- Hour
            Char
'H' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setHour24
            Char
'I' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setHour12
            Char
'k' -> (Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec_ Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setHour24)
                StateT TimeParse Parser ()
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec_ Int
1) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setHour24)
            Char
'l' -> (Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec_ Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setHour12)
                StateT TimeParse Parser ()
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec_ Int
1) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setHour12)
            -- Minute
            Char
'M' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ASetter TimeParse TimeParse Int Int
-> Int -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
assign ASetter TimeParse TimeParse Int Int
Lens' TimeParse Int
tpMinute StateT TimeParse Parser ()
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            -- Second
            Char
'S' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ASetter TimeParse TimeParse Int Int
-> Int -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
assign ASetter TimeParse TimeParse Int Int
Lens' TimeParse Int
tpSecond StateT TimeParse Parser ()
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> StateT TimeParse Parser ()
go [Char]
rspec

            -- TODO: Unsupported by pact
            Char
'q' -> Parser ByteString Micros -> StateT TimeParse Parser Micros
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Parser ByteString Micros
micro StateT TimeParse Parser Micros
-> (Micros -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ASetter TimeParse TimeParse NominalDiffTime NominalDiffTime
-> NominalDiffTime -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
assign ASetter TimeParse TimeParse NominalDiffTime NominalDiffTime
Lens' TimeParse NominalDiffTime
tpSecFrac (NominalDiffTime -> StateT TimeParse Parser ())
-> (Micros -> NominalDiffTime)
-> Micros
-> StateT TimeParse Parser ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Micros -> NominalDiffTime
NominalDiffTime StateT TimeParse Parser ()
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> StateT TimeParse Parser ()
go [Char]
rspec

            Char
'v' -> Parser ByteString Micros -> StateT TimeParse Parser Micros
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Parser ByteString Micros
micro StateT TimeParse Parser Micros
-> (Micros -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ASetter TimeParse TimeParse NominalDiffTime NominalDiffTime
-> NominalDiffTime -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
assign ASetter TimeParse TimeParse NominalDiffTime NominalDiffTime
Lens' TimeParse NominalDiffTime
tpSecFrac (NominalDiffTime -> StateT TimeParse Parser ())
-> (Micros -> NominalDiffTime)
-> Micros
-> StateT TimeParse Parser ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Micros -> NominalDiffTime
NominalDiffTime StateT TimeParse Parser ()
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            Char
'Q' -> Parser ByteString NominalDiffTime
-> StateT TimeParse Parser NominalDiffTime
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((Char -> Parser ByteString Char
P.char Char
'.' Parser ByteString Char
-> Parser ByteString NominalDiffTime
-> Parser ByteString NominalDiffTime
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Micros -> NominalDiffTime
NominalDiffTime (Micros -> NominalDiffTime)
-> Parser ByteString Micros -> Parser ByteString NominalDiffTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Micros
micro) Parser ByteString NominalDiffTime
-> Parser ByteString NominalDiffTime
-> Parser ByteString NominalDiffTime
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> NominalDiffTime -> Parser ByteString NominalDiffTime
forall (m :: * -> *) a. Monad m => a -> m a
return NominalDiffTime
forall v. AdditiveGroup v => v
zeroV)
                StateT TimeParse Parser NominalDiffTime
-> (NominalDiffTime -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ASetter TimeParse TimeParse NominalDiffTime NominalDiffTime
-> NominalDiffTime -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
assign ASetter TimeParse TimeParse NominalDiffTime NominalDiffTime
Lens' TimeParse NominalDiffTime
tpSecFrac StateT TimeParse Parser ()
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> StateT TimeParse Parser ()
go [Char]
rspec

            -- Year
            Char
'Y' -> StateT TimeParse Parser ()
fullYear
            Char
'y' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setCenturyYear
            Char
'C' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setCentury
            -- Month
            Char
'B' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ([[Char]] -> Parser Int
indexOfCI ([[Char]] -> Parser Int) -> [[Char]] -> Parser Int
forall a b. (a -> b) -> a -> b
$ ([Char], [Char]) -> [Char]
forall a b. (a, b) -> a
fst (([Char], [Char]) -> [Char]) -> [([Char], [Char])] -> [[Char]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeLocale -> [([Char], [Char])]
months TimeLocale
l) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setMonth (Int -> StateT TimeParse Parser ())
-> (Int -> Int) -> Int -> StateT TimeParse Parser ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int
forall a. Enum a => a -> a
succ
            Char
'b' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ([[Char]] -> Parser Int
indexOfCI ([[Char]] -> Parser Int) -> [[Char]] -> Parser Int
forall a b. (a -> b) -> a -> b
$ ([Char], [Char]) -> [Char]
forall a b. (a, b) -> b
snd (([Char], [Char]) -> [Char]) -> [([Char], [Char])] -> [[Char]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeLocale -> [([Char], [Char])]
months TimeLocale
l) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setMonth (Int -> StateT TimeParse Parser ())
-> (Int -> Int) -> Int -> StateT TimeParse Parser ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int
forall a. Enum a => a -> a
succ
            Char
'h' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ([[Char]] -> Parser Int
indexOfCI ([[Char]] -> Parser Int) -> [[Char]] -> Parser Int
forall a b. (a -> b) -> a -> b
$ ([Char], [Char]) -> [Char]
forall a b. (a, b) -> b
snd (([Char], [Char]) -> [Char]) -> [([Char], [Char])] -> [[Char]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeLocale -> [([Char], [Char])]
months TimeLocale
l) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setMonth (Int -> StateT TimeParse Parser ())
-> (Int -> Int) -> Int -> StateT TimeParse Parser ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int
forall a. Enum a => a -> a
succ
            Char
'm' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setMonth
            -- DayOfMonth
            Char
'd' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setDayOfMonth
            Char
'e' -> (Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec_ Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setDayOfMonth)
                StateT TimeParse Parser ()
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec_ Int
1) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setDayOfMonth)
            -- DayOfYear
            Char
'j' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
3) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ASetter TimeParse TimeParse Int Int
-> Int -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
assign ASetter TimeParse TimeParse Int Int
Lens' TimeParse Int
tpDayOfYear
                StateT TimeParse Parser ()
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsOrdinalDate ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True StateT TimeParse Parser ()
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> StateT TimeParse Parser ()
go [Char]
rspec

            -- Year (WeekDate)
            -- FIXME: problematic if input contains both %Y and %G
            Char
'G' -> TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsWeekDate ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True StateT TimeParse Parser ()
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> StateT TimeParse Parser ()
fullYear
            Char
'g' -> TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsWeekDate ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True StateT TimeParse Parser ()
-> StateT TimeParse Parser Int -> StateT TimeParse Parser Int
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setCenturyYear
            Char
'f' -> TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsWeekDate ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True StateT TimeParse Parser ()
-> StateT TimeParse Parser Int -> StateT TimeParse Parser Int
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setCentury
            -- WeekOfYear
            -- FIXME: problematic if more than one of the following
            Char
'V' -> TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsWeekDate ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True StateT TimeParse Parser ()
-> StateT TimeParse Parser Int -> StateT TimeParse Parser Int
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setWeekOfYear
            Char
'U' -> TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsSundayWeek ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True StateT TimeParse Parser ()
-> StateT TimeParse Parser Int -> StateT TimeParse Parser Int
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setWeekOfYear
            Char
'W' -> TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsMondayWeek ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True StateT TimeParse Parser ()
-> StateT TimeParse Parser Int -> StateT TimeParse Parser Int
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
2) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setWeekOfYear
            -- DayOfWeek
            Char
'w' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
1) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setDayOfWeek
            Char
'u' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
1) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setDayOfWeek
            Char
'A' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ([[Char]] -> Parser Int
indexOfCI ([[Char]] -> Parser Int) -> [[Char]] -> Parser Int
forall a b. (a -> b) -> a -> b
$ ([Char], [Char]) -> [Char]
forall a b. (a, b) -> a
fst (([Char], [Char]) -> [Char]) -> [([Char], [Char])] -> [[Char]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeLocale -> [([Char], [Char])]
wDays TimeLocale
l) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setDayOfWeek
            Char
'a' -> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ([[Char]] -> Parser Int
indexOfCI ([[Char]] -> Parser Int) -> [[Char]] -> Parser Int
forall a b. (a -> b) -> a -> b
$ ([Char], [Char]) -> [Char]
forall a b. (a, b) -> b
snd (([Char], [Char]) -> [Char]) -> [([Char], [Char])] -> [[Char]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeLocale -> [([Char], [Char])]
wDays TimeLocale
l) StateT TimeParse Parser Int
-> (Int -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> StateT TimeParse Parser ()
setDayOfWeek

            -- TimeZone
            Char
'z' -> do StateT TimeParse Parser ()
tzOffset; [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            Char
'N' -> do StateT TimeParse Parser ()
tzOffset; [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            Char
'Z' -> do StateT TimeParse Parser ()
tzOffset StateT TimeParse Parser ()
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> StateT TimeParse Parser ()
tzName; [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            -- UTCTime
            Char
's' -> do
                Micros
s <- Parser ByteString Micros -> StateT TimeParse Parser Micros
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Parser ByteString Micros -> Parser ByteString Micros
forall n. Integral n => Parser n -> Parser n
negative Parser ByteString Micros
forall a. Integral a => Parser a
P.decimal)
                ASetter TimeParse TimeParse NominalDiffTime NominalDiffTime
Lens' TimeParse NominalDiffTime
tpPOSIXTime ASetter TimeParse TimeParse NominalDiffTime NominalDiffTime
-> NominalDiffTime -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Micros -> NominalDiffTime
fromMicroseconds (Micros
1000000 Micros -> Micros -> Micros
forall a. Num a => a -> a -> a
* Micros
s)
                TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsPOSIXTime ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True
                [Char] -> StateT TimeParse Parser ()
go [Char]
rspec

            -- modifier (whatever)
            Char
'-' -> [Char] -> StateT TimeParse Parser ()
go (Char
'%' Char -> ShowS
forall a. a -> [a] -> [a]
: [Char]
rspec)
            Char
'_' -> [Char] -> StateT TimeParse Parser ()
go (Char
'%' Char -> ShowS
forall a. a -> [a] -> [a]
: [Char]
rspec)
            Char
'0' -> [Char] -> StateT TimeParse Parser ()
go (Char
'%' Char -> ShowS
forall a. a -> [a] -> [a]
: [Char]
rspec)
            -- escape (why would anyone need %t and %n?)
            Char
'%' -> Parser ByteString Char -> StateT TimeParse Parser Char
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Char -> Parser ByteString Char
P.char Char
'%') StateT TimeParse Parser Char
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            Char
_ -> Parser ByteString () -> StateT TimeParse Parser ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Parser ByteString () -> StateT TimeParse Parser ())
-> ([Char] -> Parser ByteString ())
-> [Char]
-> StateT TimeParse Parser ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Parser ByteString ()
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char] -> StateT TimeParse Parser ())
-> [Char] -> StateT TimeParse Parser ()
forall a b. (a -> b) -> a -> b
$ [Char]
"Unknown format character: " [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ Char -> [Char]
forall a. Show a => a -> [Char]
show Char
cspec

          where
            l :: TimeLocale
l = TimeLocale
defaultTimeLocale
            dayHalf :: StateT TimeParse Parser ()
dayHalf = do
                Bool
pm <- Parser ByteString Bool -> StateT TimeParse Parser Bool
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Parser ByteString Bool -> StateT TimeParse Parser Bool)
-> Parser ByteString Bool -> StateT TimeParse Parser Bool
forall a b. (a -> b) -> a -> b
$ Bool
False Bool -> Parser ByteString () -> Parser ByteString Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [Char] -> Parser ByteString ()
stringCI (([Char], [Char]) -> [Char]
forall a b. (a, b) -> a
fst (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> [Char]
forall a b. (a -> b) -> a -> b
$ TimeLocale -> ([Char], [Char])
amPm TimeLocale
l)
                    Parser ByteString Bool
-> Parser ByteString Bool -> Parser ByteString Bool
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Bool
True Bool -> Parser ByteString () -> Parser ByteString Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [Char] -> Parser ByteString ()
stringCI (([Char], [Char]) -> [Char]
forall a b. (a, b) -> b
snd (([Char], [Char]) -> [Char]) -> ([Char], [Char]) -> [Char]
forall a b. (a -> b) -> a -> b
$ TimeLocale -> ([Char], [Char])
amPm TimeLocale
l)
                TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
PostMeridiem ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
pm
                TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
TwelveHour ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True
                [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            -- NOTE: if a greedy parse fails or causes a later failure,
            -- then backtrack and only accept 4-digit years; see #5.
            fullYear :: StateT TimeParse Parser ()
fullYear = Parser Int -> StateT TimeParse Parser ()
year (Parser Int -> Parser Int
forall n. Integral n => Parser n -> Parser n
negative Parser Int
forall a. Integral a => Parser a
P.decimal) StateT TimeParse Parser ()
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser Int -> StateT TimeParse Parser ()
year (Int -> Parser Int
dec0 Int
4)
              where
                year :: Parser Int -> StateT TimeParse Parser ()
year Parser Int
p = do
                    (Int
c, Int
y) <- (Int -> Int -> (Int, Int)
forall a. Integral a => a -> a -> (a, a)
`divMod` Int
100) (Int -> (Int, Int))
-> StateT TimeParse Parser Int
-> StateT TimeParse Parser (Int, Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Parser Int
p
                    TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
HasCentury ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True
                    ASetter TimeParse TimeParse Int Int
Lens' TimeParse Int
tpCentury ASetter TimeParse TimeParse Int Int
-> Int -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Int
c
                    ASetter TimeParse TimeParse Int Int
Lens' TimeParse Int
tpCenturyYear ASetter TimeParse TimeParse Int Int
-> Int -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Int
y
                    [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            setHour12 :: Int -> StateT TimeParse Parser ()
setHour12 Int
h = do
                TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
TwelveHour ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True
                ASetter TimeParse TimeParse Int Int
Lens' TimeParse Int
tpHour ASetter TimeParse TimeParse Int Int
-> Int -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Int
h
                [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            setHour24 :: Int -> StateT TimeParse Parser ()
setHour24 Int
h = do
                TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
TwelveHour ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
False
                ASetter TimeParse TimeParse Int Int
Lens' TimeParse Int
tpHour ASetter TimeParse TimeParse Int Int
-> Int -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Int
h
                [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            setCenturyYear :: Int -> StateT TimeParse Parser ()
setCenturyYear Int
y = do ASetter TimeParse TimeParse Int Int
Lens' TimeParse Int
tpCenturyYear ASetter TimeParse TimeParse Int Int
-> Int -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Int
y; [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            setCentury :: Int -> StateT TimeParse Parser ()
setCentury Int
c = do
                ASetter TimeParse TimeParse Int Int
Lens' TimeParse Int
tpCentury ASetter TimeParse TimeParse Int Int
-> Int -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Int
c
                TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
HasCentury ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True
                [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            setMonth :: Int -> StateT TimeParse Parser ()
setMonth Int
m = do
                TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsGregorian ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True
                ASetter TimeParse TimeParse Int Int
Lens' TimeParse Int
tpMonth ASetter TimeParse TimeParse Int Int
-> Int -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Int
m
                [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            setDayOfMonth :: Int -> StateT TimeParse Parser ()
setDayOfMonth Int
d = do
                TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsGregorian ((Bool -> Identity Bool) -> TimeParse -> Identity TimeParse)
-> Bool -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True
                ASetter TimeParse TimeParse Int Int
Lens' TimeParse Int
tpDayOfMonth ASetter TimeParse TimeParse Int Int
-> Int -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Int
d
                [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            setWeekOfYear :: Int -> StateT TimeParse Parser ()
setWeekOfYear Int
w = do ASetter TimeParse TimeParse Int Int
Lens' TimeParse Int
tpWeekOfYear ASetter TimeParse TimeParse Int Int
-> Int -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Int
w; [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            setDayOfWeek :: Int -> StateT TimeParse Parser ()
setDayOfWeek Int
d = do ASetter TimeParse TimeParse Int Int
Lens' TimeParse Int
tpDayOfWeek ASetter TimeParse TimeParse Int Int
-> Int -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Int
d; [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
            tzOffset :: StateT TimeParse Parser ()
tzOffset = do
                Int -> Int
s <- Parser ByteString (Int -> Int)
-> StateT TimeParse Parser (Int -> Int)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Int
forall a. a -> a
id (Int -> Int)
-> Parser ByteString Char -> Parser ByteString (Int -> Int)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser ByteString Char
P.char Char
'+' Parser ByteString (Int -> Int)
-> Parser ByteString (Int -> Int) -> Parser ByteString (Int -> Int)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Int -> Int
forall a. Num a => a -> a
negate (Int -> Int)
-> Parser ByteString Char -> Parser ByteString (Int -> Int)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> Parser ByteString Char
P.char Char
'-')
                Int
h <- Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
2)
                () () -> StateT TimeParse Parser Char -> StateT TimeParse Parser ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Parser ByteString Char -> StateT TimeParse Parser Char
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Char -> Parser ByteString Char
P.char Char
':') StateT TimeParse Parser ()
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> () -> StateT TimeParse Parser ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
                Int
m <- Parser Int -> StateT TimeParse Parser Int
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Int -> Parser Int
dec0 Int
2)
                (TimeZone -> Identity TimeZone) -> TimeParse -> Identity TimeParse
Lens' TimeParse TimeZone
tpTimeZone ((TimeZone -> Identity TimeZone)
 -> TimeParse -> Identity TimeParse)
-> ((Int -> Identity Int) -> TimeZone -> Identity TimeZone)
-> ASetter TimeParse TimeParse Int Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Identity Int) -> TimeZone -> Identity TimeZone
Lens TimeZone TimeZone Int Int
timeZoneMinutes ASetter TimeParse TimeParse Int Int
-> Int -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Int -> Int
s (Int
h Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
60 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
m)
            tzName :: StateT TimeParse Parser ()
tzName = Parser ByteString TimeZone -> StateT TimeParse Parser TimeZone
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Parser ByteString TimeZone
timeZoneParser StateT TimeParse Parser TimeZone
-> (TimeZone -> StateT TimeParse Parser ())
-> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ((TimeZone -> Identity TimeZone)
 -> TimeParse -> Identity TimeParse)
-> TimeZone -> StateT TimeParse Parser ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
assign (TimeZone -> Identity TimeZone) -> TimeParse -> Identity TimeParse
Lens' TimeParse TimeZone
tpTimeZone

        Char
c : [Char]
rspec | Char -> Bool
P.isSpace Char
c ->
            Parser ByteString ByteString -> StateT TimeParse Parser ByteString
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((Char -> Bool) -> Parser ByteString ByteString
P.takeWhile Char -> Bool
P.isSpace) StateT TimeParse Parser ByteString
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> StateT TimeParse Parser ()
go ((Char -> Bool) -> ShowS
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
P.isSpace [Char]
rspec)
        Char
c : [Char]
rspec | Char -> Bool
isAscii Char
c -> Parser ByteString Char -> StateT TimeParse Parser Char
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Char -> Parser ByteString Char
P.char Char
c) StateT TimeParse Parser Char
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
        Char
c : [Char]
rspec -> Parser ByteString () -> StateT TimeParse Parser ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Char -> Parser ByteString ()
charU8 Char
c) StateT TimeParse Parser ()
-> StateT TimeParse Parser () -> StateT TimeParse Parser ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> StateT TimeParse Parser ()
go [Char]
rspec
        [Char]
"" -> () -> StateT TimeParse Parser ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

    micro :: Parser Int64
    micro :: Parser ByteString Micros
micro = do
        Micros
us10 <- ([Char] -> Parser ByteString Micros)
-> (Micros -> Parser ByteString Micros)
-> Either [Char] Micros
-> Parser ByteString Micros
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either [Char] -> Parser ByteString Micros
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail Micros -> Parser ByteString Micros
forall (m :: * -> *) a. Monad m => a -> m a
return (Either [Char] Micros -> Parser ByteString Micros)
-> (ByteString -> Either [Char] Micros)
-> ByteString
-> Parser ByteString Micros
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser ByteString Micros -> ByteString -> Either [Char] Micros
forall a. Parser a -> ByteString -> Either [Char] a
P.parseOnly Parser ByteString Micros
forall a. Integral a => Parser a
P.decimal (ByteString -> Either [Char] Micros)
-> (ByteString -> ByteString) -> ByteString -> Either [Char] Micros
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ByteString -> ByteString
S.take Int
7
            (ByteString -> ByteString)
-> (ByteString -> ByteString) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> ByteString -> ByteString
`S.append` [Char] -> ByteString
S.pack [Char]
"000000") (ByteString -> Parser ByteString Micros)
-> Parser ByteString ByteString -> Parser ByteString Micros
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (Char -> Bool) -> Parser ByteString ByteString
P.takeWhile1 Char -> Bool
P.isDigit
        Micros -> Parser ByteString Micros
forall (m :: * -> *) a. Monad m => a -> m a
return (Micros -> Micros -> Micros
forall a. Integral a => a -> a -> a
div (Micros
us10 Micros -> Micros -> Micros
forall a. Num a => a -> a -> a
+ Micros
5) Micros
10)
    {-# INLINE micro #-}

    unixEpoch :: TimeParse
    unixEpoch :: TimeParse
unixEpoch = TimeParse :: Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> NominalDiffTime
-> NominalDiffTime
-> TimeZone
-> TimeParse
TimeParse
        { _tpCentury :: Int
_tpCentury = Int
19
        , _tpCenturyYear :: Int
_tpCenturyYear = Int
70
        , _tpMonth :: Int
_tpMonth = Int
1
        , _tpWeekOfYear :: Int
_tpWeekOfYear = Int
1
        , _tpDayOfYear :: Int
_tpDayOfYear = Int
1
        , _tpDayOfMonth :: Int
_tpDayOfMonth = Int
1
        , _tpDayOfWeek :: Int
_tpDayOfWeek = Int
4
        , _tpFlags :: Int
_tpFlags = Int
0
        , _tpHour :: Int
_tpHour = Int
0
        , _tpMinute :: Int
_tpMinute = Int
0
        , _tpSecond :: Int
_tpSecond = Int
0
        , _tpSecFrac :: NominalDiffTime
_tpSecFrac = NominalDiffTime
forall v. AdditiveGroup v => v
zeroV
        , _tpPOSIXTime :: NominalDiffTime
_tpPOSIXTime = NominalDiffTime
forall v. AdditiveGroup v => v
zeroV
        , _tpTimeZone :: TimeZone
_tpTimeZone = TimeZone
utc
        }
    {-# INLINE unixEpoch #-}
{-# INLINEABLE timeParser #-}

parseTime :: String -> String -> Maybe UTCTime
parseTime :: [Char] -> [Char] -> Maybe UTCTime
parseTime [Char]
spec = ([Char] -> Maybe UTCTime)
-> (UTCTime -> Maybe UTCTime)
-> Either [Char] UTCTime
-> Maybe UTCTime
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe UTCTime -> [Char] -> Maybe UTCTime
forall a b. a -> b -> a
const Maybe UTCTime
forall a. Maybe a
Nothing) UTCTime -> Maybe UTCTime
forall a. a -> Maybe a
Just
    (Either [Char] UTCTime -> Maybe UTCTime)
-> ([Char] -> Either [Char] UTCTime) -> [Char] -> Maybe UTCTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser UTCTime -> ByteString -> Either [Char] UTCTime
forall a. Parser a -> ByteString -> Either [Char] a
P.parseOnly Parser UTCTime
parser (ByteString -> Either [Char] UTCTime)
-> ([Char] -> ByteString) -> [Char] -> Either [Char] UTCTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ByteString
utf8String
  where
    parser :: Parser UTCTime
parser = TimeParse -> UTCTime
forall t. ParseTime t => TimeParse -> t
buildTime (TimeParse -> UTCTime)
-> Parser ByteString () -> Parser ByteString (TimeParse -> UTCTime)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Parser ByteString ()
P.skipSpace Parser ByteString (TimeParse -> UTCTime)
-> Parser TimeParse -> Parser UTCTime
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Char] -> Parser TimeParse
timeParser [Char]
spec
        Parser UTCTime -> Parser ByteString () -> Parser UTCTime
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
P.skipSpace Parser UTCTime -> Parser ByteString () -> Parser UTCTime
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
forall t. Chunk t => Parser t ()
P.endOfInput
{-# INLINEABLE parseTime #-}

readTime :: (ParseTime t) => String -> String -> t
readTime :: [Char] -> [Char] -> t
readTime [Char]
spec = ([Char] -> t) -> (t -> t) -> Either [Char] t -> t
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either [Char] -> t
forall a. HasCallStack => [Char] -> a
error t -> t
forall a. a -> a
id (Either [Char] t -> t)
-> ([Char] -> Either [Char] t) -> [Char] -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser t -> ByteString -> Either [Char] t
forall a. Parser a -> ByteString -> Either [Char] a
P.parseOnly Parser t
parser (ByteString -> Either [Char] t)
-> ([Char] -> ByteString) -> [Char] -> Either [Char] t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ByteString
utf8String
  where
    parser :: Parser t
parser = TimeParse -> t
forall t. ParseTime t => TimeParse -> t
buildTime (TimeParse -> t)
-> Parser ByteString () -> Parser ByteString (TimeParse -> t)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Parser ByteString ()
P.skipSpace Parser ByteString (TimeParse -> t) -> Parser TimeParse -> Parser t
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Char] -> Parser TimeParse
timeParser [Char]
spec
        Parser t -> Parser ByteString () -> Parser t
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
P.skipSpace Parser t -> Parser ByteString () -> Parser t
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
forall t. Chunk t => Parser t ()
P.endOfInput
{-# INLINEABLE readTime #-}

readsTime :: (ParseTime t) => String -> ReadS t
readsTime :: [Char] -> ReadS t
readsTime [Char]
spec = Parser t -> ReadS t
forall a. Parser a -> ReadS a
parserToReadS (Parser t -> ReadS t) -> Parser t -> ReadS t
forall a b. (a -> b) -> a -> b
$
    TimeParse -> t
forall t. ParseTime t => TimeParse -> t
buildTime (TimeParse -> t)
-> Parser ByteString () -> Parser ByteString (TimeParse -> t)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Parser ByteString ()
P.skipSpace Parser ByteString (TimeParse -> t) -> Parser TimeParse -> Parser t
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Char] -> Parser TimeParse
timeParser [Char]
spec
{-# INLINEABLE readsTime #-}

-- -------------------------------------------------------------------------- --
-- Build Parse Time

class ParseTime t where
    buildTime :: TimeParse -> t

instance ParseTime TimeOfDay where
    buildTime :: TimeParse -> TimeOfDay
buildTime TimeParse
tp = Int -> Int -> NominalDiffTime -> TimeOfDay
TimeOfDay Int
h (TimeParse -> Int
_tpMinute TimeParse
tp)
        (Micros -> NominalDiffTime
fromMicroseconds (Micros
1000000 Micros -> Micros -> Micros
forall a. Num a => a -> a -> a
* Int -> Micros
forall a b. (Integral a, Num b) => a -> b
fromIntegral (TimeParse -> Int
_tpSecond TimeParse
tp)) NominalDiffTime -> NominalDiffTime -> NominalDiffTime
forall v. AdditiveGroup v => v -> v -> v
^+^ TimeParse -> NominalDiffTime
_tpSecFrac TimeParse
tp)
      where
        h :: Int
h = if TimeParse
tp TimeParse -> Getting Bool TimeParse Bool -> Bool
forall s a. s -> Getting a s a -> a
^. TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
TwelveHour
              then if TimeParse
tp TimeParse -> Getting Bool TimeParse Bool -> Bool
forall s a. s -> Getting a s a -> a
^. TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
PostMeridiem
                then if TimeParse -> Int
_tpHour TimeParse
tp Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
12
                  then TimeParse -> Int
_tpHour TimeParse
tp Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
12
                  else TimeParse -> Int
_tpHour TimeParse
tp
                else Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod (TimeParse -> Int
_tpHour TimeParse
tp) Int
12
              else TimeParse -> Int
_tpHour TimeParse
tp
    {-# INLINE buildTime #-}

instance ParseTime YearMonthDay where
    buildTime :: TimeParse -> YearMonthDay
buildTime TimeParse
tp = Int -> Int -> Int -> YearMonthDay
YearMonthDay (TimeParse -> Int
tpYear TimeParse
tp) (TimeParse -> Int
_tpMonth TimeParse
tp) (TimeParse -> Int
_tpDayOfMonth TimeParse
tp)
    {-# INLINE buildTime #-}

instance ParseTime OrdinalDate where
    buildTime :: TimeParse -> OrdinalDate
buildTime TimeParse
tp = Int -> Int -> OrdinalDate
OrdinalDate (TimeParse -> Int
tpYear TimeParse
tp) (TimeParse -> Int
_tpDayOfYear TimeParse
tp)
    {-# INLINE buildTime #-}

instance ParseTime WeekDate where
    buildTime :: TimeParse -> WeekDate
buildTime TimeParse
tp = Int -> Int -> Int -> WeekDate
WeekDate (TimeParse -> Int
tpYear TimeParse
tp) (TimeParse -> Int
_tpWeekOfYear TimeParse
tp)
        (if TimeParse -> Int
_tpDayOfWeek TimeParse
tp Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
7 else TimeParse -> Int
_tpDayOfWeek TimeParse
tp)
    {-# INLINE buildTime #-}

instance ParseTime SundayWeek where
    buildTime :: TimeParse -> SundayWeek
buildTime TimeParse
tp = Int -> Int -> Int -> SundayWeek
SundayWeek (TimeParse -> Int
tpYear TimeParse
tp) (TimeParse -> Int
_tpWeekOfYear TimeParse
tp)
        (if TimeParse -> Int
_tpDayOfWeek TimeParse
tp Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
7 then Int
0 else TimeParse -> Int
_tpDayOfWeek TimeParse
tp)
    {-# INLINE buildTime #-}

instance ParseTime MondayWeek where
    buildTime :: TimeParse -> MondayWeek
buildTime TimeParse
tp = Int -> Int -> Int -> MondayWeek
MondayWeek (TimeParse -> Int
tpYear TimeParse
tp) (TimeParse -> Int
_tpWeekOfYear TimeParse
tp)
        (if TimeParse -> Int
_tpDayOfWeek TimeParse
tp Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Int
7 else TimeParse -> Int
_tpDayOfWeek TimeParse
tp)
    {-# INLINE buildTime #-}

instance ParseTime ModifiedJulianDay where
    {-# INLINE buildTime #-}
    buildTime :: TimeParse -> ModifiedJulianDay
buildTime TimeParse
tp
        | TimeParse
tp TimeParse -> Getting Bool TimeParse Bool -> Bool
forall s a. s -> Getting a s a -> a
^. TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsOrdinalDate = OrdinalDate -> ModifiedJulianDay
fromOrdinalDate (OrdinalDate -> ModifiedJulianDay)
-> OrdinalDate -> ModifiedJulianDay
forall a b. (a -> b) -> a -> b
$ TimeParse -> OrdinalDate
forall t. ParseTime t => TimeParse -> t
buildTime TimeParse
tp
        | TimeParse
tp TimeParse -> Getting Bool TimeParse Bool -> Bool
forall s a. s -> Getting a s a -> a
^. TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsGregorian = YearMonthDay -> ModifiedJulianDay
toGregorian (YearMonthDay -> ModifiedJulianDay)
-> YearMonthDay -> ModifiedJulianDay
forall a b. (a -> b) -> a -> b
$ TimeParse -> YearMonthDay
forall t. ParseTime t => TimeParse -> t
buildTime TimeParse
tp
        | TimeParse
tp TimeParse -> Getting Bool TimeParse Bool -> Bool
forall s a. s -> Getting a s a -> a
^. TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsWeekDate = WeekDate -> ModifiedJulianDay
fromWeekDate (WeekDate -> ModifiedJulianDay) -> WeekDate -> ModifiedJulianDay
forall a b. (a -> b) -> a -> b
$ TimeParse -> WeekDate
forall t. ParseTime t => TimeParse -> t
buildTime TimeParse
tp
        | TimeParse
tp TimeParse -> Getting Bool TimeParse Bool -> Bool
forall s a. s -> Getting a s a -> a
^. TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsSundayWeek = SundayWeek -> ModifiedJulianDay
fromSundayWeek (SundayWeek -> ModifiedJulianDay)
-> SundayWeek -> ModifiedJulianDay
forall a b. (a -> b) -> a -> b
$ TimeParse -> SundayWeek
forall t. ParseTime t => TimeParse -> t
buildTime TimeParse
tp
        | TimeParse
tp TimeParse -> Getting Bool TimeParse Bool -> Bool
forall s a. s -> Getting a s a -> a
^. TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsMondayWeek = MondayWeek -> ModifiedJulianDay
fromMondayWeek (MondayWeek -> ModifiedJulianDay)
-> MondayWeek -> ModifiedJulianDay
forall a b. (a -> b) -> a -> b
$ TimeParse -> MondayWeek
forall t. ParseTime t => TimeParse -> t
buildTime TimeParse
tp
        | Bool
otherwise = OrdinalDate -> ModifiedJulianDay
fromOrdinalDate (OrdinalDate -> ModifiedJulianDay)
-> OrdinalDate -> ModifiedJulianDay
forall a b. (a -> b) -> a -> b
$ TimeParse -> OrdinalDate
forall t. ParseTime t => TimeParse -> t
buildTime TimeParse
tp
        -- TODO: Better conflict handling when multiple flags are set?

instance ParseTime TimeZone where
    buildTime :: TimeParse -> TimeZone
buildTime = TimeParse -> TimeZone
_tpTimeZone
    {-# INLINE buildTime #-}

instance ParseTime UTCTime where
    buildTime :: TimeParse -> UTCTime
buildTime TimeParse
tp = if TimeParse
tp TimeParse -> Getting Bool TimeParse Bool -> Bool
forall s a. s -> Getting a s a -> a
^. TimeFlag -> Lens' TimeParse Bool
flag TimeFlag
IsPOSIXTime
        then  Micros -> UTCTime
fromPosixTimestampMicros (Micros -> UTCTime) -> Micros -> UTCTime
forall a b. (a -> b) -> a -> b
$ NominalDiffTime -> Micros
toMicroseconds (NominalDiffTime -> Micros) -> NominalDiffTime -> Micros
forall a b. (a -> b) -> a -> b
$ TimeParse -> NominalDiffTime
_tpPOSIXTime TimeParse
tp
        else UTCTime
zoned
      where
        d :: ModifiedJulianDay
        d :: ModifiedJulianDay
d = TimeParse -> ModifiedJulianDay
forall t. ParseTime t => TimeParse -> t
buildTime TimeParse
tp

        dt :: TimeOfDay
        dt :: TimeOfDay
dt = TimeParse -> TimeOfDay
forall t. ParseTime t => TimeParse -> t
buildTime TimeParse
tp

        tz :: TimeZone
        tz :: TimeZone
tz = TimeParse -> TimeZone
forall t. ParseTime t => TimeParse -> t
buildTime TimeParse
tp

        jul :: ModifiedJulianDate
        jul :: ModifiedJulianDate
jul = ModifiedJulianDay -> NominalDiffTime -> ModifiedJulianDate
ModifiedJulianDate ModifiedJulianDay
d (TimeOfDay -> NominalDiffTime
toDayTime TimeOfDay
dt)

        zoned :: UTCTime
        zoned :: UTCTime
zoned = ModifiedJulianDate -> UTCTime
fromModifiedJulianDate ModifiedJulianDate
jul UTCTime -> Diff UTCTime -> UTCTime
forall p. AffineSpace p => p -> Diff p -> p
.+^ TimeZone -> NominalDiffTime
timeZoneOffset TimeZone
tz

        toDayTime :: TimeOfDay -> NominalDiffTime
        toDayTime :: TimeOfDay -> NominalDiffTime
toDayTime (TimeOfDay Int
h Int
m NominalDiffTime
s) = NominalDiffTime
s
            NominalDiffTime -> NominalDiffTime -> NominalDiffTime
forall v. AdditiveGroup v => v -> v -> v
^+^ Int -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
m Scalar NominalDiffTime -> NominalDiffTime -> NominalDiffTime
forall v. VectorSpace v => Scalar v -> v -> v
*^ Micros -> NominalDiffTime
NominalDiffTime Micros
60000000
            NominalDiffTime -> NominalDiffTime -> NominalDiffTime
forall v. AdditiveGroup v => v -> v -> v
^+^ Int -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
h Scalar NominalDiffTime -> NominalDiffTime -> NominalDiffTime
forall v. VectorSpace v => Scalar v -> v -> v
*^ Micros -> NominalDiffTime
NominalDiffTime Micros
3600000000
        {-# INLINEABLE toDayTime #-}
    {-# INLINE buildTime #-}

-- -------------------------------------------------------------------------- --
-- Time Zone Parser

timeZoneParser :: Parser TimeZone
timeZoneParser :: Parser ByteString TimeZone
timeZoneParser = [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"TAI" Int
0 Bool
False Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"UT1" Int
0 Bool
False

    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"ZULU" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
00 Int
00) Bool
False --  Same as UTC
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"Z" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
00 Int
00) Bool
False --  Same as UTC
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"YST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
09 Int
00) Bool
False -- Yukon Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"YDT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
08 Int
00) Bool
True -- Yukon Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"WST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
08 Int
00) Bool
False -- West Australian Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"WETDST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
01 Int
00) Bool
True -- Western European Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"WET" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
00 Int
00) Bool
False --  Western European Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"WDT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
09 Int
00) Bool
True -- West Australian Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"WAT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
01 Int
00) Bool
False -- West Africa Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"WAST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
07 Int
00) Bool
False -- West Australian Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"WADT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
08 Int
00) Bool
True -- West Australian Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"UTC" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
00 Int
00) Bool
False --  Universal Coordinated Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"UT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
00 Int
00) Bool
False --  Universal Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"TFT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
05 Int
00) Bool
False -- Kerguelen Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"SWT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
01 Int
00) Bool
False -- Swedish Winter Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"SST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
02 Int
00) Bool
False -- Swedish Summer Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"SET" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
01 Int
00) Bool
False -- Seychelles Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"SCT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
04 Int
00) Bool
False -- Mahe Island Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"SAST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
09 Int
30) Bool
False -- South Australia Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"SADT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
10 Int
30) Bool
True -- South Australian Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"RET" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
04 Int
00) Bool
False -- Reunion Island Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"PST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
08 Int
00) Bool
False -- Pacific Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"PDT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
07 Int
00) Bool
True -- Pacific Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"NZT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
12 Int
00) Bool
False -- New Zealand Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"NZST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
12 Int
00) Bool
False -- New Zealand Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"NZDT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
13 Int
00) Bool
True -- New Zealand Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"NT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
11 Int
00) Bool
False -- Nome Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"NST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
03 Int
30) Bool
False -- Newfoundland Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"NOR" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
01 Int
00) Bool
False -- Norway Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"NFT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
03 Int
30) Bool
False -- Newfoundland Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"NDT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
02 Int
30) Bool
True -- Newfoundland Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"MVT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
05 Int
00) Bool
False -- Maldives Island Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"MUT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
04 Int
00) Bool
False -- Mauritius Island Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"MT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
08 Int
30) Bool
False -- Moluccas Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"MST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
07 Int
00) Bool
False -- Mountain Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"MMT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
06 Int
30) Bool
False -- Myanmar Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"MHT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
09 Int
00) Bool
False -- Kwajalein Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"MEZ" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
01 Int
00) Bool
False -- Mitteleuropaeische Zeit
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"MEWT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
01 Int
00) Bool
False -- Middle European Winter Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"METDST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
02 Int
00) Bool
True -- Middle Europe Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"MET" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
01 Int
00) Bool
False -- Middle European Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"MEST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
02 Int
00) Bool
False -- Middle European Summer Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"MDT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
06 Int
00) Bool
True -- Mountain Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"MAWT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
06 Int
00) Bool
False -- Mawson (Antarctica) Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"MART" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
09 Int
30) Bool
False -- Marquesas Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"LIGT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
10 Int
00) Bool
False -- Melbourne, Australia
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"KST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
09 Int
00) Bool
False -- Korea Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"JT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
07 Int
30) Bool
False -- Java Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"JST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
09 Int
00) Bool
False -- Japan Standard Time, Russia zone 8
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"IT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
03 Int
30) Bool
False -- Iran Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"IST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
02 Int
00) Bool
False -- Israel Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"IRT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
03 Int
30) Bool
False -- Iran Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"IOT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
05 Int
00) Bool
False -- Indian Chagos Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"IDLW" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
12 Int
00) Bool
False -- International Date Line, West
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"IDLE" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
12 Int
00) Bool
False -- International Date Line, East
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"HST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
10 Int
00) Bool
False -- Hawaii Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"HMT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
03 Int
00) Bool
False -- Hellas Mediterranean Time (?)
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"HDT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
09 Int
00) Bool
True -- Hawaii/Alaska Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"GST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
10 Int
00) Bool
False -- Guam Standard Time, Russia zone 9
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"GMT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
00 Int
00) Bool
False --  Greenwich Mean Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"FWT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
02 Int
00) Bool
False -- French Winter Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"FST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
01 Int
00) Bool
False -- French Summer Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"FNT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
02 Int
00) Bool
False -- Fernando de Noronha Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"FNST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
01 Int
00) Bool
False -- Fernando de Noronha Summer Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"EST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
05 Int
00) Bool
False -- Eastern Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"EETDST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
03 Int
00) Bool
True -- Eastern Europe Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"EET" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
02 Int
00) Bool
False -- Eastern European Time, Russia zone 1
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"EDT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
04 Int
00) Bool
True -- Eastern Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"EAT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
03 Int
00) Bool
False -- Antananarivo, Comoro Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"EAST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
10 Int
00) Bool
False -- East Australian Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"EAST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
04 Int
00) Bool
False -- Antananarivo Summer Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"DNT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
01 Int
00) Bool
False -- Dansk Normal Tid
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"CXT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
07 Int
00) Bool
False -- Christmas (Island) Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"CST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
06 Int
00) Bool
False -- Central Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"CETDST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
02 Int
00) Bool
True -- Central European Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"CET" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
01 Int
00) Bool
False -- Central European Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"CEST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
02 Int
00) Bool
False -- Central European Summer Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"CDT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
05 Int
00) Bool
True -- Central Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"CCT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
08 Int
00) Bool
False -- China Coastal Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"CAT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
10 Int
00) Bool
False -- Central Alaska Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"CAST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
09 Int
30) Bool
False -- Central Australia Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"CADT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
10 Int
30) Bool
True -- Central Australia Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"BT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
03 Int
00) Bool
False -- Baghdad Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"BST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
01 Int
00) Bool
False -- British Summer Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"BRT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
03 Int
00) Bool
False -- Brasilia Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"BRST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
02 Int
00) Bool
False -- Brasilia Summer Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"BDST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
02 Int
00) Bool
False -- British Double Summer Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"AWT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
03 Int
00) Bool
False -- (unknown)
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"AWST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
08 Int
00) Bool
False -- Australia Western Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"AWSST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
09 Int
00) Bool
False -- Australia Western Summer Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"AST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
04 Int
00) Bool
False -- Atlantic Standard Time (Canada)
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"ALMT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
06 Int
00) Bool
False -- Almaty Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"ALMST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
07 Int
00) Bool
False -- Almaty Summer Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"AKST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
09 Int
00) Bool
False -- Alaska Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"AKDT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
08 Int
00) Bool
True -- Alaska Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"AHST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
10 Int
00) Bool
False -- Alaska/Hawaii Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"AFT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
04 Int
30) Bool
False -- Afghanistan Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"AEST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
10 Int
00) Bool
False -- Australia Eastern Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"AESST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
11 Int
00) Bool
False -- Australia Eastern Summer Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"ADT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
03 Int
00) Bool
True -- Atlantic Daylight-Saving Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"ACT" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
05 Int
00) Bool
False -- Atlantic/Porto Acre Standard Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"ACST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($-) Int
04 Int
00) Bool
False -- Atlantic/Porto Acre Summer Time
    Parser ByteString TimeZone
-> Parser ByteString TimeZone -> Parser ByteString TimeZone
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
"ACSST" (Int -> Int -> Int
forall a. Num a => a -> a -> a
($+) Int
10 Int
30) Bool
False -- Central Australia Summer Standard Time
  where
    zone :: [Char] -> Int -> Bool -> Parser ByteString TimeZone
zone [Char]
name Int
offset Bool
dst = Int -> Bool -> [Char] -> TimeZone
TimeZone Int
offset Bool
dst [Char]
name TimeZone
-> Parser ByteString ByteString -> Parser ByteString TimeZone
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ByteString -> Parser ByteString ByteString
P.string ([Char] -> ByteString
S.pack [Char]
name)
    $+ :: a -> a -> a
($+) a
h a
m = a
h a -> a -> a
forall a. Num a => a -> a -> a
* a
60 a -> a -> a
forall a. Num a => a -> a -> a
+ a
m
    $- :: a -> a -> a
($-) a
h a
m = a -> a
forall a. Num a => a -> a
negate (a
h a -> a -> a
forall a. Num a => a -> a -> a
* a
60 a -> a -> a
forall a. Num a => a -> a -> a
+ a
m)

-- -------------------------------------------------------------------------- --
-- Orphan Read Instances

instance Read UTCTime where
    readsPrec :: Int -> ReadS UTCTime
readsPrec Int
_ = Bool -> ReadS UTCTime -> ReadS UTCTime
forall a. Bool -> ReadS a -> ReadS a
readParen Bool
False (ReadS UTCTime -> ReadS UTCTime) -> ReadS UTCTime -> ReadS UTCTime
forall a b. (a -> b) -> a -> b
$
        [Char] -> ReadS UTCTime
forall t. ParseTime t => [Char] -> ReadS t
readsTime [Char]
"%Y-%m-%d %H:%M:%S%Q %Z"
    {-# INLINEABLE readsPrec #-}

-- -------------------------------------------------------------------------- --
-- Orphan Show Instances

instance Show UTCTime where
    showsPrec :: Int -> UTCTime -> ShowS
showsPrec Int
_ = [Char] -> UTCTime -> ShowS
forall t. FormatTime t => [Char] -> t -> ShowS
formatTimeS [Char]
"%Y-%m-%d %H:%M:%S%Q %Z"

instance Show NominalDiffTime where
    showsPrec :: Int -> NominalDiffTime -> ShowS
showsPrec Int
p (NominalDiffTime Micros
a) [Char]
rest = Int -> Micros -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p Micros
a (Char
's' Char -> ShowS
forall a. a -> [a] -> [a]
: [Char]
rest)

-- -------------------------------------------------------------------------- --
-- Orphan Aeson instances

instance ToJSON UTCTime where
    toJSON :: UTCTime -> Value
toJSON UTCTime
t = Text -> Value
String (Text -> Value) -> Text -> Value
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack ([Char] -> Text) -> [Char] -> Text
forall a b. (a -> b) -> a -> b
$ [Char] -> UTCTime -> [Char]
forall t. FormatTime t => [Char] -> t -> [Char]
formatTime [Char]
"%FT%T%QZ" UTCTime
t
    {-# INLINE toJSON #-}

instance FromJSON UTCTime where
    parseJSON :: Value -> Parser UTCTime
parseJSON = [Char] -> (Text -> Parser UTCTime) -> Value -> Parser UTCTime
forall a. [Char] -> (Text -> Parser a) -> Value -> Parser a
withText [Char]
"UTCTime" ((Text -> Parser UTCTime) -> Value -> Parser UTCTime)
-> (Text -> Parser UTCTime) -> Value -> Parser UTCTime
forall a b. (a -> b) -> a -> b
$ \Text
t ->
        case [Char] -> [Char] -> Maybe UTCTime
parseTime [Char]
"%FT%T%QZ" (Text -> [Char]
T.unpack Text
t) of
          Just UTCTime
d -> UTCTime -> Parser UTCTime
forall (f :: * -> *) a. Applicative f => a -> f a
pure UTCTime
d
          Maybe UTCTime
_      -> [Char] -> Parser UTCTime
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"could not parse ISO-8601 date"
    {-# INLINE parseJSON #-}

-- -------------------------------------------------------------------------- --
-- TimeParse Lenses

tpCentury :: Lens' TimeParse Int
tpCentury :: (Int -> f Int) -> TimeParse -> f TimeParse
tpCentury = (TimeParse -> Int)
-> (TimeParse -> Int -> TimeParse) -> Lens' TimeParse Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TimeParse -> Int
_tpCentury (\TimeParse
a Int
b -> TimeParse
a { _tpCentury :: Int
_tpCentury = Int
b })
{-# INLINE tpCentury #-}

tpCenturyYear :: Lens' TimeParse Int
tpCenturyYear :: (Int -> f Int) -> TimeParse -> f TimeParse
tpCenturyYear = (TimeParse -> Int)
-> (TimeParse -> Int -> TimeParse) -> Lens' TimeParse Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TimeParse -> Int
_tpCenturyYear (\TimeParse
a Int
b -> TimeParse
a { _tpCenturyYear :: Int
_tpCenturyYear = Int
b })
{-# INLINE tpCenturyYear #-}

tpMonth :: Lens' TimeParse Int
tpMonth :: (Int -> f Int) -> TimeParse -> f TimeParse
tpMonth = (TimeParse -> Int)
-> (TimeParse -> Int -> TimeParse) -> Lens' TimeParse Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TimeParse -> Int
_tpMonth (\TimeParse
a Int
b -> TimeParse
a { _tpMonth :: Int
_tpMonth = Int
b })
{-# INLINE tpMonth #-}

tpWeekOfYear :: Lens' TimeParse Int
tpWeekOfYear :: (Int -> f Int) -> TimeParse -> f TimeParse
tpWeekOfYear = (TimeParse -> Int)
-> (TimeParse -> Int -> TimeParse) -> Lens' TimeParse Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TimeParse -> Int
_tpWeekOfYear (\TimeParse
a Int
b -> TimeParse
a { _tpWeekOfYear :: Int
_tpWeekOfYear = Int
b })
{-# INLINE tpWeekOfYear #-}

tpDayOfMonth :: Lens' TimeParse Int
tpDayOfMonth :: (Int -> f Int) -> TimeParse -> f TimeParse
tpDayOfMonth = (TimeParse -> Int)
-> (TimeParse -> Int -> TimeParse) -> Lens' TimeParse Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TimeParse -> Int
_tpDayOfMonth (\TimeParse
a Int
b -> TimeParse
a { _tpDayOfMonth :: Int
_tpDayOfMonth = Int
b })
{-# INLINE tpDayOfMonth #-}

tpDayOfYear :: Lens' TimeParse Int
tpDayOfYear :: (Int -> f Int) -> TimeParse -> f TimeParse
tpDayOfYear = (TimeParse -> Int)
-> (TimeParse -> Int -> TimeParse) -> Lens' TimeParse Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TimeParse -> Int
_tpDayOfYear (\TimeParse
a Int
b -> TimeParse
a { _tpDayOfYear :: Int
_tpDayOfYear = Int
b })
{-# INLINE tpDayOfYear #-}

tpDayOfWeek :: Lens' TimeParse Int
tpDayOfWeek :: (Int -> f Int) -> TimeParse -> f TimeParse
tpDayOfWeek = (TimeParse -> Int)
-> (TimeParse -> Int -> TimeParse) -> Lens' TimeParse Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TimeParse -> Int
_tpDayOfWeek (\TimeParse
a Int
b -> TimeParse
a { _tpDayOfWeek :: Int
_tpDayOfWeek = Int
b })
{-# INLINE tpDayOfWeek #-}

tpFlags :: Lens' TimeParse Int
tpFlags :: (Int -> f Int) -> TimeParse -> f TimeParse
tpFlags = (TimeParse -> Int)
-> (TimeParse -> Int -> TimeParse) -> Lens' TimeParse Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TimeParse -> Int
_tpFlags (\TimeParse
a Int
b -> TimeParse
a { _tpFlags :: Int
_tpFlags = Int
b })
{-# INLINE tpFlags #-}

tpHour :: Lens' TimeParse Int
tpHour :: (Int -> f Int) -> TimeParse -> f TimeParse
tpHour = (TimeParse -> Int)
-> (TimeParse -> Int -> TimeParse) -> Lens' TimeParse Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TimeParse -> Int
_tpHour (\TimeParse
a Int
b -> TimeParse
a { _tpHour :: Int
_tpHour = Int
b })
{-# INLINE tpHour #-}

tpMinute :: Lens' TimeParse Int
tpMinute :: (Int -> f Int) -> TimeParse -> f TimeParse
tpMinute = (TimeParse -> Int)
-> (TimeParse -> Int -> TimeParse) -> Lens' TimeParse Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TimeParse -> Int
_tpMinute (\TimeParse
a Int
b -> TimeParse
a { _tpMinute :: Int
_tpMinute = Int
b })
{-# INLINE tpMinute #-}

tpSecond :: Lens' TimeParse Int
tpSecond :: (Int -> f Int) -> TimeParse -> f TimeParse
tpSecond = (TimeParse -> Int)
-> (TimeParse -> Int -> TimeParse) -> Lens' TimeParse Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TimeParse -> Int
_tpSecond (\TimeParse
a Int
b -> TimeParse
a { _tpSecond :: Int
_tpSecond = Int
b })
{-# INLINE tpSecond #-}

tpSecFrac :: Lens' TimeParse NominalDiffTime
tpSecFrac :: (NominalDiffTime -> f NominalDiffTime) -> TimeParse -> f TimeParse
tpSecFrac = (TimeParse -> NominalDiffTime)
-> (TimeParse -> NominalDiffTime -> TimeParse)
-> Lens' TimeParse NominalDiffTime
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TimeParse -> NominalDiffTime
_tpSecFrac (\TimeParse
a NominalDiffTime
b -> TimeParse
a { _tpSecFrac :: NominalDiffTime
_tpSecFrac = NominalDiffTime
b })
{-# INLINE tpSecFrac #-}

tpPOSIXTime :: Lens' TimeParse NominalDiffTime
tpPOSIXTime :: (NominalDiffTime -> f NominalDiffTime) -> TimeParse -> f TimeParse
tpPOSIXTime = (TimeParse -> NominalDiffTime)
-> (TimeParse -> NominalDiffTime -> TimeParse)
-> Lens' TimeParse NominalDiffTime
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TimeParse -> NominalDiffTime
_tpPOSIXTime (\TimeParse
a NominalDiffTime
b -> TimeParse
a { _tpPOSIXTime :: NominalDiffTime
_tpPOSIXTime = NominalDiffTime
b })
{-# INLINE tpPOSIXTime #-}

tpTimeZone :: Lens' TimeParse TimeZone
tpTimeZone :: (TimeZone -> f TimeZone) -> TimeParse -> f TimeParse
tpTimeZone = (TimeParse -> TimeZone)
-> (TimeParse -> TimeZone -> TimeParse) -> Lens' TimeParse TimeZone
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens TimeParse -> TimeZone
_tpTimeZone (\TimeParse
a TimeZone
b -> TimeParse
a { _tpTimeZone :: TimeZone
_tpTimeZone = TimeZone
b })
{-# INLINE tpTimeZone #-}