Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EdifactFormatVersion.FV2410 and EdifactFormatVersion.FV2504 #167

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions EDILibrary/EdifactFormatVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ public enum EdifactFormatVersion
/// Format Version April 2024
/// </summary>
FV2404,

/// <summary>
/// Format Version valid since October 2024
/// </summary>
FV2410,

/// <summary>
/// Format Version valid since April 2025
/// </summary>
FV2504
}

public class EdifactFormatVersionComparer : IComparer<EdifactFormatVersion>
Expand Down Expand Up @@ -239,6 +249,8 @@ public static string ToLegacyVersionString(this EdifactFormatVersion edifactForm
EdifactFormatVersion.FV2304 => "04/23",
EdifactFormatVersion.FV2310 => "10/23",
EdifactFormatVersion.FV2404 => "04/24",
EdifactFormatVersion.FV2410 => "10/24",
EdifactFormatVersion.FV2504 => "04/25",
_ => throw new NotImplementedException($"The legacy format for {edifactFormatVersion} is not yet implemented.")
};
}
Expand Down Expand Up @@ -368,8 +380,29 @@ public class EdifactFormatVersionHelper : IEdifactFormatVersionProvider
/// </summary>
/// <remarks>Note that this is _not_ April 1st</remarks>
private static readonly DateTime KeyDate2404 = new(2024, 04, 02, 22, 0, 0, DateTimeKind.Utc);

/// <summary>
/// validity date of <see cref="EdifactFormatVersion.FV2410"/>
/// </summary>
private static readonly DateTime KeyDate2410 = new(2024, 09, 30, 22, 0, 0, DateTimeKind.Utc);

/// <summary>
/// validity date of <see cref="EdifactFormatVersion.FV2504"/>
/// </summary>
/// <remarks>Note that this is _not_ April 1st</remarks>
private static readonly DateTime KeyDate2504 = new(2025, 04, 03, 22, 0, 0, DateTimeKind.Utc);


public EdifactFormatVersion GetFormatVersion(DateTimeOffset keydate)
{
if (keydate >= KeyDate2504)
{
return EdifactFormatVersion.FV2504;
}
if (keydate >= KeyDate2410)
{
return EdifactFormatVersion.FV2410;
}
if (keydate >= KeyDate2404)
{
return EdifactFormatVersion.FV2404;
Expand Down
27 changes: 18 additions & 9 deletions EDILibraryTests/EdifactFormatVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public void TestFormatVersionOrder()
EdifactFormatVersion.FV2304,
EdifactFormatVersion.FV2310,
EdifactFormatVersion.FV2404,
EdifactFormatVersion.FV2410,
EdifactFormatVersion.FV2504,
};
var comparer = new EdifactFormatVersionComparer();
for (int i = 0; i < expectedNaturalOrder.Count - 1; i++)
Expand Down Expand Up @@ -111,6 +113,8 @@ public void UnmappedThrowsNotImplemented()
[DataRow("FV1710", EdifactFormatVersion.FV1710)]
[DataRow("FV2404", EdifactFormatVersion.FV2404)]
[DataRow("04/24", EdifactFormatVersion.FV2404)]
[DataRow("10/24", EdifactFormatVersion.FV2410)]
[DataRow("04/25", EdifactFormatVersion.FV2504)]
public void TestLegacyStrings(string legacyString, EdifactFormatVersion expectedFormatVersion)
{
var actualFormatVersion = legacyString.ToEdifactFormatVersion();
Expand Down Expand Up @@ -150,17 +154,22 @@ public void TestMockingVersionProvider()
/// Test that the <see cref="EdifactFormatVersionHelper"/> returns <see cref="EdifactFormatVersion.FV2110"/> in for 2021-10-01&lt;=dt&lt;2022-10-01 (german local time)
/// </summary>
[TestMethod]
public void TestFV2110()
[DataRow("2021-09-30T21:59:59+00:00", EdifactFormatVersion.FV2104)]
[DataRow("2021-09-30T22:00:00+00:00", EdifactFormatVersion.FV2110)]
[DataRow("2022-03-31T22:00:00+00:00", EdifactFormatVersion.FV2110)]
[DataRow("2022-09-30T21:59:59+00:00", EdifactFormatVersion.FV2110)]
[DataRow("2022-09-30T22:00:00+00:00", EdifactFormatVersion.FV2210)]
[DataRow("2023-09-30T22:00:00+00:00", EdifactFormatVersion.FV2310)]
[DataRow("2024-03-31T22:00:00+00:00", EdifactFormatVersion.FV2310)]
[DataRow("2024-04-02T22:00:00+00:00", EdifactFormatVersion.FV2404)]
[DataRow("2024-09-30T22:00:00+00:00", EdifactFormatVersion.FV2410)]
[DataRow("2025-03-31T22:00:00+00:00", EdifactFormatVersion.FV2410)]
[DataRow("2025-04-03T22:00:00+00:00", EdifactFormatVersion.FV2504)]
public void TestFormatVersionProvider(string dateTimeOffset, EdifactFormatVersion expectedVersion)
{
IEdifactFormatVersionProvider versionProvider = new EdifactFormatVersionHelper();
Assert.AreEqual(EdifactFormatVersion.FV2104, versionProvider.GetFormatVersion(new DateTimeOffset(2021, 9, 30, 21, 59, 59, TimeSpan.Zero)));
Assert.AreEqual(EdifactFormatVersion.FV2110, versionProvider.GetFormatVersion(new DateTimeOffset(2021, 9, 30, 22, 0, 0, TimeSpan.Zero)));
Assert.AreEqual(EdifactFormatVersion.FV2110, versionProvider.GetFormatVersion(new DateTimeOffset(2022, 3, 31, 22, 0, 0, TimeSpan.Zero)));
Assert.AreEqual(EdifactFormatVersion.FV2110, versionProvider.GetFormatVersion(new DateTimeOffset(2022, 9, 30, 21, 59, 59, TimeSpan.Zero)));
Assert.AreEqual(EdifactFormatVersion.FV2210, versionProvider.GetFormatVersion(new DateTimeOffset(2022, 9, 30, 22, 0, 0, TimeSpan.Zero)));
Assert.AreEqual(EdifactFormatVersion.FV2310, versionProvider.GetFormatVersion(new DateTimeOffset(2023, 9, 30, 22, 0, 0, TimeSpan.Zero)));
Assert.AreEqual(EdifactFormatVersion.FV2310, versionProvider.GetFormatVersion(new DateTimeOffset(2024, 3, 31, 22, 0, 0, TimeSpan.Zero)));
Assert.AreEqual(EdifactFormatVersion.FV2404, versionProvider.GetFormatVersion(new DateTimeOffset(2024, 4, 2, 22, 0, 0, TimeSpan.Zero)));
DateTimeOffset date = DateTimeOffset.Parse(dateTimeOffset);
Assert.AreEqual(expectedVersion, versionProvider.GetFormatVersion(date));
}
}
}
Loading