| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="TimeHumanizerExtensions.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using MyNet.Humanizer.Temporal; |
| | | 9 | | using MyNet.Temporal.Decomposition; |
| | | 10 | | |
| | | 11 | | #pragma warning disable IDE0130 // Namespace does not match folder structure |
| | | 12 | | namespace MyNet.Humanizer; |
| | | 13 | | #pragma warning restore IDE0130 // Namespace does not match folder structure |
| | | 14 | | |
| | | 15 | | public static class TimeHumanizerExtensions |
| | | 16 | | { |
| | | 17 | | extension(TimeSpan timeSpan) |
| | | 18 | | { |
| | | 19 | | /// <summary> |
| | | 20 | | /// Infers the tense from the specified time span. |
| | | 21 | | /// </summary> |
| | | 22 | | /// <returns> |
| | | 23 | | /// <see cref="Tense.Future"/> when the span is positive or zero; |
| | | 24 | | /// otherwise <see cref="Tense.Past"/>. |
| | | 25 | | /// </returns> |
| | 18 | 26 | | public Tense Tense() => timeSpan >= TimeSpan.Zero ? Temporal.Tense.Future : Temporal.Tense.Past; |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | extension(TimeHumanizationOptions options) |
| | | 30 | | { |
| | | 31 | | /// <summary> |
| | | 32 | | /// Converts humanization options to decomposition options. |
| | | 33 | | /// </summary> |
| | | 34 | | /// <returns>The corresponding decomposition options.</returns> |
| | | 35 | | public TimeSpanDecompositionOptions ToDecompositionOptions() |
| | | 36 | | { |
| | 294 | 37 | | ArgumentNullException.ThrowIfNull(options); |
| | | 38 | | |
| | 294 | 39 | | return new() |
| | 294 | 40 | | { |
| | 294 | 41 | | MinUnit = options.MinUnit, |
| | 294 | 42 | | MaxUnit = options.MaxUnit, |
| | 294 | 43 | | Mode = options.DecompositionMode, |
| | 294 | 44 | | MaxComponents = options.MaxComponents, |
| | 294 | 45 | | IncludeZeroUnits = options.IncludeZeroUnits, |
| | 294 | 46 | | Quantizer = options.Quantizer |
| | 294 | 47 | | }; |
| | | 48 | | } |
| | | 49 | | } |
| | | 50 | | } |
| | | 51 | | |