X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fhalcyon.git;a=blobdiff_plain;f=src%2FTwitter%2FStatus.hs;h=01ef0ab04504596881188ebde26373281d42a1a3;hp=976ccb31590c134bcaa766cd3d718a4bdf9dd454;hb=230072d26d55aed92737308aa04ce8a0daa0b71a;hpb=ef7a19a9d1a51bb31e98321fed395c8f41c16c28 diff --git a/src/Twitter/Status.hs b/src/Twitter/Status.hs index 976ccb3..01ef0ab 100644 --- a/src/Twitter/Status.hs +++ b/src/Twitter/Status.hs @@ -4,6 +4,8 @@ where import Data.Maybe import Data.String.Utils (join, splitWs) +import Data.Time (ZonedTime, formatTime, readsTime) +import System.Locale (defaultTimeLocale, rfc822DateFormat) import Test.HUnit import Text.Regex (matchRegex, mkRegex) import Text.XML.HaXml @@ -91,6 +93,21 @@ parse_statuses xml_data = xml_file_name :: String xml_file_name = "" + +created_at_to_rfc822 :: String -> Maybe String +created_at_to_rfc822 s = + case reads_result of + [(t,_)] -> + Just $ formatTime defaultTimeLocale rfc822DateFormat t + _ -> Nothing + where + -- Should match e.g. "Sun Oct 24 18:21:41 +0000 2010" + fmt :: String + fmt = "%a %b %d %H:%M:%S %z %Y" + + reads_result :: [(ZonedTime, String)] + reads_result = readsTime defaultTimeLocale fmt s + -- |Returns a nicely-formatted String representing the given 'Status' -- object. pretty_print :: Status -> String