Skip to content

Commit

Permalink
Montspan subtract improvement (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel committed Mar 11, 2024
1 parent 1cfaf58 commit 656aef7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions specs/Qowaiv.Specs/Month_span_specs.cs
Expand Up @@ -92,6 +92,7 @@ public void decrement()

public class Can_subtract
{
[TestCase("2020-04-30", "1710-02-01", "310Y+2M")]
[TestCase("2020-04-30", "2020-04-01", 00)]
[TestCase("2020-04-30", "2020-03-31", 01)]
[TestCase("2020-01-01", "2019-01-02", 11)]
Expand All @@ -102,6 +103,7 @@ public void two_dates(Date d1, Date d2, MonthSpan expected)
=> MonthSpan.Subtract(d1, d2).Should().Be(expected);

#if NET6_0_OR_GREATER
[TestCase("2020-04-30", "1710-02-01", "310Y+2M")]
[TestCase("2020-04-30", "2020-04-01", 00)]
[TestCase("2020-04-30", "2020-03-31", 01)]
[TestCase("2020-01-01", "2019-01-02", 11)]
Expand Down
3 changes: 2 additions & 1 deletion src/Qowaiv.TestTools/SerializationWrapper.cs
Expand Up @@ -3,10 +3,11 @@
/// <summary>Wrapper used by <see cref="Serialize.Xml{T}(T)"/>
/// and <see cref="SerializeDeserialize.Xml{T}(T)"/>.
/// </summary>
[Mutable]
[Serializable]
[XmlRoot("Wrapper")]
public sealed class SerializationWrapper<T>
{
/// <summary>The generic part of the wrapper.</summary>
public T? Value { get; init; }
public T? Value { get; set; }
}
7 changes: 4 additions & 3 deletions src/Qowaiv.TestTools/XmlStructure.TSvo.cs
@@ -1,19 +1,20 @@
namespace Qowaiv.TestTools;

/// <summary>A test structure to test <see cref="IXmlSerializable"/> behavior of SVO's.</summary>
[Mutable]
[Serializable]
public sealed class XmlStructure<TSvo>
: IEquatable<XmlStructure<TSvo>>
where TSvo : struct
{
/// <summary>Gets and sets int property.</summary>
public int Id { get; init; } = 17;
public int Id { get; set; } = 17;

/// <summary>Gets and sets SVO property.</summary>
public TSvo Svo { get; init; }
public TSvo Svo { get; set; }

/// <summary>Gets and sets a date (time) property.</summary>
public DateTime Date { get; init; } = new DateTime(2017, 06, 11, 00, 00, 000, DateTimeKind.Utc);
public DateTime Date { get; set; } = new DateTime(2017, 06, 11, 00, 00, 000, DateTimeKind.Utc);

/// <inheritdoc />
[Pure]
Expand Down
8 changes: 4 additions & 4 deletions src/Qowaiv/MonthSpan.cs
Expand Up @@ -332,13 +332,13 @@ public static MonthSpan Subtract(Date d1, Date d2)

if (negative)
{
max = d2;
min = d1;
(min, max) = (max, min);
}

var test = min;
var years = Math.Max(0, max.Year - min.Year - 1);
var months = years * 12;

var months = 0;
var test = min.AddYears(years);

while (test < max)
{
Expand Down

0 comments on commit 656aef7

Please sign in to comment.