From 07126575a35ef16cff8304fff221cdd4597eeda3 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 21 Apr 2022 21:23:49 +0100 Subject: [PATCH] Don't bother adding overflowed long --- X10D/src/Time/UInt64Extensions.cs | 69 ++++--------------------------- 1 file changed, 7 insertions(+), 62 deletions(-) diff --git a/X10D/src/Time/UInt64Extensions.cs b/X10D/src/Time/UInt64Extensions.cs index 05b940a..64ff6f7 100644 --- a/X10D/src/Time/UInt64Extensions.cs +++ b/X10D/src/Time/UInt64Extensions.cs @@ -13,14 +13,7 @@ public static class UInt64Extensions /// A whose will equal . public static TimeSpan Ticks(this ulong value) { - long remainder = 0; - if (value > long.MaxValue) - { - remainder = (long)(value - long.MaxValue); - value -= long.MaxValue; - } - - return TimeSpan.FromTicks((long)value).Add(TimeSpan.FromTicks(remainder)); + return TimeSpan.FromTicks((long)value); } /// @@ -32,15 +25,7 @@ public static class UInt64Extensions /// public static TimeSpan Milliseconds(this ulong value) { - long remainder = 0; - - if (value > long.MaxValue) - { - remainder = (long)(value - long.MaxValue); - value -= long.MaxValue; - } - - return TimeSpan.FromMilliseconds((long)value).Add(TimeSpan.FromMilliseconds(remainder)); + return TimeSpan.FromMilliseconds((long)value); } /// @@ -52,15 +37,7 @@ public static class UInt64Extensions /// public static TimeSpan Seconds(this ulong value) { - long remainder = 0; - - if (value > long.MaxValue) - { - remainder = (long)(value - long.MaxValue); - value -= long.MaxValue; - } - - return TimeSpan.FromSeconds((long)value).Add(TimeSpan.FromSeconds(remainder)); + return TimeSpan.FromSeconds((long)value); } /// @@ -72,15 +49,7 @@ public static class UInt64Extensions /// public static TimeSpan Minutes(this ulong value) { - long remainder = 0; - - if (value > long.MaxValue) - { - remainder = (long)(value - long.MaxValue); - value -= long.MaxValue; - } - - return TimeSpan.FromMinutes((long)value).Add(TimeSpan.FromMinutes(remainder)); + return TimeSpan.FromMinutes((long)value); } /// @@ -92,15 +61,7 @@ public static class UInt64Extensions /// public static TimeSpan Hours(this ulong value) { - long remainder = 0; - - if (value > long.MaxValue) - { - remainder = (long)(value - long.MaxValue); - value -= long.MaxValue; - } - - return TimeSpan.FromHours((long)value).Add(TimeSpan.FromHours(remainder)); + return TimeSpan.FromHours((long)value); } /// @@ -110,15 +71,7 @@ public static class UInt64Extensions /// A whose will equal . public static TimeSpan Days(this ulong value) { - long remainder = 0; - - if (value > long.MaxValue) - { - remainder = (long)(value - long.MaxValue); - value -= long.MaxValue; - } - - return TimeSpan.FromDays((long)value).Add(TimeSpan.FromDays(remainder)); + return TimeSpan.FromDays((long)value); } /// @@ -130,14 +83,6 @@ public static class UInt64Extensions /// public static TimeSpan Weeks(this ulong value) { - long remainder = 0; - - if (value > long.MaxValue) - { - remainder = (long)(value - long.MaxValue); - value -= long.MaxValue; - } - - return TimeSpan.FromDays((long)value * 7).Add(TimeSpan.FromDays(remainder * 7)); + return TimeSpan.FromDays((long)value * 7); } }