{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Data.Time.RFC822 (
formatTimeRFC822, parseTimeRFC822
) where
import Control.Applicative
import Data.Maybe
import Data.Monoid ((<>))
import Data.Monoid.Textual hiding (foldr, map)
import Data.String (fromString)
import Data.Text (Text)
import Data.Time.Calendar
import Data.Time.Format
import Data.Time.LocalTime
import Data.Time.Util
formatTimeRFC822 :: (TextualMonoid t) => ZonedTime -> t
formatTimeRFC822 :: ZonedTime -> t
formatTimeRFC822 ZonedTime
zonedTime = String -> t
forall a. IsString a => String -> a
fromString (String -> t) -> String -> t
forall a b. (a -> b) -> a -> b
$ TimeLocale -> String -> ZonedTime -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale String
"%a, %d %b %Y %X %z" ZonedTime
zonedTime
formatsRFC822 :: [Text]
formatsRFC822 :: [Text]
formatsRFC822 = do
Text
day <- [Text
"%a, ", Text
""]
Text
year <- [Text
"%y", Text
"%Y"]
Text
time <- [Text
"%X", Text
"%H:%M"]
Text
zone <- [Text
"%z", Text
"%Z"]
Text -> [Text]
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$ Text
day Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"%e %b " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
year Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
time Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
zone
parseTimeRFC822 :: (TextualMonoid t) => t -> Maybe ZonedTime
parseTimeRFC822 :: t -> Maybe ZonedTime
parseTimeRFC822 = [Text] -> t -> Maybe ZonedTime
forall t t' time.
(TextualMonoid t, TextualMonoid t', ParseTime time) =>
[t] -> t' -> Maybe time
parseTimeUsing [Text]
formatsRFC822