X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=time-http.git;a=blobdiff_plain;f=Data%2FTime%2FFormat%2FC.hs;fp=Data%2FTime%2FFormat%2FC.hs;h=ba9fee881198afd04aba614238ec38da983daf61;hp=0c204d5d387177c01e51023dca6e5723e4f48441;hb=e8f778a92c4aa7c7606bb1b17dada43639543509;hpb=9e1f758b33355286df79648ffcf1f73cb414b5d9 diff --git a/Data/Time/Format/C.hs b/Data/Time/Format/C.hs index 0c204d5..ba9fee8 100644 --- a/Data/Time/Format/C.hs +++ b/Data/Time/Format/C.hs @@ -3,6 +3,7 @@ , MultiParamTypeClasses , OverloadedStrings , TemplateHaskell + , TypeSynonymInstances , UnicodeSyntax #-} -- |This module provides functions for ANSI C's date and time strings. @@ -24,17 +25,14 @@ -- > year ::= 4DIGIT module Data.Time.Format.C ( C - , c - , cDateAndTime ) where -import Control.Applicative import Data.Ascii (Ascii, AsciiBuilder) import qualified Data.Ascii as A import Data.Attoparsec.Char8 import Data.Convertible.Base +import Data.Default import Data.Monoid.Unicode -import Data.Proxy import Data.Tagged import Data.Time import Data.Time.Calendar.WeekDate @@ -44,50 +42,44 @@ import Prelude.Unicode -- |The phantom type for conversions between ANSI C's date and time -- strings and 'LocalTime'. -- --- >>> convertSuccess (LocalTime (ModifiedJulianDay 49662) (TimeOfDay 8 49 37)) --- Tagged "Sun Nov 6 08:49:37 1994" +-- >>> convertSuccess (Tagged (LocalTime (ModifiedJulianDay 49662) (TimeOfDay 8 49 37)) :: Tagged C LocalTime) +-- "Sun Nov 6 08:49:37 1994" data C --- |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 +instance ConvertSuccess (Tagged C LocalTime) Ascii where {-# INLINE convertSuccess #-} - convertSuccess = (A.fromAsciiBuilder <$>) ∘ cs + convertSuccess = A.fromAsciiBuilder ∘ cs -instance ConvertSuccess LocalTime (Tagged C AsciiBuilder) where +instance ConvertSuccess (Tagged C LocalTime) AsciiBuilder where {-# INLINE convertSuccess #-} - convertSuccess = Tagged ∘ toAsciiBuilder + convertSuccess = toAsciiBuilder ∘ untag -instance ConvertAttempt (Tagged C Ascii) LocalTime where +instance ConvertAttempt Ascii (Tagged C LocalTime) where {-# INLINE convertAttempt #-} - convertAttempt = parseAttempt' cDateAndTime ∘ untag + convertAttempt = parseAttempt' def -- |Parse an ANSI C's date and time string. -cDateAndTime ∷ Parser LocalTime -cDateAndTime - = do weekDay ← shortWeekDayNameP - _ ← char ' ' - month ← shortMonthNameP - _ ← char ' ' - day ← read2' - _ ← char ' ' - hour ← read2 - _ ← char ':' - minute ← read2 - _ ← char ':' - second ← read2 - _ ← char ' ' - year ← read4 +instance Default (Parser (Tagged C LocalTime)) where + {-# INLINEABLE def #-} + def = do weekDay ← shortWeekDayNameP + _ ← char ' ' + month ← shortMonthNameP + _ ← char ' ' + day ← read2' + _ ← char ' ' + hour ← read2 + _ ← char ':' + minute ← read2 + _ ← char ':' + second ← read2 + _ ← char ' ' + year ← read4 - gregDay ← assertGregorianDateIsGood year month day - _ ← assertWeekDayIsGood weekDay gregDay - tod ← assertTimeOfDayIsGood hour minute second + gregDay ← assertGregorianDateIsGood year month day + _ ← assertWeekDayIsGood weekDay gregDay + tod ← assertTimeOfDayIsGood hour minute second - return (LocalTime gregDay tod) + return ∘ Tagged $ LocalTime gregDay tod toAsciiBuilder ∷ LocalTime → AsciiBuilder toAsciiBuilder localTime @@ -109,6 +101,6 @@ toAsciiBuilder localTime ⊕ A.toAsciiBuilder " " ⊕ show4 year -deriveAttempts [ ([t| LocalTime |], [t| Tagged C Ascii |]) - , ([t| LocalTime |], [t| Tagged C AsciiBuilder |]) +deriveAttempts [ ([t| Tagged C LocalTime |], [t| Ascii |]) + , ([t| Tagged C LocalTime |], [t| AsciiBuilder |]) ]