Skip to content

Period.CreateComparer Method

Definition

Namespace: Corvus.Text.Json
Assembly: Corvus.Text.Json.dll
Source: Period.cs

CreateComparer(LocalDateTime)

Creates an IComparer for periods, using the given "base" local date/time.

public static IComparer<Period> CreateComparer(LocalDateTime baseDateTime)

Parameters

Name Type Description
baseDateTime LocalDateTime The base local date/time to use for comparisons.

Returns

IComparer<Period>

The new comparer.

Remarks

Certain periods can't naturally be compared without more context - how "one month" compares to "30 days" depends on where you start. In order to compare two periods, the returned comparer effectively adds both periods to the "base" specified by baseDateTime and compares the results. In some cases this arithmetic isn't actually required - when two periods can be converted to durations, the comparer uses that conversion for efficiency.

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Collaborate with us on GitHub

The source for this content can be found on GitHub, where you can also create and review issues and pull requests.

Open an issue