Humanizer
Humanizer copied to clipboard
TimeSpan.FromSeconds(-10).Humanize() SHOULD NOT EQUAL TimeSpan.FromSeconds(10).Humanize()
A negative TimeSpan should retain its direction when Humanized.
We pass an absolute value to BuildFormatTimePart()
in the TimeSpanHumanizerExt
so we can return the correct word.
I would suggest adding negative word when we assemble the ListCreateTheTimePartsWithUpperAndLowerLimits()
, but we would still need to fetch the word in a cultureFormat for the correct word and grammar.
private static IEnumerable<string> CreateTheTimePartsWithUpperAndLowerLimits(TimeSpan timespan, CultureInfo culture, TimeUnit maxUnit, TimeUnit minUnit, bool toWords = false)
{
/* ... */
foreach (var timeUnitType in timeUnitsEnumTypes)
{
var timepart = GetTimeUnitPart(timeUnitType,timespan, maxUnit, minUnit, cultureFormatter, toWords);
if (timepart != null || firstValueFound)
{
firstValueFound = true;
timeParts.Add(timepart);
}
}
// Add the Negative word (E.g "Minus") ad the begining or end depending on Locale) of the list
@clairernovotny Since it would affect the IFormatter Interface, I would ask your opinion on this solution.
100% would be an excellent feature for negative timespans to return "2 Days, 45 Minutes ago"