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

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