-- > day ::= 2DIGIT | SP 1DIGIT
-- > time ::= 2DIGIT ':' 2DIGIT [':' 2DIGIT]
-- > year ::= 4DIGIT
-module Data.Time.Format.Asctime
- ( Asctime
- , asctime
+module Data.Time.Format.C
+ ( C
+ , c
+ , cDateAndTime
)
where
import Control.Applicative
import Data.Attoparsec.Char8
import Data.Convertible.Base
import Data.Monoid.Unicode
+import Data.Proxy
import Data.Tagged
import Data.Time
import Data.Time.Calendar.WeekDate
import Prelude.Unicode
-- |The phantom type for conversions between ANSI C's date and time
--- string and 'LocalTime'.
+-- strings and 'LocalTime'.
--
-- >>> convertSuccess (LocalTime (ModifiedJulianDay 49662) (TimeOfDay 8 49 37))
-- Tagged "Sun Nov 6 08:49:37 1994"
-data Asctime
+data C
-instance ConvertSuccess LocalTime (Tagged Asctime Ascii) where
+-- |The proxy for conversions between ANSI C's date and time strings
+-- and 'LocalTime'.
+c ∷ Proxy C
+{-# INLINE CONLIKE c #-}
+c = Proxy
+
+instance ConvertSuccess LocalTime (Tagged C Ascii) where
{-# INLINE convertSuccess #-}
convertSuccess = (A.fromAsciiBuilder <$>) ∘ cs
-instance ConvertSuccess LocalTime (Tagged Asctime AsciiBuilder) where
+instance ConvertSuccess LocalTime (Tagged C AsciiBuilder) where
{-# INLINE convertSuccess #-}
convertSuccess = Tagged ∘ toAsciiBuilder
-instance ConvertAttempt (Tagged Asctime Ascii) LocalTime where
+instance ConvertAttempt (Tagged C Ascii) LocalTime where
{-# INLINE convertAttempt #-}
- convertAttempt = parseAttempt' asctime ∘ untag
+ convertAttempt = parseAttempt' cDateAndTime ∘ untag
-- |Parse an ANSI C's date and time string.
-asctime ∷ Parser LocalTime
-asctime
+cDateAndTime ∷ Parser LocalTime
+cDateAndTime
= do weekDay ← shortWeekDayNameP
_ ← char ' '
month ← shortMonthNameP
⊕ A.toAsciiBuilder " "
⊕ show4 year
-deriveAttempts [ ([t| LocalTime |], [t| Tagged Asctime Ascii |])
- , ([t| LocalTime |], [t| Tagged Asctime AsciiBuilder |])
+deriveAttempts [ ([t| LocalTime |], [t| Tagged C Ascii |])
+ , ([t| LocalTime |], [t| Tagged C AsciiBuilder |])
]