Skip to content

Commit 10e024c

Browse files
committed
feat(duration): add DurationUnit enum for temporal measurements
- Implements an enumeration for various units of duration including fixed-duration (Tick, Hour) and calendar-duration units (Day, Millennium). - Includes XML documentation to aid in understanding the purpose and usage of each unit. - Provides examples for converting duration units to TimeSpan for ease of use in applications.
1 parent fc6c755 commit 10e024c

1 file changed

Lines changed: 127 additions & 0 deletions

File tree

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
using JetBrains.Annotations;
2+
3+
namespace ES.FX.Primitives;
4+
5+
/// <summary>
6+
/// Specifies units of duration for temporal measurements.
7+
/// </summary>
8+
/// <remarks>
9+
/// <para>
10+
/// The <see cref="DurationUnit" /> enumeration defines both fixed-duration units
11+
/// (<see cref="Tick" /> through <see cref="Hour" />) and calendar-duration units
12+
/// (<see cref="Day" /> through <see cref="Millennium" />).
13+
/// </para>
14+
/// <para>
15+
/// Fixed-duration units correspond to <see cref="TimeSpan" /> properties (for example,
16+
/// <c>TimeSpan.TicksPerSecond</c> for <see cref="Second" />). Calendar-duration units
17+
/// require <see cref="DateTime" /> arithmetic (for example, <c>DateTime.AddMonths(int)</c>
18+
/// for <see cref="Month" />).
19+
/// </para>
20+
/// </remarks>
21+
/// <example>
22+
/// <code language="csharp">
23+
/// // Convert 3 units of the specified duration to a TimeSpan.
24+
/// TimeSpan span;
25+
/// switch (unit)
26+
/// {
27+
/// case DurationUnit.Hour:
28+
/// span = TimeSpan.FromHours(3);
29+
/// break;
30+
/// case DurationUnit.Minute:
31+
/// span = TimeSpan.FromMinutes(3);
32+
/// break;
33+
/// case DurationUnit.Second:
34+
/// span = TimeSpan.FromSeconds(3);
35+
/// break;
36+
/// // Add additional cases as needed...
37+
/// default:
38+
/// throw new ArgumentOutOfRangeException(nameof(unit), unit, null);
39+
/// }
40+
/// Console.WriteLine(span);
41+
/// </code>
42+
/// </example>
43+
/// <seealso cref="TimeSpan" />
44+
/// <seealso cref="DateTime" />
45+
[PublicAPI]
46+
public enum DurationUnit
47+
{
48+
/// <summary>
49+
/// No duration unit.
50+
/// </summary>
51+
None,
52+
53+
/// <summary>
54+
/// A 100-nanosecond interval.
55+
/// </summary>
56+
Tick,
57+
58+
/// <summary>
59+
/// One nanosecond (1×10⁻⁹ second). Mapping to ticks may require rounding.
60+
/// </summary>
61+
Nanosecond,
62+
63+
/// <summary>
64+
/// One microsecond (1×10⁻⁶ second). Mapping to ticks may require rounding.
65+
/// </summary>
66+
Microsecond,
67+
68+
/// <summary>
69+
/// One millisecond (1×10⁻³ second).
70+
/// </summary>
71+
Millisecond,
72+
73+
/// <summary>
74+
/// One second.
75+
/// </summary>
76+
Second,
77+
78+
/// <summary>
79+
/// One minute (60 seconds).
80+
/// </summary>
81+
Minute,
82+
83+
/// <summary>
84+
/// One hour (60 minutes).
85+
/// </summary>
86+
Hour,
87+
88+
/// <summary>
89+
/// One day (24 hours).
90+
/// </summary>
91+
Day,
92+
93+
/// <summary>
94+
/// One week (7 days).
95+
/// </summary>
96+
Week,
97+
98+
/// <summary>
99+
/// One calendar month (28–31 days).
100+
/// </summary>
101+
Month,
102+
103+
/// <summary>
104+
/// One calendar quarter (3 months).
105+
/// </summary>
106+
Quarter,
107+
108+
/// <summary>
109+
/// One calendar year (12 months).
110+
/// </summary>
111+
Year,
112+
113+
/// <summary>
114+
/// One decade (10 years).
115+
/// </summary>
116+
Decade,
117+
118+
/// <summary>
119+
/// One century (100 years).
120+
/// </summary>
121+
Century,
122+
123+
/// <summary>
124+
/// One millennium (1000 years).
125+
/// </summary>
126+
Millennium
127+
}

0 commit comments

Comments
 (0)