]> gitweb.michael.orlitzky.com - dead/halcyon.git/blobdiff - src/Twitter/Status.hs
Add two functions to get the "retweeted" and "in_reply_to_status_id" element text.
[dead/halcyon.git] / src / Twitter / Status.hs
index e40bc6a6a718aa4b68e62902125859b128fc91ad..01ef0ab04504596881188ebde26373281d42a1a3 100644 (file)
@@ -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)