5 -- |Internal functions for "Data.Time.Asctime".
6 module Data.Time.Asctime.Internal
11 import Data.Ascii (AsciiBuilder)
12 import qualified Data.Ascii as A
13 import Data.Attoparsec.Char8
14 import Data.Monoid.Unicode
16 import Data.Time.Calendar.WeekDate
17 import Data.Time.HTTP.Common
19 -- |Parse an ANSI C's @asctime()@ string.
20 asctime ∷ Parser LocalTime
21 asctime = do weekDay ← shortWeekDayNameP
23 month ← shortMonthNameP
35 gregDay ← assertGregorianDateIsGood year month day
36 _ ← assertWeekDayIsGood weekDay gregDay
37 tod ← assertTimeOfDayIsGood hour minute second
39 return (LocalTime gregDay tod)
41 -- |Convert a 'LocalTime' to ANSI C's @asctime()@ string.
42 toAsciiBuilder ∷ LocalTime → AsciiBuilder
43 toAsciiBuilder localTime
44 = let (year, month, day) = toGregorian (localDay localTime)
45 (_, _, week) = toWeekDate (localDay localTime)
46 timeOfDay = localTimeOfDay localTime
49 ⊕ A.toAsciiBuilder " "
50 ⊕ shortMonthName month
51 ⊕ A.toAsciiBuilder " "
53 ⊕ A.toAsciiBuilder " "
54 ⊕ show2 (todHour timeOfDay)
55 ⊕ A.toAsciiBuilder ":"
56 ⊕ show2 (todMin timeOfDay)
57 ⊕ A.toAsciiBuilder ":"
58 ⊕ show2 (floor (todSec timeOfDay) ∷ Int)
59 ⊕ A.toAsciiBuilder " "