humantime icon indicating copy to clipboard operation
humantime copied to clipboard

regex for supported inputs

Open danieleades opened this issue 2 years ago • 2 comments

is there a regex that can be used to check whether the provided string is in a format that can be parsed by this library?

for the purposes of using in a jsonschema

danieleades avatar Nov 02 '23 14:11 danieleades

For durations, here's what I came up with (newlines for clarity, remove them from the final regex):

(?:\d+\s*(?:years|year|y))?\s*
(?:\d+\s*(?:months|month|M))?\s*
(?:\d+\s*(?:weeks|week|w))?\s*
(?:\d+\s*(?:hours|hour|hr|hrs|h))?\s*
(?:\d+\s*(?:minutes|minute|min|mins|m))?\s*
(?:\d+\s*(?:seconds|second|sec|secs|s))?\s*
(?:\d+\s*(?:millis|msec|ms))?\s*
(?:\d+\s*(?:usec|us))?\s*
(?:\d+\s*(?:nanos|nsec|ns))?\s*

This isn't perfect, though, because it doesn't reject empty strings.

sunshowers avatar Aug 12 '24 01:08 sunshowers

Ideally the regex would be a constant exported by the library itself.

I wonder if the maintainers would be open to a PR?

danieleades avatar Aug 15 '24 07:08 danieleades