--- |Takes an XML String as an argument, and returns the list of
--- statuses that can be parsed from it.
-parse_statuses :: String -> [Status]
-parse_statuses xml_data =
- catMaybes maybe_statuses
- where
- (Document _ _ root _) = xmlParse xml_file_name xml_data
- root_elem = CElem root noPos
- status_elements = (all_statuses root_elem)
- maybe_statuses = map status_from_content status_elements
-
-
--- |This is a required parameter to the xmlParse function used in
--- error reporting. We're not parsing a function, though, so we leave
--- it blank.
-xml_file_name :: String
-xml_file_name = ""
-
--- |Returns a nicely-formatted String representing the given 'Status'
--- object.
-pretty_print :: Status -> String
-pretty_print status =
- concat [ name,
- " - ",
- (created_at status),
- "\n",
- replicate ((length name) + 3 + (length (created_at status))) '-',
- "\n",
- replace_entities (text status),
- "\n\n",
- join "\n" user_timeline_urls,
- "\n" ]
- where
- name = screen_name (user status)
- user_timeline_urls = listify (make_user_timeline_urls status)
-
-
--- |Given a list of statuses, returns the greatest status_id belonging
--- to one of the statuses in the list.
-get_max_status_id :: [Status] -> Integer
+ -- Do whatever.
+ parseJSON _ = mempty
+
+
+-- | Parse a timestamp from a status into a UTCTime (or Nothing).
+--
+-- Examples:
+--
+-- >>> let s = "Sun Oct 24 18:21:41 +0000 2010"
+-- >>> parse_status_time s
+-- Just 2010-10-24 18:21:41 UTC
+--
+-- >>> parse_status_time "what's up dawg"
+-- Nothing
+--
+parse_status_time :: String -> Maybe UTCTime
+parse_status_time =
+ parseTime defaultTimeLocale status_format
+ where
+ status_format :: String
+ status_format = "%a %b %d %H:%M:%S %z %Y"
+
+
+-- | Given a 'TimeZone', convert a 'UTCTime' into an RFC822-format
+-- time string. If no 'TimeZone' is given, assume UTC.
+--
+-- Examples:
+--
+-- >>> let s = "Sun Oct 24 18:21:41 +0000 2010"
+-- >>> let Just t = parse_status_time s
+-- >>> utc_time_to_rfc822 Nothing t
+-- "Sun, 24 Oct 2010 18:21:41 UTC"
+--
+utc_time_to_rfc822 :: Maybe TimeZone -> UTCTime -> String
+utc_time_to_rfc822 mtz utc =
+ case mtz of
+ Nothing -> foo utc
+ Just tz -> foo $ utcToZonedTime tz utc
+ where
+ foo = formatTime defaultTimeLocale rfc822DateFormat
+
+
+-- | Get the 'created_at' time out of a 'Status' and display it as an
+-- RFC822-format time string. If there's no created-at time in the
+-- status, you'll get an empty string instead.
+--
+-- >>> let u = User "washington_irving"
+-- >>> let created = parse_status_time "Sun Oct 24 18:21:41 +0000 2010"
+-- >>> let s = Status created 8675309 False False "IM TWITTERING" u
+-- >>> show_created_at Nothing s
+-- "Sun, 24 Oct 2010 18:21:41 UTC"
+-- >>> show_created_at Nothing s{ created_at = Nothing }
+-- ""
+--
+show_created_at :: Maybe TimeZone -> Status -> String
+show_created_at mtz =
+ (maybe "" (utc_time_to_rfc822 mtz)) . created_at
+
+
+-- | Returns a nicely-formatted String representing the given 'Status'
+-- object.
+--
+-- Examples:
+--
+-- >>> let u = User "washington_irving"
+-- >>> let created = parse_status_time "Sun Oct 24 18:21:41 +0000 2010"
+-- >>> let s = Status created 8675309 False False "IM TWITTERING" u
+-- >>> putStr $ pretty_print Nothing s
+-- washington_irving - Sun, 24 Oct 2010 18:21:41 UTC
+-- -------------------------------------------------
+-- IM TWITTERING
+-- <BLANKLINE>
+-- <BLANKLINE>
+--
+pretty_print :: Maybe TimeZone -> Status -> String
+pretty_print mtz status =
+ concat [ name,
+ " - ",
+ sca,
+ "\n",
+ replicate bar_length '-',
+ "\n",
+ text status,
+ "\n\n",
+ join "\n" user_timeline_urls,
+ "\n" ]
+ where
+ sca = show_created_at mtz status
+ name = screen_name (user status)
+ user_timeline_urls = listify (make_user_timeline_urls status)
+ bar_length = (length name) + 3 + (length sca)
+
+
+-- | Given a list of statuses, returns the greatest status_id
+-- belonging to one of the statuses in the list.
+--
+-- Examples:
+--
+-- >>> let u = User "washington_irving"
+-- >>> let created = parse_status_time "Sun Oct 24 18:21:41 +0000 2010"
+-- >>> let s = Status created 8675309 False False "IM TWITTERING" u
+-- >>> let timeline = [s,s,s,s,s]
+-- >>> get_max_status_id timeline
+-- 8675309
+--
+get_max_status_id :: Timeline -> Integer