qBittorrent
qBittorrent copied to clipboard
Search: Added parse_date helper
This PR proposes adding a parse_date helper for search engines. parse_date is a function that understands many human-readable date formats, standard date formats, and relative date formats. It doesn't even attempt to parse ambiguous formats like md/dd/yy dd/mm/yy yy/mm/dd but it can try a user-provided format if it is known.
Some examples:
- 12 June 2024
- June 12, 2024
- 2024-01-01 10:10
- 2024.01.01
- 10 days ago
- last year
- yesterday
- today
- 01/01/24 (if custom format provided)
Currently each search plugin do its own date parsing. This isn't terribly difficult to implement, and in fact it might be preferable because parse_date can't possibly cover all formats out there. But on the other hand, providing a helper might encourage third party authors to add date support to their plugin.
So I wanted to have your opinion as to whether or not adding something like parse_date might be desirable. If so, I will continue the work to make sure that this function can handle all formats required by official plugins (as of now it covers most of them).
So I wanted to have your opinion as to whether or not adding something like parse_date might be desirable. If so, I will continue the work to make sure that this function can handle all formats required by official plugins (as of now it covers most of them).
I would prefer that plugins handle the parsing themselves. Like you said, it seems impossible to have a function that can cover all cases.
What if some website updated the format and parse_date helper didn't cover it? The affected plugin would require an update in any case and the generic helper function become less useful (and slowly a burden to maintain).
But on the other hand, providing a helper might encourage third party authors to add date support to their plugin.
It might, assuming we are talking about websites that are using either English or ISO dates. For websites that are using other languages or localized date strings, the plugin still has to do the parsing themselves.
Thanks for the reply, that's what I figured.