Merge branch 'fix/ModulusRename' of Common/Utils into dev

This commit is contained in:
Chris Cameron
2019-09-09 19:54:24 +00:00
committed by Gogs
5 changed files with 10 additions and 9 deletions

View File

@@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Added a method for converting 24 hour to 12 hour format
- Added a method for determining if a culture uses 24 hour format
- Added math util method for mod
- Added math util method for modulus
- Added TimeSpan extension methods for cycling hours and minutes without modifying the day
### Changed

View File

@@ -72,9 +72,9 @@ namespace ICD.Common.Utils.Tests
[TestCase(9, 3, 0)]
[TestCase(3, 2, 1)]
[TestCase(-3, 2, 1)]
public void ModTest(int value, int mod, int expected)
public void ModulusTest(int value, int mod, int expected)
{
Assert.AreEqual(expected, MathUtils.Mod(value, mod));
Assert.AreEqual(expected, MathUtils.Modulus(value, mod));
}
}
}

View File

@@ -9,7 +9,7 @@
/// <returns></returns>
public static int To12Hour(int hour)
{
return MathUtils.Mod(hour + 11, 12) + 1;
return MathUtils.Modulus(hour + 11, 12) + 1;
}
}
}

View File

@@ -34,7 +34,7 @@ namespace ICD.Common.Utils.Extensions
/// <returns></returns>
public static TimeSpan AddHoursAndWrap(this TimeSpan extends, int hours)
{
hours = MathUtils.Mod(hours + extends.Hours, 24);
hours = MathUtils.Modulus(hours + extends.Hours, 24);
return new TimeSpan(extends.Days, hours, extends.Minutes, extends.Seconds, extends.Milliseconds);
}
@@ -49,8 +49,8 @@ namespace ICD.Common.Utils.Extensions
int currentHour = extends.Hours;
bool am = extends.Hours < 12;
int current12Hour = MathUtils.Mod(currentHour, 12);
int new12Hour = MathUtils.Mod(current12Hour + hours, 12);
int current12Hour = MathUtils.Modulus(currentHour, 12);
int new12Hour = MathUtils.Modulus(current12Hour + hours, 12);
return am
? new TimeSpan(extends.Days, new12Hour, extends.Minutes, extends.Seconds, extends.Milliseconds)
@@ -65,7 +65,7 @@ namespace ICD.Common.Utils.Extensions
/// <returns></returns>
public static TimeSpan AddMinutesAndWrap(this TimeSpan extends, int minutes)
{
minutes = MathUtils.Mod(minutes + extends.Minutes, 60);
minutes = MathUtils.Modulus(minutes + extends.Minutes, 60);
return new TimeSpan(extends.Days, extends.Hours, minutes, extends.Seconds, extends.Milliseconds);
}
}

View File

@@ -216,7 +216,8 @@ namespace ICD.Common.Utils
/// <param name="number"></param>
/// <param name="mod"></param>
/// <returns></returns>
public static int Mod(int number, int mod)
/// <remarks>method name can't be "Mod", due to S+ compatability issues</remarks>
public static int Modulus(int number, int mod)
{
int remainder = number % mod;
return remainder < 0 ? remainder + mod : remainder;