コード例 #1
0
            /// <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);
            }
コード例 #2
0
 public virtual string DateHumanize(TimeUnit timeUnit, TimeUnitTense timeUnitTense, int unit)
 {
     return GetResourceForDate(timeUnit, timeUnitTense, unit);
 }
コード例 #3
0
 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);
 }