1 -- |This module provides functions for ANSI C's asctime() format.
3 -- ANSI C's asctime() format looks like:
5 -- @Wdy Mon DD HH:MM:SS YYYY@
7 -- The exact syntax is as follows:
9 -- > date-time ::= wday SP month SP day SP time SP year
10 -- > wday ::= "Mon" | "Tue" | "Wed" | "Thu"
11 -- > | "Fri" | "Sat" | "Sun"
12 -- > month ::= "Jan" | "Feb" | "Mar" | "Apr"
13 -- > | "May" | "Jun" | "Jul" | "Aug"
14 -- > | "Sep" | "Oct" | "Nov" | "Dec"
16 -- > time ::= 2DIGIT ':' 2DIGIT [':' 2DIGIT]
19 -- As you can see, it has no time zone info. "Data.Time.HTTP" will
21 module Data.Time.Asctime
27 import qualified Text.Parsec as P
30 import Data.Time.Calendar.WeekDate
31 import Data.Time.HTTP.Common
32 import Data.Time.Asctime.Parsec
34 -- |Format a 'LocalTime' in the ANSI C's asctime() way.
35 format :: LocalTime -> String
37 = let (year, month, day) = toGregorian (localDay localTime)
38 (_, _, week) = toWeekDate (localDay localTime)
39 timeOfDay = localTimeOfDay localTime
41 concat [ shortWeekDayName week
43 , shortMonthName month
47 , show2 (todHour timeOfDay)
49 , show2 (todMin timeOfDay)
51 , show2 (floor (todSec timeOfDay))
56 -- |Parse an ANSI C's asctime() format to 'LocalTime'. When the string
57 -- can't be parsed, it returns 'Nothing'.
58 parse :: String -> Maybe LocalTime
59 parse src = case P.parse p "" src of