This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace AyaNova.Util
|
||||
{
|
||||
@@ -60,10 +62,10 @@ namespace AyaNova.Util
|
||||
return DateToDisplay.ToLocalTime().ToString("g");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// <summary>
|
||||
/// Returns current date/time in sortable format
|
||||
///(used for duplicate names by stringUtil and others)
|
||||
///(used for duplicate names by stringUtil and others)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string SortableShortCurrentDateTimeValue
|
||||
@@ -77,18 +79,49 @@ namespace AyaNova.Util
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 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)
|
||||
/// </summary>
|
||||
/// <param name="DateToDisplay"></param>
|
||||
/// <returns></returns>
|
||||
public static string UniversalISO8661Format(DateTime DateToDisplay)
|
||||
{
|
||||
DateTime dtUTC=new DateTime(DateToDisplay.Ticks, DateTimeKind.Utc);
|
||||
DateTime dtUTC = new DateTime(DateToDisplay.Ticks, DateTimeKind.Utc);
|
||||
return dtUTC.ToString("o");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// returns passed in timespan to human readable format
|
||||
/// </summary>
|
||||
/// <param name="timeSpan"></param>
|
||||
/// <returns></returns>
|
||||
public static string FormatTimeSpan(TimeSpan timeSpan)
|
||||
{
|
||||
Func<Tuple<int, string>, string> tupleFormatter = t => $"{t.Item1} {t.Item2}{(t.Item1 == 1 ? string.Empty : "s")}";
|
||||
var components = new List<Tuple<int, string>>
|
||||
{
|
||||
Tuple.Create((int) timeSpan.TotalDays, "day"),
|
||||
Tuple.Create(timeSpan.Hours, "hour"),
|
||||
Tuple.Create(timeSpan.Minutes, "minute"),
|
||||
Tuple.Create(timeSpan.Seconds, "second"),
|
||||
};
|
||||
|
||||
components.RemoveAll(i => i.Item1 == 0);
|
||||
|
||||
string extra = "";
|
||||
|
||||
if (components.Count > 1)
|
||||
{
|
||||
var finalComponent = components[components.Count - 1];
|
||||
components.RemoveAt(components.Count - 1);
|
||||
extra = $" and {tupleFormatter(finalComponent)}";
|
||||
}
|
||||
|
||||
return $"{string.Join(", ", components.Select(tupleFormatter))}{extra}";
|
||||
}
|
||||
|
||||
|
||||
}//eoc
|
||||
|
||||
}//eons
|
||||
Reference in New Issue
Block a user