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 Data.Time.Calendar.WeekDate
28 import Data.Time.HTTP.Common
29 import Data.Time.Asctime.Internal
31 -- |Format a 'LocalTime' in the ANSI C's asctime() way.
32 format :: LocalTime -> String
34 = let (year, month, day) = toGregorian (localDay localTime)
35 (_, _, week) = toWeekDate (localDay localTime)
36 timeOfDay = localTimeOfDay localTime
38 concat [ shortWeekDayName week
40 , shortMonthName month
44 , show2 (todHour timeOfDay)
46 , show2 (todMin timeOfDay)
48 , show2 (floor (todSec timeOfDay))
53 -- |Parse an ANSI C's asctime() format to 'LocalTime'. When the string
54 -- can't be parsed, it returns 'Nothing'.
55 parse :: String -> Maybe LocalTime
56 parse src = case P.parse p "" src of