X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTwitter%2FStatus.hs;h=01ef0ab04504596881188ebde26373281d42a1a3;hb=636deff8c41fd640cc2945eae1d7b51432527a6a;hp=e40bc6a6a718aa4b68e62902125859b128fc91ad;hpb=606371fece618f28d3fedf182165ef3a56bf4159;p=dead%2Fhalcyon.git diff --git a/src/Twitter/Status.hs b/src/Twitter/Status.hs index e40bc6a..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 @@ -131,7 +148,7 @@ parse_username word = matches = matchRegex username_regex word --- |Parse all usernames of the form @username from a status. +-- |Parse all usernames of the form \@username from a status. parse_usernames_from_status :: Status -> [String] parse_usernames_from_status status = catMaybes (map parse_username status_words)