Page 1 of 1

Automatically detect date format and require a date

PostPosted: Fri Dec 29, 2023 6:21 am
by jandamm
I've got an issue where I want to find the first date in a document and the format can vary a lot.
So I use `content contain match` with a date and use the default which searches for "any" date format.

This works fine most of the time but I've got a few files where it always matches the current date.
I found the issue to be that there was a `9:00-15:00` before the correct date. It seems that Hazel matches the `9:00` as a date and according to the documentation it uses the current date as default. When testing the rule the date was `today 9:00`.

I'd love to have two additional checkboxes when `Automatically detect date format` is selected. `Require date` and `Require time`. By default both would be off which is the current behavior.
With `Require date` it would match `1.1.23` and `1.1.23 9:00` but not `9:00` since there is no date but only a time.
With `Require time` it would match `9:00` and `1.1.23 9:00` but not `1.1.23` since there is no time but only a date.
With both options it would match `1.1.23 9:00` but not `1.1.23` or `9:00` since there is only either time or date.

Re: Automatically detect date format and require a date

PostPosted: Fri Dec 29, 2023 9:50 am
by Mr_Noodle
Thanks for the suggestion. Unfortunately, the automatic date detection is based on Apple's data detector system which doesn't allow ways to specify that. I've submitted bug reports for improvements but of course, nothing has been done about it. For this to change, I would probably have to implement my own date detector.

Re: Automatically detect date format and require a date

PostPosted: Fri Dec 29, 2023 7:35 pm
by jandamm
Thanks for the reply.
I didn't know that the matcher comes from Apple.
I think it'd be a nice feature but reimplementing the matcher with all its date quirks and localization isn't easy.