Exceptionless.DateTimeExtensions icon indicating copy to clipboard operation
Exceptionless.DateTimeExtensions copied to clipboard

SubtractSaturating

Open dzmitry-lahoda opened this issue 3 years ago • 4 comments
trafficstars

public static class TimeSpanExtensions {
        public static TimeSpan SubtractSaturating(this TimeSpan self, TimeSpan other) =>
            self >= other ? self.Subtract(other) : TimeSpan.Zero;
    }

dzmitry-lahoda avatar Dec 09 '21 18:12 dzmitry-lahoda

This is a method that subtracts a TimeSpan and is just ensuring that the resulting TimeSpan doesn't go below zero?

ejsmith avatar Dec 09 '21 19:12 ejsmith

yes.

dzmitry-lahoda avatar Dec 09 '21 21:12 dzmitry-lahoda

Isn't this the same as safe subtract that we have for datetimes?

niemyjski avatar Dec 09 '21 21:12 niemyjski

@dzmitry-lahoda ^^

niemyjski avatar May 05 '23 03:05 niemyjski