]> gitweb @ CieloNegro.org - time-http.git/blob - Data/Time/Asctime.hs
Asctime
[time-http.git] / Data / Time / Asctime.hs
1 module Data.Time.Asctime
2     ( format
3     , parse
4     )
5     where
6
7 import qualified Text.Parsec as P
8
9 import Data.Time
10 import Data.Time.Calendar.WeekDate
11 import Data.Time.HTTP.Common
12 import Data.Time.Asctime.Parsec
13
14 {-
15   Wdy Mon DD HH:MM:SS YYYY
16 -}
17
18 format :: LocalTime -> String
19 format localTime
20     = let (year, month, day) = toGregorian (localDay localTime)
21           (_, _, week)       = toWeekDate  (localDay localTime)
22           timeOfDay          = localTimeOfDay localTime
23       in
24         concat [ shortWeekDayName week
25                , ", "
26                , shortMonthName month
27                , " "
28                , show2 day
29                , " "
30                , show2 (todHour timeOfDay)
31                , ":"
32                , show2 (todMin timeOfDay)
33                , ":"
34                , show2 (floor (todSec timeOfDay))
35                , " "
36                , show4 year
37                ]
38
39 parse :: String -> Maybe LocalTime
40 parse src = case P.parse p "" src of
41               Right zt -> Just zt
42               Left  _  -> Nothing
43     where
44       p = do zt <- asctime
45              _  <- P.eof
46              return zt