]> gitweb.michael.orlitzky.com - dead/halcyon.git/blobdiff - src/Twitter/Status.hs
Use the newer Data.Time library.
[dead/halcyon.git] / src / Twitter / Status.hs
index 976ccb31590c134bcaa766cd3d718a4bdf9dd454..01ef0ab04504596881188ebde26373281d42a1a3 100644 (file)
@@ -4,6 +4,8 @@ where
 
 import Data.Maybe
 import Data.String.Utils (join, splitWs)
 
 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
 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 = ""
 
 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
 -- |Returns a nicely-formatted String representing the given 'Status'
 -- object.
 pretty_print :: Status -> String