+-- |This module is for ANSI C's asctime() format.
+--
+-- ANSI C's asctime() format looks like:
+--
+-- @Wdy Mon DD HH:MM:SS YYYY@
+--
+-- The exact syntax is as follows:
+--
+-- > date-time ::= wday ' ' month ' ' day ' ' time ' ' year
+-- > wday ::= "Mon" | "Tue" | "Wed" | "Thu"
+-- > | "Fri" | "Sat" | "Sun"
+-- > month ::= "Jan" | "Feb" | "Mar" | "Apr"
+-- > | "May" | "Jun" | "Jul" | "Aug"
+-- > | "Sep" | "Oct" | "Nov" | "Dec"
+-- > day ::= 2DIGIT
+-- > time ::= 2DIGIT ':' 2DIGIT [':' 2DIGIT]
+-- > year ::= 4DIGIT
+--
+-- As you can see, it has no time zone info. "Data.Time.HTTP" will
+-- treat it as UTC.
module Data.Time.Asctime
( format
, parse
import Data.Time.HTTP.Common
import Data.Time.Asctime.Parsec
-{-
- Wdy Mon DD HH:MM:SS YYYY
--}
-
+-- |Format a 'LocalTime' in the ANSI C's asctime() way.
format :: LocalTime -> String
format localTime
= let (year, month, day) = toGregorian (localDay localTime)
, show4 year
]
+-- |Parse an ANSI C's asctime() format to 'LocalTime'. When the string
+-- can't be parsed, it returns 'Nothing'.
parse :: String -> Maybe LocalTime
parse src = case P.parse p "" src of
Right zt -> Just zt
import Data.Time.HTTP.Common
import Text.Parsec
-
+-- |This is a parsec parser for ANSI C's asctime() format.
asctime :: Stream s m Char => ParsecT s u m LocalTime
asctime = do weekDay <- shortWeekDayNameP
_ <- string ", "