Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
ensures consistent date parsing
Uses `CultureInfo.InvariantCulture` for date parsing in tests to avoid locale-specific issues.
  • Loading branch information
arturcic committed Aug 9, 2025
commit 27ef7096752c4b5ee2bf7a550e0736a12523cd10
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Formatting;

Expand Down Expand Up @@ -261,7 +262,7 @@ public void FormatAssemblyInformationalVersionWithSemanticVersionCustomFormatted
Sha = "commitSha",
ShortSha = "commitShortSha",
CommitsSinceVersionSource = 42,
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture)
}
};
const string target = "{Major}.{Minor}.{Patch}-{CommitsSinceVersionSource:0000}";
Expand Down
5 changes: 3 additions & 2 deletions src/GitVersion.Core.Tests/Formatting/DateFormatterTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GitVersion.Formatting;
using System.Globalization;
using GitVersion.Formatting;

namespace GitVersion.Tests.Formatting;

Expand All @@ -21,7 +22,7 @@ public void TryFormat_NullValue_ReturnsFalse()
[TestCase("2021-01-01T12:00:00Z", "yyyy-MM-ddTHH:mm:ssZ", "2021-01-01T12:00:00Z")]
public void TryFormat_ValidDateFormats_ReturnsExpectedResult(string input, string format, string expected)
{
var date = DateTime.Parse(input);
var date = DateTime.Parse(input, CultureInfo.InvariantCulture);
var sut = new DateFormatter();
var result = sut.TryFormat(date, format, out var formatted);
result.ShouldBeTrue();
Expand Down
6 changes: 3 additions & 3 deletions src/GitVersion.Core.Tests/Formatting/ValueFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void TryFormat_Number_UsesNumericFormatter()
[Test]
public void TryFormat_Date_UsesDateFormatter()
{
var date = new DateTime(2023, 12, 25);
var date = new DateTime(2023, 12, 25, 0, 0, 0, DateTimeKind.Utc);
var result = ValueFormatter.Default.TryFormat(date, "yyyy-MM-dd", out var formatted);
result.ShouldBeTrue();
formatted.ShouldBe("2023-12-25");
Expand All @@ -42,7 +42,7 @@ public void TryFormat_Date_UsesDateFormatter()
[Test]
public void TryFormat_FormattableObject_UsesFormattableFormatter()
{
var value = 123.456m;
const decimal value = 123.456m;
var result = ValueFormatter.Default.TryFormat(value, "C", out var formatted);
result.ShouldBeTrue();
formatted.ShouldBe("¤123.46");
Expand Down Expand Up @@ -106,7 +106,7 @@ public void Formatters_ExecuteInPriorityOrder()
formatted.ShouldBe("CUSTOM:test");
}

private class TestFormatter : IValueFormatter
private sealed class TestFormatter : IValueFormatter
{
public int Priority { get; init; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using GitVersion.Configuration;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Git;
Expand Down Expand Up @@ -301,7 +302,7 @@ public void Format_Allows_CSharp_FormatStrings()
Sha = "commitSha",
ShortSha = "commitShortSha",
CommitsSinceVersionSource = 42,
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z", CultureInfo.InvariantCulture)
}
};

Expand Down