Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept next tuesday +10 days #536

Closed
HendrikJan opened this issue Sep 29, 2023 · 4 comments
Closed

Accept next tuesday +10 days #536

HendrikJan opened this issue Sep 29, 2023 · 4 comments

Comments

@HendrikJan
Copy link
Contributor

HendrikJan commented Sep 29, 2023

I have a combined PHP and Javascript application.

Currently PHP supports "next tuesday +10 days" or variations on that (using strtotime).
It seems that chrono does not, unless I am missing something.

Chrono supports "+10 days" or "next tuesday", but not the combinations of the two.

A workaround for me is currently this:

// Read a PHP date like "next tuesday +1 day"
function readPHPDate(dateStr) {
  const match = dateStr.match(/(.*)([+-].*)/);

  if (match) {
    // Get the chrono +days
    const date = chrono.parseDate(match[1]);
    // Return result as string
    const offset = chrono.parseDate(match[2], date);
    // Get the chrono date
    return offset;
  }

  return chrono.parseDate(dateStr);
}
@wanasit
Copy link
Owner

wanasit commented Nov 11, 2023

Hello.

Chrono supports "X before/after Y" (e.g. "10 days after next Friday") in ENMergeRelativeDateRefiner.ts. It is possible to extend the module to support your case.

I can work on it when I have more free time, but also feel free to submit a PR.

@HendrikJan
Copy link
Contributor Author

I've looked into the code.
Since the new relative time "+10 days" comes after the absolute date ("today +10 days"), while the existing code handles the situation where it comes before ("10 days before today"), it is not a trivial change.
If you are willing and have time to look into this, I would appreciate it.

@wanasit
Copy link
Owner

wanasit commented Dec 30, 2023

Added in fed9f9d.

@wanasit wanasit closed this as completed Dec 30, 2023
@HendrikJan
Copy link
Contributor Author

Many thanks for this improvement 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants