diff --git a/CHANGELOG.md b/CHANGELOG.md
index 865a965..37d7988 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
+### Added
+ - Added an extension method for getting the hour in 12 hour format
+
## [9.8.0] - 2019-09-03
### Added
- Added Public API Properties to get the program install date based on the creation date of core dll file for NetStandard and SimplSharp
diff --git a/ICD.Common.Utils.Tests/Extensions/DateTimeExtensionsTest.cs b/ICD.Common.Utils.Tests/Extensions/DateTimeExtensionsTest.cs
index 12e610d..a186f96 100644
--- a/ICD.Common.Utils.Tests/Extensions/DateTimeExtensionsTest.cs
+++ b/ICD.Common.Utils.Tests/Extensions/DateTimeExtensionsTest.cs
@@ -1,18 +1,29 @@
-using NUnit.Framework;
+using System;
+using ICD.Common.Utils.Extensions;
+using NUnit.Framework;
namespace ICD.Common.Utils.Tests.Extensions
{
[TestFixture]
- public sealed class DateTimeExtensionsTest
- {
- [Test]
- public static void ToShortTimeStringTest()
- {
- Assert.Inconclusive();
- }
+ public sealed class DateTimeExtensionsTest
+ {
+ [TestCase(1, 1)]
+ [TestCase(0, 12)]
+ [TestCase(12, 12)]
+ [TestCase(23, 11)]
+ public void Get12Hour(int hour, int expected)
+ {
+ Assert.AreEqual(expected, new DateTime(2019, 1, 1, hour, 0, 0).Get12Hour());
+ }
[Test]
- public static void ToLongTimeStringWithMillisecondsTest()
+ public void ToShortTimeStringTest()
+ {
+ Assert.Inconclusive();
+ }
+
+ [Test]
+ public void ToLongTimeStringWithMillisecondsTest()
{
Assert.Inconclusive();
}
diff --git a/ICD.Common.Utils/Extensions/DateTimeExtensions.cs b/ICD.Common.Utils/Extensions/DateTimeExtensions.cs
index acdc661..ecba069 100644
--- a/ICD.Common.Utils/Extensions/DateTimeExtensions.cs
+++ b/ICD.Common.Utils/Extensions/DateTimeExtensions.cs
@@ -10,6 +10,16 @@ namespace ICD.Common.Utils.Extensions
///
public static class DateTimeExtensions
{
+ ///
+ /// Gets the hour in 12 hour format (1 through 12).
+ ///
+ ///
+ ///
+ public static int Get12Hour(this DateTime extends)
+ {
+ return ((extends.Hour + 11) % 12) + 1;
+ }
+
///
/// Replacement for missing DateTime.ToShortTimeString() absent from NetStandard.
///