X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=time-http.git;a=blobdiff_plain;f=Data%2FTime%2FAsctime.hs;fp=Data%2FTime%2FAsctime.hs;h=7ebb59670f487507255c75f74244fbfc6ddbc5cc;hp=0000000000000000000000000000000000000000;hb=e90df736d33162bb7ade70cb6fe1372a28af62ff;hpb=269a28dfe8b08af854f7217bbe9c141c9c18f1ec diff --git a/Data/Time/Asctime.hs b/Data/Time/Asctime.hs new file mode 100644 index 0000000..7ebb596 --- /dev/null +++ b/Data/Time/Asctime.hs @@ -0,0 +1,46 @@ +module Data.Time.Asctime + ( format + , parse + ) + where + +import qualified Text.Parsec as P + +import Data.Time +import Data.Time.Calendar.WeekDate +import Data.Time.HTTP.Common +import Data.Time.Asctime.Parsec + +{- + Wdy Mon DD HH:MM:SS YYYY +-} + +format :: LocalTime -> String +format localTime + = let (year, month, day) = toGregorian (localDay localTime) + (_, _, week) = toWeekDate (localDay localTime) + timeOfDay = localTimeOfDay localTime + in + concat [ shortWeekDayName week + , ", " + , shortMonthName month + , " " + , show2 day + , " " + , show2 (todHour timeOfDay) + , ":" + , show2 (todMin timeOfDay) + , ":" + , show2 (floor (todSec timeOfDay)) + , " " + , show4 year + ] + +parse :: String -> Maybe LocalTime +parse src = case P.parse p "" src of + Right zt -> Just zt + Left _ -> Nothing + where + p = do zt <- asctime + _ <- P.eof + return zt