Skip to content

Commit

Permalink
use some compound expressions (#1315)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Feb 11, 2024
1 parent 5eaef3f commit f407e8b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Humanizer/DateHumanizeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class DateHumanizeExtensions
/// <returns>distance of time in words</returns>
public static string Humanize(this DateTime input, bool? utcDate = null, DateTime? dateToCompareAgainst = null, CultureInfo culture = null)
{
var comparisonBase = dateToCompareAgainst.HasValue ? dateToCompareAgainst.Value : DateTime.UtcNow;
var comparisonBase = dateToCompareAgainst ?? DateTime.UtcNow;
utcDate ??= input.Kind != DateTimeKind.Local;
comparisonBase = utcDate.Value ? comparisonBase.ToUniversalTime() : comparisonBase.ToLocalTime();

Expand Down Expand Up @@ -89,8 +89,7 @@ public static string Humanize(this DateTimeOffset? input, DateTimeOffset? dateTo
/// <returns>distance of time in words</returns>
public static string Humanize(this DateOnly input, DateOnly? dateToCompareAgainst = null, CultureInfo culture = null)
{
var comparisonBase = dateToCompareAgainst.HasValue ? dateToCompareAgainst.Value : DateOnly.FromDateTime(DateTime.UtcNow);

var comparisonBase = dateToCompareAgainst ?? DateOnly.FromDateTime(DateTime.UtcNow);
return Configurator.DateOnlyHumanizeStrategy.Humanize(input, comparisonBase, culture);
}

Expand Down Expand Up @@ -123,7 +122,7 @@ public static string Humanize(this DateOnly? input, DateOnly? dateToCompareAgain
/// <returns>distance of time in words</returns>
public static string Humanize(this TimeOnly input, TimeOnly? timeToCompareAgainst = null, bool useUtc = true, CultureInfo culture = null)
{
var comparisonBase = timeToCompareAgainst.HasValue ? timeToCompareAgainst.Value : TimeOnly.FromDateTime(useUtc ? DateTime.UtcNow : DateTime.Now);
var comparisonBase = timeToCompareAgainst ?? TimeOnly.FromDateTime(useUtc ? DateTime.UtcNow : DateTime.Now);

return Configurator.TimeOnlyHumanizeStrategy.Humanize(input, comparisonBase, culture);
}
Expand Down

0 comments on commit f407e8b

Please sign in to comment.