parse-human-relative-time icon indicating copy to clipboard operation
parse-human-relative-time copied to clipboard

parse "last week"

Open binarykitchen opened this issue 3 years ago • 6 comments

How can we parse "last week" with this library best?

I mean, point to beginning of last week best. Pick "last Monday" instead?

binarykitchen avatar Feb 24 '22 23:02 binarykitchen

We'll have to extend the grammar, the Luxon implementation and the date-fns implementation.

derhuerst avatar Mar 15 '22 20:03 derhuerst

@derhuerst do you think you could add that?

binarykitchen avatar Apr 11 '22 01:04 binarykitchen

Or give at least some clues where to start, and I can try.

binarykitchen avatar Apr 11 '22 04:04 binarykitchen

@derhuerst do you think you could add that?

I currently have other priorities.

Or give at least some clues where to start, and I can try.

As I mentioned above, the grammar will have to be adapted, in order to parse the new syntax "last week".

Then, the code applying the parsed result to a DateTime (Luxon adapter) or Date (date-fns adapter), respectively, needs to be extended to handle the new cases.

derhuerst avatar Apr 11 '22 09:04 derhuerst

Totally respect your priorities.

Cloned your repo yesterday and my first attempts failed. My idea was to have last week to return the first day of the last week.

But then I realised I can implement the last week date range with the following workaround:

const lastMonday = parseHumanRelative("last monday");
const lastSunday = parseHumanRelative("last sunday");

// then combine both and so on...

Guess for now can live with that.

binarykitchen avatar Apr 11 '22 21:04 binarykitchen

But yeah, now I am stuck with “last month” as there is no workaround like the above: https://github.com/derhuerst/parse-human-relative-time/issues/6

binarykitchen avatar Apr 11 '22 23:04 binarykitchen