| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="TimeHumanizationPresets.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using MyNet.Primitives; |
| | | 8 | | using MyNet.Temporal.Decomposition; |
| | | 9 | | |
| | | 10 | | namespace MyNet.Humanizer.Temporal; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Provides preset configurations for <see cref="TimeSpanDecompositionOptions"/>. |
| | | 14 | | /// </summary> |
| | | 15 | | public static class TimeHumanizationPresets |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// Gets the default humanization options, which is the same as <see cref="Duration"/>. |
| | | 19 | | /// </summary> |
| | 3 | 20 | | public static TimeHumanizationOptions Default { get; } = new() |
| | 3 | 21 | | { |
| | 3 | 22 | | Mode = TimeHumanizationMode.Duration, |
| | 3 | 23 | | MaxComponents = 2, |
| | 3 | 24 | | MinUnit = TimeUnit.Second, |
| | 3 | 25 | | MaxUnit = TimeUnit.Year, |
| | 3 | 26 | | DecompositionMode = TimeSpanDecompositionMode.Hierarchical |
| | 3 | 27 | | }; |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets human-readable duration with up to 2 components. |
| | | 31 | | /// Example: |
| | | 32 | | /// 1 minute 59 seconds. |
| | | 33 | | /// </summary> |
| | 3 | 34 | | public static TimeHumanizationOptions Duration { get; } = new() |
| | 3 | 35 | | { |
| | 3 | 36 | | Mode = TimeHumanizationMode.Duration, |
| | 3 | 37 | | MaxComponents = 2, |
| | 3 | 38 | | MinUnit = TimeUnit.Second, |
| | 3 | 39 | | MaxUnit = TimeUnit.Year, |
| | 3 | 40 | | DecompositionMode = TimeSpanDecompositionMode.Hierarchical |
| | 3 | 41 | | }; |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Gets human-readable relative time with a single component. |
| | | 45 | | /// Example: |
| | | 46 | | /// 1 minute ago. |
| | | 47 | | /// </summary> |
| | 3 | 48 | | public static TimeHumanizationOptions Relative { get; } = new() |
| | 3 | 49 | | { |
| | 3 | 50 | | Mode = TimeHumanizationMode.Relative, |
| | 3 | 51 | | MaxComponents = 1, |
| | 3 | 52 | | Quantizer = HumanFriendlyTimeSpanQuantizer.Default |
| | 3 | 53 | | }; |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Gets exact human-readable decomposition. |
| | | 57 | | /// Example: |
| | | 58 | | /// 1 minute 59 seconds. |
| | | 59 | | /// </summary> |
| | 3 | 60 | | public static TimeHumanizationOptions Precise { get; } = new() |
| | 3 | 61 | | { |
| | 3 | 62 | | Mode = TimeHumanizationMode.Duration, |
| | 3 | 63 | | MaxComponents = null, |
| | 3 | 64 | | IncludeZeroUnits = false |
| | 3 | 65 | | }; |
| | | 66 | | |
| | | 67 | | /// <summary> |
| | | 68 | | /// Gets human-friendly approximation. |
| | | 69 | | /// Example: |
| | | 70 | | /// 59 seconds -> 1 minute. |
| | | 71 | | /// </summary> |
| | 3 | 72 | | public static TimeHumanizationOptions Fuzzy { get; } = new() |
| | 3 | 73 | | { |
| | 3 | 74 | | Mode = TimeHumanizationMode.Relative, |
| | 3 | 75 | | MaxComponents = 1, |
| | 3 | 76 | | Quantizer = HumanFriendlyTimeSpanQuantizer.Default |
| | 3 | 77 | | }; |
| | | 78 | | |
| | | 79 | | /// <summary> |
| | | 80 | | /// Gets compact UI-oriented representation. |
| | | 81 | | /// Example: |
| | | 82 | | /// 2h. |
| | | 83 | | /// </summary> |
| | 3 | 84 | | public static TimeHumanizationOptions Compact { get; } = new() |
| | 3 | 85 | | { |
| | 3 | 86 | | Mode = TimeHumanizationMode.Duration, |
| | 3 | 87 | | MaxComponents = 1 |
| | 3 | 88 | | }; |
| | | 89 | | } |
| | | 90 | | |