This commit is contained in:
69
server/AyaNova/util/DateUtil.cs
Normal file
69
server/AyaNova/util/DateUtil.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
|
||||
namespace AyaNova.Util
|
||||
{
|
||||
|
||||
|
||||
internal static class DateUtil
|
||||
{
|
||||
/// <summary>
|
||||
/// Is the current date after the referenced date by at least the duration specified
|
||||
/// </summary>
|
||||
/// <param name="startDate">UTC start point to compare to current UTC date</param>
|
||||
/// <param name="Hours"></param>
|
||||
/// <param name="Minutes"></param>
|
||||
/// <param name="Seconds"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsAfterDuration(DateTime startDate, int Hours, int Minutes = 0, int Seconds = 0)
|
||||
{
|
||||
TimeSpan ts = new TimeSpan(Hours, Minutes, Seconds);
|
||||
return IsAfterDuration(startDate, ts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the current date after the referenced date by at least the timespan specified
|
||||
/// </summary>
|
||||
/// <param name="startDate">UTC start point to compare to current UTC date</param>
|
||||
/// <param name="tspan"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsAfterDuration(DateTime startDate, TimeSpan tspan)
|
||||
{
|
||||
if (DateTime.UtcNow - startDate < tspan)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// An internally consistent empty or not relevant date marker:
|
||||
/// January 1st 5555
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static DateTime EmptyDateValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return new DateTime(5555, 1, 1);
|
||||
//Was going to use MaxValue but apparently that varies depending on culture
|
||||
// and Postgres has issues with year 1 as it interprets as year 2001
|
||||
// so to be on safe side just defining one for all usage
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// returns a UTC short date, short time formatted date for local display to end user in logs, errors etc at the server level
|
||||
/// (Not related to UI display of dates and times)
|
||||
/// </summary>
|
||||
/// <param name="DateToDisplay"></param>
|
||||
/// <returns></returns>
|
||||
public static string ServerDateTimeString(DateTime DateToDisplay)
|
||||
{
|
||||
return DateToDisplay.ToLocalTime().ToString("g");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}//eoc
|
||||
|
||||
}//eons
|
||||
Reference in New Issue
Block a user