feat: Added an extension method for getting the hour in 12 hour format

This commit is contained in:
Chris Cameron
2019-09-04 12:36:54 -04:00
parent 091ad10068
commit dc1b60e629
3 changed files with 33 additions and 9 deletions

View File

@@ -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

View File

@@ -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();
}

View File

@@ -10,6 +10,16 @@ namespace ICD.Common.Utils.Extensions
/// </summary>
public static class DateTimeExtensions
{
/// <summary>
/// Gets the hour in 12 hour format (1 through 12).
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static int Get12Hour(this DateTime extends)
{
return ((extends.Hour + 11) % 12) + 1;
}
/// <summary>
/// Replacement for missing DateTime.ToShortTimeString() absent from NetStandard.
/// </summary>