bear / parsedatetime

Parse human-readable date/time strings
Apache License 2.0
695 stars 106 forks source link

supporting compositional queries #214

Open anupamme opened 7 years ago

anupamme commented 7 years ago

What currently works is:

last year yesterday

what does not work is:

last to last year day before yesterday

My sense of looking at it is that it does not support compositional queries so far. I would like to contribute so if author can provide little guidance how it can be achieved that would be great.

Thanks

idpaterson commented 7 years ago

Thanks for the request. To be clear, while your examples are accurate some similar forms are supported. For example, 1 day before yesterday or 2 weeks from next Friday will parse how you expect. It seems like at least the day before yesterday or a day before yesterday would be good to support since in other places parsedatetime allows those words in place of the number 1.

I don't think I've ever heard "last to last year," is that a common phrase?

anupamme commented 7 years ago

Okay I just checked

a day before yesterday works, however the day before yesterday and day before yesterday do not.

My thought was to support compositional queries rather than just phrases e.g.

day before yesterday = yesterday - 1 last to last year = last year - 1 last to last to last year = last to last year - 1

Benefit is that it would probably be more scalable.

I think current implementation relies on regex pattern matching but to support compositional queries it would need to move to creating mini-grammars. So probably lot more work.