Skip to content

Conversation

@Rutherther
Copy link
Contributor

The current custom regex-based TimeSpanParser doesn't check if there is excessive text in the string. Because of that, even strings like x60sx are 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 -60s means the same as 60s.

This PR aims to change that,

  1. It is checked that there are no excessive characters
  2. Support for negative TimeSpans is implemented (it was already supported by TimeSpan.TryParse when the entered time span was in format parseable by this)

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.

TimeSpanParser currently ignores excess characters in front of or
after the matches. This means unexpected input like x60sx will lead to
a match of 60 s. The same, worse so, goes for - in front of the
TimeSpan.

This commit checks for excess characters, and returns a parsing error.
In addition it implements support for negative time spans. Negative
time spans are already supported in cases where TimeSpan.TryParse
parses the TimeSpan, but not with the custom format.
@Rutherther Rutherther force-pushed the fix/timespanparser branch from f5a893d to 25b740d Compare June 18, 2025 17:09
@Nihlus Nihlus merged commit 21bf4d8 into Remora:main Jun 18, 2025
3 checks passed
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.

2 participants