TShock icon indicating copy to clipboard operation
TShock copied to clipboard

More robust parsing of large timespans (Fixes #2625)

Open punchready opened this issue 2 years ago • 6 comments

Added a robust parsing method for positive timespans using an ulong. Commands that parse timespans now support up to 9999999 days. The old method must stay unmodified for compatibility, other plugins can upgrade manually if needed.

Fixes #2625

punchready avatar May 08 '22 08:05 punchready

Hey! Thanks so much for actioning this so quickly. 👍

JordanDi123 avatar May 08 '22 16:05 JordanDi123

Could probably update the existing TryParseTime(string, int) to call TryParseTime(string, long) and reduce code duplication, but I'm not overly fussed :)

the other method should stay to allow negative time spans imo, for whomever may need it.

punchready avatar May 10 '22 10:05 punchready

Also, I just noticed, I think a second method is unnecessary. You could fit 24855 days 3 hours 14 minutes and 7 seconds worth of seconds into the positive bounds of a 32-bit signed integer, casting the seconds to ulong before multiplying to turn it into milliseconds should be enough

Arthri avatar May 10 '22 10:05 Arthri

The method still also ensures that the time span is positive, which is probably wanted in most cases. The issue in /tempgroup is already fixed by simply multiplying by 1000d which causes the seconds to be casted to double anyways (if my understanding is correct), considering that the timer class wants a double in any case.

punchready avatar May 10 '22 10:05 punchready

Looks good to me :+1:

Arthri avatar May 10 '22 10:05 Arthri

Although now that i think of it, i forgot about some edge cases, like 1s-10d+11d...

punchready avatar May 10 '22 10:05 punchready

@punchready

Although now that i think of it, i forgot about some edge cases, like 1s-10d+11d...

Were you planning on fixing those edge cases?

hakusaro avatar Oct 06 '22 04:10 hakusaro

I don't think it's worth it since nobody is ever gonna enter time in that way (first creating a negative duration and then offsetting it to be positive again), and even if somebody does it, it will just be seen as invalid instead of breaking in weird ways.

punchready avatar Oct 06 '22 12:10 punchready

if you want to have it "1h shorter than 2 days" you'll input "1d23h" and not "2d-1h" lmao

I concur that it's pointless

bartico6 avatar Oct 06 '22 14:10 bartico6