, TemplateHaskell
, UnicodeSyntax
#-}
--- |This module provides functions for ANSI C's asctime() format.
+-- |This module provides functions for ANSI C's date and time strings.
--
--- ANSI C's asctime() format looks like:
+-- ANSI C's @ctime(3)@/@asctime(3)@ format looks like:
--
-- @Wdy Mon [D]D HH:MM:SS YYYY@
--
-- > day ::= 2DIGIT | SP 1DIGIT
-- > time ::= 2DIGIT ':' 2DIGIT [':' 2DIGIT]
-- > year ::= 4DIGIT
---
--- As you can see, it has no time zone info. "Data.Time.HTTP" will
--- treat it as UTC.
-module Data.Time.Asctime
+module Data.Time.Format.Asctime
( Asctime
, asctime
)
import Data.Tagged
import Data.Time
import Data.Time.Calendar.WeekDate
-import Data.Time.HTTP.Common
+import Data.Time.Format.HTTP.Common
import Prelude.Unicode
--- |The phantom type for conversion between ANSI C's @asctime()@
+-- |The phantom type for conversions between ANSI C's date and time
-- string and 'LocalTime'.
--
-- >>> convertSuccess (LocalTime (ModifiedJulianDay 49662) (TimeOfDay 8 49 37))
{-# INLINE convertAttempt #-}
convertAttempt = parseAttempt' asctime ∘ untag
--- |Parse an ANSI C's @asctime()@ string.
+-- |Parse an ANSI C's date and time 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
+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
+ gregDay ← assertGregorianDateIsGood year month day
+ _ ← assertWeekDayIsGood weekDay gregDay
+ tod ← assertTimeOfDayIsGood hour minute second
- return (LocalTime gregDay tod)
+ return (LocalTime gregDay tod)
toAsciiBuilder ∷ LocalTime → AsciiBuilder
toAsciiBuilder localTime