AnimaSA/Atarashii — pull request #143 by d-sko (2014-03-19 18:56:33+00:00)
Title: Parse dates from MAL

MAL uses some different date formats and as the API is scraping the HTML from MAL, Atarashii has to deal with it :-).
So I created a class which can parse all those date formats and creates Date-Objects of them, which can be used to get the dates formatted in a unique way and to translate them.
The dateformats I noticed on MAL (in data relevant to Atarashii) are:

**fixed dates**:
- yyyy-MM-dd, h:m a
- MM-dd-yy, h:m a
- MMMM dd, yyyy

**relative dates:**
- EEEE, h:m a
- Yesterday, h:m a
- x hours/minutes ago

(see [time pattern syntax](http://developer.android.com/reference/java/text/SimpleDateFormat.html) for explanation of those variables)

The class *MALDateTools* can convert all these date formats and can return them as
- Date-Object
- ISO 8601 date strings (yyyy-MM-dd'T'HH:mm:ssZ)
- formatted date strings (with format definitions from string resources)

Database: all dates which are stored in the database are now stored as ISO 8601 strings. For last online this fixes one issue: currently if the last online date is "4 minutes ago" this string will be saved in the database and it will be also 4 minutes ago if I look at the friendlist or profile tomorrow without resync. By storing a complete date this can be calculated correctly.

The returned date strings are also converted to the time zone of the device. Formatted date strings are also relative if they are not too far in the past:
- for dates which are less than a hour ago: *"x minutes ago"*
- for dates which are less than a day ago: *"x hours ago"*
- for dates which are less than two days ago: *"Yesterday, Time"*
- for dates which are less than five days ago: *"Dayname, Time"*
- everything else will be formatted as *"Date, Time"*

All these formats are defined as resources to make them translatable.

If date parsing fails (that happend never in my tests) everything acts as before: dates are stored and displayed as they are returned by the API.

**Downside:** there is one downside: the date format "x hours ago" can't be parsed exactly, because eg. "5 hours ago" can be 300 to 359 minutes ago. As far as I can tell this format is only used for the last online date so it might be not a big problem.