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