Browsing directories by type 'date' returns incorrect names when format is not YYYY-MM-DD
As reported in https://github.com/mopidy/mopidy-mpd/issues/31, when browsing by 'Release Years' (or any local:directory query with type=date), tracks with their date tag not in the format YYYY-MM-DD are not displayed correctly.
- Legitimate dates in format YYYY are returned with name '-470'
- Any non-null values that cannot be converted by
strftimeare returned without a name
One way to fix this would be to only insert valid YYYY-MM-DD format SQLite time strings when adding tracks to the database. Then strftime can always handle the value.
Maybe it's not necessary to rely on SQLite's parsing function and just do (if the format is %Y):
SELECT DISTINCT substr(date, 1, 4) AS date
FROM track
WHERE date IS NOT NULL
ORDER BY date
One could do this with a check for %Y in https://github.com/mopidy/mopidy-local/blob/master/mopidy_local/schema.py#L233 to not break anything.
Am I correct in understanding that there are two cases to be expected, format is %Y or %Y-%m-%d (at least that's what i find in my files) and SQLite should actually work only with a full ISO date, so that's why inserting a full date when adding tracks is an option?
I am running the fix proposed by @schmaller and AFAICT it works. Any plan to merge this?