Skip to content

Commit 66fe10b

Browse files
committed
feat: Improve UTC date string parsing in tests
1 parent b99178e commit 66fe10b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/GitVersion.Core.Tests/Formatting/DateFormatterTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@ public void TryFormat_NullValue_ReturnsFalse()
2222
[TestCase("2021-01-01T12:00:00Z", "yyyy-MM-ddTHH:mm:ssZ", "2021-01-01T12:00:00Z")]
2323
public void TryFormat_ValidDateFormats_ReturnsExpectedResult(string input, string format, string expected)
2424
{
25-
var date = DateTime.Parse(input, CultureInfo.InvariantCulture);
25+
// For UTC datetime strings, parse as UTC to ensure consistent behavior across timezones
26+
DateTime date;
27+
if (input.EndsWith("Z"))
28+
{
29+
date = DateTime.Parse(input, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
30+
}
31+
else
32+
{
33+
date = DateTime.Parse(input, CultureInfo.InvariantCulture);
34+
}
35+
2636
var sut = new DateFormatter();
2737
var result = sut.TryFormat(date, format, out var formatted);
2838
result.ShouldBeTrue();

0 commit comments

Comments
 (0)