/// <summary> /// Generates Resource Keys accordning to convention. /// </summary> /// <param name="timeUnit">Time unit</param> /// <param name="timeUnitTense">Is time unit in future or past</param> /// <param name="count">Number of units, default is One.</param> /// <returns>Resource key, like DateHumanize_SingleMinuteAgo</returns> public static string GetResourceKey(TimeUnit timeUnit, TimeUnitTense timeUnitTense, int count = 1) { ValidateRange(count); if (count == 0) return Now; var singularity = count == 1 ? Single : Multiple; var tense = timeUnitTense == TimeUnitTense.Future ? FromNow : Ago; var unit = timeUnit.ToString().ToQuantity(count, ShowQuantityAs.None); return DateTimeFormat.FormatWith(singularity, unit, tense); }
public virtual string DateHumanize(TimeUnit timeUnit, TimeUnitTense timeUnitTense, int unit) { return GetResourceForDate(timeUnit, timeUnitTense, unit); }
private string GetResourceForDate(TimeUnit unit, TimeUnitTense timeUnitTense, int count) { string resourceKey = ResourceKeys.DateHumanize.GetResourceKey(unit, timeUnitTense: timeUnitTense, count: count); return count == 1 ? Format(resourceKey) : Format(resourceKey, count); }