humantime
humantime copied to clipboard
regex for supported inputs
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
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.
Ideally the regex would be a constant exported by the library itself.
I wonder if the maintainers would be open to a PR?