refactor: Changed DateTime extension method to a simple util method

This commit is contained in:
Chris Cameron
2019-09-04 14:30:45 -04:00
parent dc1b60e629
commit 027c9ffe82
8 changed files with 55 additions and 23 deletions

View File

@@ -7,7 +7,7 @@ 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
- Added a method for converting 24 hour to 12 hour format
## [9.8.0] - 2019-09-03
### Added

View File

@@ -0,0 +1,17 @@
using NUnit.Framework;
namespace ICD.Common.Utils.Tests
{
[TestFixture]
public sealed class DateTimeUtilsTest
{
[TestCase(1, 1)]
[TestCase(0, 12)]
[TestCase(12, 12)]
[TestCase(23, 11)]
public void Get12Hour(int hour, int expected)
{
Assert.AreEqual(expected, DateTimeUtils.To12Hour(hour));
}
}
}

View File

@@ -1,21 +1,10 @@
using System;
using ICD.Common.Utils.Extensions;
using NUnit.Framework;
using NUnit.Framework;
namespace ICD.Common.Utils.Tests.Extensions
{
[TestFixture]
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 void ToShortTimeStringTest()
{

View File

@@ -0,0 +1,15 @@
namespace ICD.Common.Utils
{
public static class DateTimeUtils
{
/// <summary>
/// Converts the hour in 24 hour format to 12 hour format (1 through 12).
/// </summary>
/// <param name="hour"></param>
/// <returns></returns>
public static int To12Hour(int hour)
{
return ((hour + 11) % 12) + 1;
}
}
}

View File

@@ -10,16 +10,6 @@ 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>

View File

@@ -86,6 +86,7 @@
<Compile Include="Comparers\PredicateComparer.cs" />
<Compile Include="Comparers\SequenceComparer.cs" />
<Compile Include="ConsoleColor.cs" />
<Compile Include="DateTimeUtils.cs" />
<Compile Include="Email\EmailClient.cs" />
<Compile Include="Email\eMailErrorCode.cs" />
<Compile Include="Email\EmailStringCollection.cs" />

View File

@@ -190,6 +190,16 @@ namespace ICD.Common.Utils
return CrestronEnvironment.GetLocalTime();
}
public static void SetLocalTime(DateTime localTime)
{
CrestronEnvironment.SetTimeAndDate((ushort)localTime.Hour,
(ushort)localTime.Minute,
(ushort)localTime.Second,
(ushort)localTime.Month,
(ushort)localTime.Day,
(ushort)localTime.Year);
}
public static eEthernetEventType GetEthernetEventType(Crestron.SimplSharp.eEthernetEventType type)
{
switch (type)

View File

@@ -79,6 +79,16 @@ namespace ICD.Common.Utils
return DateTime.Now;
}
public static void SetLocalTime(DateTime localTime)
{
#if DEBUG
IcdConsole.PrintLine(eConsoleColor.Magenta, "Debug Build - Skipped setting local time to {0}",
localTime.ToString("s"));
#else
throw new NotSupportedException();
#endif
}
/// <summary>
/// Converts 12 digit address to XX:XX:XX... format
/// </summary>