TimeSpanParser unintuitive edge cases #30
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current custom regex-based TimeSpanParser doesn't check if there is excessive text in the string. Because of that, even strings like
x60sxare matched properly, x'es being ignored. Even worse so, this also goes for-sign in front of the TimeSpan specification. This can lead to confusion as-60smeans the same as60s.This PR aims to change that,
Tbh I don't really understand the group matches, I tried multiple approaches that didn't work, mostly based on matching the whole string rather than matching just the individual parts, but I couldn't get it to match the groups. I ended up with a solution with a few changes from the current one. The change I dislike the most is that lookahead is removed, and instead the last character is trimmed in the foreach for matching groups. For months two characters are trimmed. This works, but if you have better ideas on how to implement it, I welcome that.