| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="FluentTimeSpan.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Runtime.InteropServices; |
| | | 9 | | |
| | | 10 | | namespace MyNet.Primitives.Temporal; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Represents a time span extended with months and years components to allow fluent arithmetic |
| | | 14 | | /// while still being convertible to a <see cref="TimeSpan"/>. |
| | | 15 | | /// </summary> |
| | | 16 | | [StructLayout(LayoutKind.Sequential)] |
| | | 17 | | public readonly struct FluentTimeSpan : |
| | | 18 | | IEquatable<FluentTimeSpan>, |
| | | 19 | | IComparable<TimeSpan>, |
| | | 20 | | IComparable<FluentTimeSpan> |
| | | 21 | | { |
| | | 22 | | private const int DaysPerYear = 365; |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Gets the number of months component of the fluent timespan. |
| | | 26 | | /// </summary> |
| | | 27 | | public int Months { get; init; } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets the number of years component of the fluent timespan. |
| | | 31 | | /// </summary> |
| | | 32 | | public int Years { get; init; } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Gets the <see cref="TimeSpan"/> component of the fluent timespan (days, hours, minutes, etc.). |
| | | 36 | | /// </summary> |
| | | 37 | | public TimeSpan TimeSpan { get; init; } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets the number of ticks that represent the value of the current <see cref="TimeSpan"/> structure. |
| | | 41 | | /// </summary> |
| | 3 | 42 | | public long Ticks => ((TimeSpan)this).Ticks; |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Gets the days portion of the underlying <see cref="TimeSpan"/>. |
| | | 46 | | /// </summary> |
| | 27 | 47 | | public int Days => ((TimeSpan)this).Days; |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Gets the hours portion of the underlying <see cref="TimeSpan"/>. |
| | | 51 | | /// </summary> |
| | 3 | 52 | | public int Hours => ((TimeSpan)this).Hours; |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// Gets the milliseconds portion of the underlying <see cref="TimeSpan"/>. |
| | | 56 | | /// </summary> |
| | 3 | 57 | | public int Milliseconds => ((TimeSpan)this).Milliseconds; |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// Gets the minutes portion of the underlying <see cref="TimeSpan"/>. |
| | | 61 | | /// </summary> |
| | 3 | 62 | | public int Minutes => ((TimeSpan)this).Minutes; |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// Gets the seconds portion of the underlying <see cref="TimeSpan"/>. |
| | | 66 | | /// </summary> |
| | 3 | 67 | | public int Seconds => ((TimeSpan)this).Seconds; |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// Gets the total days represented by this fluent timespan. |
| | | 71 | | /// </summary> |
| | 3 | 72 | | public double TotalDays => ((TimeSpan)this).TotalDays; |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// Gets the total hours represented by this fluent timespan. |
| | | 76 | | /// </summary> |
| | 3 | 77 | | public double TotalHours => ((TimeSpan)this).TotalHours; |
| | | 78 | | |
| | | 79 | | /// <summary> |
| | | 80 | | /// Gets the total milliseconds represented by this fluent timespan. |
| | | 81 | | /// </summary> |
| | 3 | 82 | | public double TotalMilliseconds => ((TimeSpan)this).TotalMilliseconds; |
| | | 83 | | |
| | | 84 | | /// <summary> |
| | | 85 | | /// Gets the total minutes represented by this fluent timespan. |
| | | 86 | | /// </summary> |
| | 3 | 87 | | public double TotalMinutes => ((TimeSpan)this).TotalMinutes; |
| | | 88 | | |
| | | 89 | | /// <summary> |
| | | 90 | | /// Gets the total seconds represented by this fluent timespan. |
| | | 91 | | /// </summary> |
| | 3 | 92 | | public double TotalSeconds => ((TimeSpan)this).TotalSeconds; |
| | | 93 | | |
| | | 94 | | /// <summary> |
| | | 95 | | /// Converts the <see cref="FluentTimeSpan"/> to a <see cref="TimeSpan"/>. Years are treated as 365 days and months |
| | | 96 | | /// </summary> |
| | | 97 | | /// <param name="fluentTimeSpan">The fluent timespan to convert.</param> |
| | | 98 | | public static implicit operator TimeSpan(FluentTimeSpan fluentTimeSpan) |
| | | 99 | | { |
| | 396 | 100 | | var daysFromYears = DaysPerYear * fluentTimeSpan.Years; |
| | 396 | 101 | | var daysFromMonths = 30 * fluentTimeSpan.Months; |
| | 396 | 102 | | var days = daysFromMonths + daysFromYears; |
| | 396 | 103 | | return new TimeSpan(days, 0, 0, 0) + fluentTimeSpan.TimeSpan; |
| | | 104 | | } |
| | | 105 | | |
| | | 106 | | /// <summary> |
| | | 107 | | /// Converts a <see cref="TimeSpan"/> to a <see cref="FluentTimeSpan"/> with only the <see cref="TimeSpan"/> compone |
| | | 108 | | /// </summary> |
| | | 109 | | /// <param name="timeSpan">The TimeSpan to convert.</param> |
| | 45 | 110 | | public static implicit operator FluentTimeSpan(TimeSpan timeSpan) => new() { TimeSpan = timeSpan }; |
| | | 111 | | |
| | | 112 | | /// <summary> |
| | | 113 | | /// Adds two <see cref="FluentTimeSpan"/> instances. |
| | | 114 | | /// </summary> |
| | 6 | 115 | | public static FluentTimeSpan operator +(FluentTimeSpan left, FluentTimeSpan right) => AddInternal(left, right); |
| | | 116 | | |
| | | 117 | | /// <summary> |
| | | 118 | | /// Adds a <see cref="TimeSpan"/> to a <see cref="FluentTimeSpan"/>. |
| | | 119 | | /// </summary> |
| | 6 | 120 | | public static FluentTimeSpan operator +(FluentTimeSpan left, TimeSpan right) => AddInternal(left, right); |
| | | 121 | | |
| | | 122 | | /// <summary> |
| | | 123 | | /// Adds a <see cref="TimeSpan"/> and a <see cref="FluentTimeSpan"/>. |
| | | 124 | | /// </summary> |
| | 9 | 125 | | public static FluentTimeSpan operator +(TimeSpan left, FluentTimeSpan right) => AddInternal(left, right); |
| | | 126 | | |
| | | 127 | | /// <summary> |
| | | 128 | | /// Subtracts two <see cref="FluentTimeSpan"/> instances. |
| | | 129 | | /// </summary> |
| | 6 | 130 | | public static FluentTimeSpan operator -(FluentTimeSpan left, FluentTimeSpan right) => SubtractInternal(left, right); |
| | | 131 | | |
| | | 132 | | /// <summary> |
| | | 133 | | /// Subtracts a <see cref="FluentTimeSpan"/> from a <see cref="TimeSpan"/>. |
| | | 134 | | /// </summary> |
| | 6 | 135 | | public static FluentTimeSpan operator -(TimeSpan left, FluentTimeSpan right) => SubtractInternal(left, right); |
| | | 136 | | |
| | | 137 | | /// <summary> |
| | | 138 | | /// Subtracts a <see cref="TimeSpan"/> from a <see cref="FluentTimeSpan"/>. |
| | | 139 | | /// </summary> |
| | 6 | 140 | | public static FluentTimeSpan operator -(FluentTimeSpan left, TimeSpan right) => SubtractInternal(left, right); |
| | | 141 | | |
| | | 142 | | /// <summary> |
| | | 143 | | /// Determines whether two <see cref="FluentTimeSpan"/> instances are equal. |
| | | 144 | | /// </summary> |
| | 264 | 145 | | public static bool operator ==(FluentTimeSpan left, FluentTimeSpan right) => left.Years == right.Years && |
| | 264 | 146 | | left.Months == right.Months && |
| | 264 | 147 | | left.TimeSpan == right.TimeSpan; |
| | | 148 | | |
| | | 149 | | /// <summary> |
| | | 150 | | /// Determines whether a <see cref="TimeSpan"/> and a <see cref="FluentTimeSpan"/> are equal. |
| | | 151 | | /// </summary> |
| | 6 | 152 | | public static bool operator ==(TimeSpan left, FluentTimeSpan right) => (FluentTimeSpan)left == right; |
| | | 153 | | |
| | | 154 | | /// <summary> |
| | | 155 | | /// Determines whether a <see cref="FluentTimeSpan"/> and a <see cref="TimeSpan"/> are equal. |
| | | 156 | | /// </summary> |
| | 9 | 157 | | public static bool operator ==(FluentTimeSpan left, TimeSpan right) => left == (FluentTimeSpan)right; |
| | | 158 | | |
| | | 159 | | /// <summary> |
| | | 160 | | /// Determines whether two <see cref="FluentTimeSpan"/> instances are not equal. |
| | | 161 | | /// </summary> |
| | 3 | 162 | | public static bool operator !=(FluentTimeSpan left, FluentTimeSpan right) => !(left == right); |
| | | 163 | | |
| | | 164 | | /// <summary> |
| | | 165 | | /// Determines whether a <see cref="TimeSpan"/> and a <see cref="FluentTimeSpan"/> are not equal. |
| | | 166 | | /// </summary> |
| | 3 | 167 | | public static bool operator !=(TimeSpan left, FluentTimeSpan right) => !(left == right); |
| | | 168 | | |
| | | 169 | | /// <summary> |
| | | 170 | | /// Determines whether a <see cref="FluentTimeSpan"/> and a <see cref="TimeSpan"/> are not equal. |
| | | 171 | | /// </summary> |
| | 3 | 172 | | public static bool operator !=(FluentTimeSpan left, TimeSpan right) => !(left == right); |
| | | 173 | | |
| | | 174 | | /// <summary> |
| | | 175 | | /// Returns the negation of the specified fluent timespan. |
| | | 176 | | /// </summary> |
| | 9 | 177 | | public static FluentTimeSpan operator -(FluentTimeSpan value) => value.Negate(); |
| | | 178 | | |
| | | 179 | | /// <summary> |
| | | 180 | | /// Less-than comparison between two fluent timespans using their <see cref="TimeSpan"/> representation. |
| | | 181 | | /// </summary> |
| | 3 | 182 | | public static bool operator <(FluentTimeSpan left, FluentTimeSpan right) => (TimeSpan)left < (TimeSpan)right; |
| | | 183 | | |
| | | 184 | | /// <summary> |
| | | 185 | | /// Less-than comparison between a fluent timespan and a <see cref="TimeSpan"/>. |
| | | 186 | | /// </summary> |
| | 3 | 187 | | public static bool operator <(FluentTimeSpan left, TimeSpan right) => (TimeSpan)left < right; |
| | | 188 | | |
| | | 189 | | /// <summary> |
| | | 190 | | /// Less-than comparison between a <see cref="TimeSpan"/> and a fluent timespan. |
| | | 191 | | /// </summary> |
| | 3 | 192 | | public static bool operator <(TimeSpan left, FluentTimeSpan right) => left < (TimeSpan)right; |
| | | 193 | | |
| | | 194 | | /// <summary> |
| | | 195 | | /// Less-than-or-equal comparison between two fluent timespans. |
| | | 196 | | /// </summary> |
| | 3 | 197 | | public static bool operator <=(FluentTimeSpan left, FluentTimeSpan right) => (TimeSpan)left <= (TimeSpan)right; |
| | | 198 | | |
| | | 199 | | /// <summary> |
| | | 200 | | /// Less-than-or-equal comparison between a fluent timespan and a <see cref="TimeSpan"/>. |
| | | 201 | | /// </summary> |
| | 3 | 202 | | public static bool operator <=(FluentTimeSpan left, TimeSpan right) => (TimeSpan)left <= right; |
| | | 203 | | |
| | | 204 | | /// <summary> |
| | | 205 | | /// Less-than-or-equal comparison between a <see cref="TimeSpan"/> and a fluent timespan. |
| | | 206 | | /// </summary> |
| | 3 | 207 | | public static bool operator <=(TimeSpan left, FluentTimeSpan right) => left <= (TimeSpan)right; |
| | | 208 | | |
| | | 209 | | /// <summary> |
| | | 210 | | /// Greater-than comparison between two fluent timespans. |
| | | 211 | | /// </summary> |
| | 3 | 212 | | public static bool operator >(FluentTimeSpan left, FluentTimeSpan right) => (TimeSpan)left > (TimeSpan)right; |
| | | 213 | | |
| | | 214 | | /// <summary> |
| | | 215 | | /// Greater-than comparison between a fluent timespan and a <see cref="TimeSpan"/>. |
| | | 216 | | /// </summary> |
| | 3 | 217 | | public static bool operator >(FluentTimeSpan left, TimeSpan right) => (TimeSpan)left > right; |
| | | 218 | | |
| | | 219 | | /// <summary> |
| | | 220 | | /// Greater-than comparison between a <see cref="TimeSpan"/> and a fluent timespan. |
| | | 221 | | /// </summary> |
| | 3 | 222 | | public static bool operator >(TimeSpan left, FluentTimeSpan right) => left > (TimeSpan)right; |
| | | 223 | | |
| | | 224 | | /// <summary> |
| | | 225 | | /// Greater-than-or-equal comparison between two fluent timespans. |
| | | 226 | | /// </summary> |
| | 3 | 227 | | public static bool operator >=(FluentTimeSpan left, FluentTimeSpan right) => (TimeSpan)left >= (TimeSpan)right; |
| | | 228 | | |
| | | 229 | | /// <summary> |
| | | 230 | | /// Greater-than-or-equal comparison between a fluent timespan and a <see cref="TimeSpan"/>. |
| | | 231 | | /// </summary> |
| | 3 | 232 | | public static bool operator >=(FluentTimeSpan left, TimeSpan right) => (TimeSpan)left >= right; |
| | | 233 | | |
| | | 234 | | /// <summary> |
| | | 235 | | /// Greater-than-or-equal comparison between a <see cref="TimeSpan"/> and a fluent timespan. |
| | | 236 | | /// </summary> |
| | 3 | 237 | | public static bool operator >=(TimeSpan left, FluentTimeSpan right) => left >= (TimeSpan)right; |
| | | 238 | | |
| | | 239 | | /// <summary> |
| | | 240 | | /// Creates a <see cref="FluentTimeSpan"/> from a <see cref="TimeSpan"/>. |
| | | 241 | | /// </summary> |
| | | 242 | | /// <param name="timeSpan">The <see cref="TimeSpan"/> to convert.</param> |
| | | 243 | | /// <returns>A fluent timespan representing the same duration (no months/years component).</returns> |
| | 0 | 244 | | public static FluentTimeSpan ToFluentTimeSpan(TimeSpan timeSpan) => new() { TimeSpan = timeSpan }; |
| | | 245 | | |
| | | 246 | | /// <summary> |
| | | 247 | | /// Converts a <see cref="FluentTimeSpan"/> into a <see cref="TimeSpan"/> taking months and years into account |
| | | 248 | | /// (months = 30 days, years = 365 days). |
| | | 249 | | /// </summary> |
| | | 250 | | /// <param name="fluentTimeSpan">The fluent timespan to convert.</param> |
| | | 251 | | /// <returns>The equivalent <see cref="TimeSpan"/>.</returns> |
| | | 252 | | public static TimeSpan FromFluentTimeSpan(FluentTimeSpan fluentTimeSpan) |
| | | 253 | | { |
| | 0 | 254 | | var daysFromYears = DaysPerYear * fluentTimeSpan.Years; |
| | 0 | 255 | | var daysFromMonths = 30 * fluentTimeSpan.Months; |
| | 0 | 256 | | var days = daysFromMonths + daysFromYears; |
| | 0 | 257 | | return new TimeSpan(days, 0, 0, 0) + fluentTimeSpan.TimeSpan; |
| | | 258 | | } |
| | | 259 | | |
| | | 260 | | /// <summary> |
| | | 261 | | /// Adds another fluent timespan to this instance. |
| | | 262 | | /// </summary> |
| | | 263 | | /// <param name="number">The fluent timespan to add.</param> |
| | 3 | 264 | | public FluentTimeSpan Add(FluentTimeSpan number) => AddInternal(this, number); |
| | | 265 | | |
| | | 266 | | /// <summary> |
| | | 267 | | /// Adds a <see cref="TimeSpan"/> to this fluent timespan. |
| | | 268 | | /// </summary> |
| | | 269 | | /// <param name="timeSpan">The TimeSpan to add.</param> |
| | 6 | 270 | | public FluentTimeSpan Add(TimeSpan timeSpan) => AddInternal(this, timeSpan); |
| | | 271 | | |
| | | 272 | | /// <summary> |
| | | 273 | | /// Subtracts the specified fluent timespan from this instance. |
| | | 274 | | /// </summary> |
| | | 275 | | /// <param name="fluentTimeSpan">The fluent timespan to subtract.</param> |
| | 3 | 276 | | public FluentTimeSpan Subtract(FluentTimeSpan fluentTimeSpan) => SubtractInternal(this, fluentTimeSpan); |
| | | 277 | | |
| | | 278 | | /// <summary> |
| | | 279 | | /// Subtracts the specified <see cref="TimeSpan"/> from this fluent timespan. |
| | | 280 | | /// </summary> |
| | | 281 | | /// <param name="timeSpan">The TimeSpan to subtract.</param> |
| | 0 | 282 | | public FluentTimeSpan Subtract(TimeSpan timeSpan) => SubtractInternal(this, timeSpan); |
| | | 283 | | |
| | | 284 | | /// <summary> |
| | | 285 | | /// Compares this fluent timespan to a <see cref="TimeSpan"/> using the converted value. |
| | | 286 | | /// </summary> |
| | 9 | 287 | | public int CompareTo(TimeSpan other) => ((TimeSpan)this).CompareTo(other); |
| | | 288 | | |
| | | 289 | | /// <summary> |
| | | 290 | | /// Compares this fluent timespan to an object that must be a <see cref="TimeSpan"/>. |
| | | 291 | | /// </summary> |
| | 9 | 292 | | public int CompareTo(object value) => value is TimeSpan timeSpan |
| | 9 | 293 | | ? ((TimeSpan)this).CompareTo(timeSpan) |
| | 9 | 294 | | : throw new ArgumentException("Value must be a TimeSpan", nameof(value)); |
| | | 295 | | |
| | | 296 | | /// <summary> |
| | | 297 | | /// Compares this fluent timespan to another fluent timespan. |
| | | 298 | | /// </summary> |
| | 9 | 299 | | public int CompareTo(FluentTimeSpan other) => ((TimeSpan)this).CompareTo(other); |
| | | 300 | | |
| | | 301 | | /// <summary> |
| | | 302 | | /// Returns a new fluent timespan that represents the negation of this instance. |
| | | 303 | | /// </summary> |
| | 9 | 304 | | public TimeSpan Negate() => new FluentTimeSpan |
| | 9 | 305 | | { |
| | 9 | 306 | | TimeSpan = -TimeSpan, |
| | 9 | 307 | | Months = -Months, |
| | 9 | 308 | | Years = -Years |
| | 9 | 309 | | }; |
| | | 310 | | |
| | | 311 | | /// <summary> |
| | | 312 | | /// Creates a new object that is a copy of the current instance. |
| | | 313 | | /// </summary> |
| | | 314 | | /// <returns>A copy of this instance.</returns> |
| | 3 | 315 | | public object Clone() => new FluentTimeSpan |
| | 3 | 316 | | { |
| | 3 | 317 | | TimeSpan = TimeSpan, |
| | 3 | 318 | | Months = Months, |
| | 3 | 319 | | Years = Years |
| | 3 | 320 | | }; |
| | | 321 | | |
| | | 322 | | /// <inheritdoc /> |
| | 3 | 323 | | public override string ToString() => ((TimeSpan)this).ToString(); |
| | | 324 | | |
| | | 325 | | /// <summary> |
| | | 326 | | /// Determines whether the specified fluent timespan is equal to the current instance. |
| | | 327 | | /// </summary> |
| | 243 | 328 | | public bool Equals(FluentTimeSpan other) => this == other; |
| | | 329 | | |
| | | 330 | | /// <inheritdoc /> |
| | | 331 | | public override bool Equals(object? obj) |
| | | 332 | | { |
| | 12 | 333 | | if (obj == null) |
| | 3 | 334 | | return false; |
| | 9 | 335 | | var type = obj.GetType(); |
| | 9 | 336 | | return type == typeof(FluentTimeSpan) ? this == (FluentTimeSpan)obj : type == typeof(TimeSpan) && this == (TimeS |
| | | 337 | | } |
| | | 338 | | |
| | | 339 | | /// <inheritdoc /> |
| | 3 | 340 | | public override int GetHashCode() => Months.GetHashCode() ^ Years.GetHashCode() ^ TimeSpan.GetHashCode(); |
| | | 341 | | |
| | | 342 | | /// <summary> |
| | | 343 | | /// Subtracts a <see cref="FluentTimeSpan"/> from a <see cref="TimeSpan"/> by negating the months and years componen |
| | | 344 | | /// </summary> |
| | | 345 | | /// <param name="left">The TimeSpan from which to subtract.</param> |
| | | 346 | | /// <param name="right">The FluentTimeSpan to subtract.</param> |
| | | 347 | | /// <returns>A new FluentTimeSpan representing the result of the subtraction.</returns> |
| | 9 | 348 | | internal static FluentTimeSpan SubtractInternal(TimeSpan left, FluentTimeSpan right) => new() |
| | 9 | 349 | | { |
| | 9 | 350 | | Months = -right.Months, |
| | 9 | 351 | | Years = -right.Years, |
| | 9 | 352 | | TimeSpan = left - right.TimeSpan |
| | 9 | 353 | | }; |
| | | 354 | | |
| | | 355 | | /// <summary> |
| | | 356 | | /// Adds a <see cref="TimeSpan"/> to a <see cref="FluentTimeSpan"/> by adding the TimeSpan components and keeping th |
| | | 357 | | /// </summary> |
| | | 358 | | /// <param name="left">The FluentTimeSpan to which to add.</param> |
| | | 359 | | /// <param name="right">The TimeSpan to add.</param> |
| | | 360 | | /// <returns>A new FluentTimeSpan representing the result of the addition.</returns> |
| | 12 | 361 | | private static FluentTimeSpan AddInternal(FluentTimeSpan left, TimeSpan right) => left with { TimeSpan = left.TimeSp |
| | | 362 | | |
| | | 363 | | /// <summary> |
| | | 364 | | /// Adds two <see cref="FluentTimeSpan"/> instances by adding their months, years, and TimeSpan components together. |
| | | 365 | | /// </summary> |
| | | 366 | | /// <param name="left">The first FluentTimeSpan to add.</param> |
| | | 367 | | /// <param name="right">The second FluentTimeSpan to add.</param> |
| | | 368 | | /// <returns>A new FluentTimeSpan representing the result of the addition.</returns> |
| | 18 | 369 | | private static FluentTimeSpan AddInternal(FluentTimeSpan left, FluentTimeSpan right) => new() |
| | 18 | 370 | | { |
| | 18 | 371 | | Years = left.Years + right.Years, |
| | 18 | 372 | | Months = left.Months + right.Months, |
| | 18 | 373 | | TimeSpan = left.TimeSpan + right.TimeSpan |
| | 18 | 374 | | }; |
| | | 375 | | |
| | | 376 | | /// <summary> |
| | | 377 | | /// Subtracts a <see cref="TimeSpan"/> from a <see cref="FluentTimeSpan"/> by subtracting the TimeSpan components an |
| | | 378 | | /// </summary> |
| | | 379 | | /// <param name="left">The FluentTimeSpan from which to subtract.</param> |
| | | 380 | | /// <param name="right">The TimeSpan to subtract.</param> |
| | | 381 | | /// <returns>A new FluentTimeSpan representing the result of the subtraction.</returns> |
| | 6 | 382 | | private static FluentTimeSpan SubtractInternal(FluentTimeSpan left, TimeSpan right) => left with { TimeSpan = left.T |
| | | 383 | | |
| | | 384 | | /// <summary> |
| | | 385 | | /// Subtracts two <see cref="FluentTimeSpan"/> instances by subtracting their months, years, and TimeSpan components |
| | | 386 | | /// </summary> |
| | | 387 | | /// <param name="left">The first FluentTimeSpan to subtract.</param> |
| | | 388 | | /// <param name="right">The second FluentTimeSpan to subtract.</param> |
| | | 389 | | /// <returns>A new FluentTimeSpan representing the result of the subtraction.</returns> |
| | 9 | 390 | | private static FluentTimeSpan SubtractInternal(FluentTimeSpan left, FluentTimeSpan right) => new() |
| | 9 | 391 | | { |
| | 9 | 392 | | Years = left.Years - right.Years, |
| | 9 | 393 | | Months = left.Months - right.Months, |
| | 9 | 394 | | TimeSpan = left.TimeSpan - right.TimeSpan |
| | 9 | 395 | | }; |
| | | 396 | | } |
| | | 397 | | |