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