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

[EN] Fix for multiple time units within parser (e.g. set a timer for 5 minutes and 30 seconds) #542

Closed
wants to merge 2 commits into from

Conversation

trothe
Copy link

@trothe trothe commented Dec 20, 2023

I ran into issues with phrases like "for 5 minutes AND 30 seconds". It seems the regex didn't capture the second time unit. I updated the regex to capture multiple time units in ENTimeUnitWithinFormatParser. I also added a test case. I hope this is acceptable. If not let me know.

@coveralls
Copy link

coveralls commented Dec 20, 2023

Coverage Status

coverage: 91.337% (+0.005%) from 91.332%
when pulling 0425219 on trothe:en-time-within
into f00e9ef on wanasit:master.

expect(result.start).toBeDate(new Date(2012, 7, 10, 12, 19, 30));
});

testSingleCase(chrono, "set a timer for 10 minutes and 10 seconds", new Date(2012, 7, 10, 12, 14), { forwardDate: true }, (result) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also test a combination of both comma + and e.g. "1 hour, 10 minutes, and 10 seconds".

Copy link
Owner

@wanasit wanasit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @trothe. Thanks for your improvement!

However, I think adding the connection word in the parser pattern is not the best way to fix the problem (e.g. we also want to support other parsers e.g. "5 minutes AND 30 seconds ago"). Instead, we should fix the TIME_UNIT_PATTERN in constants.ts.

I would:

  • Update repeatedTimeunitPattern to take a connector as a parameter (with the current pattern as default).
  • For English constant, we use the current pattern plus your new connector.

Sorry if my request is too difficult.

@wanasit
Copy link
Owner

wanasit commented Jan 20, 2024

Hello @trothe! Thanks again for the improvement.
I incorporated your change in d1a71c9.

@wanasit wanasit closed this Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants