using System; namespace AyaNova.Util { internal static class DateUtil { /// /// Is the current date after the referenced date by at least the duration specified /// /// UTC start point to compare to current UTC date /// /// /// /// 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); } /// /// Is the current date after the referenced date by at least the timespan specified /// /// UTC start point to compare to current UTC date /// /// public static bool IsAfterDuration(DateTime startDate, TimeSpan tspan) { if (DateTime.UtcNow - startDate < tspan) return false; return true; } /// /// An internally consistent empty or not relevant date marker: /// January 1st 5555 /// /// 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 } } /// /// 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) /// /// /// public static string ServerDateTimeString(DateTime DateToDisplay) { return DateToDisplay.ToLocalTime().ToString("g"); } /// /// Returns current date/time in sortable format ///(used for duplicate names by stringUtil and others) /// /// public static string SortableShortCurrentDateTimeValue { get { return DateTime.Now.ToString("s"); //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 } } /// /// returns passed in date as a string format ISO8661 UTC date (no conversion of date is done, it's assumed to be in UTC already) /// /// /// public static string UniversalISO8661Format(DateTime DateToDisplay) { DateTime dtUTC=new DateTime(DateToDisplay.Ticks, DateTimeKind.Utc); return dtUTC.ToString("o"); } }//eoc }//eons