+import Prelude.Unicode
+
+-- |Convert a 'LocalTime' to ANSI C's @asctime()@ string.
+toAscii ∷ LocalTime → Ascii
+toAscii = A.fromAsciiBuilder ∘ toAsciiBuilder
+
+-- |Parse an ANSI C's @asctime()@ string. When the string can't be
+-- parsed, it returns @'Left' err@.
+fromAscii ∷ Ascii → Either String LocalTime
+fromAscii = parseOnly p ∘ A.toByteString
+ where
+ p = do zt ← asctime
+ endOfInput
+ return zt
+
+-- |Parse an ANSI C's @asctime()@ string.
+asctime ∷ Parser LocalTime
+asctime = do weekDay ← shortWeekDayNameP
+ _ ← char ' '
+ month ← shortMonthNameP
+ _ ← char ' '
+ day ← read2'
+ _ ← char ' '
+ hour ← read2
+ _ ← char ':'
+ minute ← read2
+ _ ← char ':'
+ second ← read2
+ _ ← char ' '
+ year ← read4
+
+ gregDay ← assertGregorianDateIsGood year month day
+ _ ← assertWeekDayIsGood weekDay gregDay
+ tod ← assertTimeOfDayIsGood hour minute second