Skip to content

Commit

Permalink
improve perf of ResourceKeys.GetResourceKey (#1313)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Feb 13, 2024
1 parent 4f88997 commit afdb749
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Humanizer/Localisation/ResourceKeys.DateHumanize.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Humanizer.Localisation
using System;

namespace Humanizer.Localisation
{
public partial class ResourceKeys
{
Expand Down Expand Up @@ -42,9 +44,19 @@ public static string GetResourceKey(TimeUnit timeUnit, Tense timeUnitTense, int
return Now;
}

var singularity = count == 1 ? Single : Multiple;
string singularity;
var unit = timeUnit.ToString();
if (count == 1)
{
singularity = Single;
}
else
{
unit += "s";
singularity = Multiple;
}

var tense = timeUnitTense == Tense.Future ? FromNow : Ago;
var unit = timeUnit.ToString().ToQuantity(count, ShowQuantityAs.None);
return DateTimeFormat.FormatWith(singularity, unit, tense);
}
}
Expand Down

0 comments on commit afdb749

Please sign in to comment.