mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-15 12:45:01 +00:00
Merge branch 'fix/ModulusRename' of Common/Utils into dev
This commit is contained in:
@@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||||||
### Added
|
### Added
|
||||||
- Added a method for converting 24 hour to 12 hour format
|
- Added a method for converting 24 hour to 12 hour format
|
||||||
- Added a method for determining if a culture uses 24 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
|
- Added TimeSpan extension methods for cycling hours and minutes without modifying the day
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
@@ -72,9 +72,9 @@ namespace ICD.Common.Utils.Tests
|
|||||||
[TestCase(9, 3, 0)]
|
[TestCase(9, 3, 0)]
|
||||||
[TestCase(3, 2, 1)]
|
[TestCase(3, 2, 1)]
|
||||||
[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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int To12Hour(int hour)
|
public static int To12Hour(int hour)
|
||||||
{
|
{
|
||||||
return MathUtils.Mod(hour + 11, 12) + 1;
|
return MathUtils.Modulus(hour + 11, 12) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static TimeSpan AddHoursAndWrap(this TimeSpan extends, int hours)
|
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);
|
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;
|
int currentHour = extends.Hours;
|
||||||
bool am = extends.Hours < 12;
|
bool am = extends.Hours < 12;
|
||||||
|
|
||||||
int current12Hour = MathUtils.Mod(currentHour, 12);
|
int current12Hour = MathUtils.Modulus(currentHour, 12);
|
||||||
int new12Hour = MathUtils.Mod(current12Hour + hours, 12);
|
int new12Hour = MathUtils.Modulus(current12Hour + hours, 12);
|
||||||
|
|
||||||
return am
|
return am
|
||||||
? new TimeSpan(extends.Days, new12Hour, extends.Minutes, extends.Seconds, extends.Milliseconds)
|
? new TimeSpan(extends.Days, new12Hour, extends.Minutes, extends.Seconds, extends.Milliseconds)
|
||||||
@@ -65,7 +65,7 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static TimeSpan AddMinutesAndWrap(this TimeSpan extends, int minutes)
|
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);
|
return new TimeSpan(extends.Days, extends.Hours, minutes, extends.Seconds, extends.Milliseconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -216,7 +216,8 @@ namespace ICD.Common.Utils
|
|||||||
/// <param name="number"></param>
|
/// <param name="number"></param>
|
||||||
/// <param name="mod"></param>
|
/// <param name="mod"></param>
|
||||||
/// <returns></returns>
|
/// <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;
|
int remainder = number % mod;
|
||||||
return remainder < 0 ? remainder + mod : remainder;
|
return remainder < 0 ? remainder + mod : remainder;
|
||||||
|
|||||||
Reference in New Issue
Block a user