Skip to content

Commit 1611d06

Browse files
committed
refactor(GitVersion.Configuration): add BeforeString to avoid serializing Nullable<DateTimeOffset>
Nullable types seem to ignore the types' built-in JSON converters i.e. DateTimeOffset <=> string, but DateTimeOffset? <=> object or null
1 parent 0e68314 commit 1611d06

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/GitVersion.Configuration/IgnoreConfiguration.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ namespace GitVersion.Configuration;
44

55
internal record IgnoreConfiguration : IIgnoreConfiguration
66
{
7+
[JsonIgnore]
8+
public DateTimeOffset? Before { get; init; }
9+
710
[JsonPropertyName("commits-before")]
811
[JsonPropertyDescription("Commits before this date will be ignored. Format: yyyy-MM-ddTHH:mm:ss.")]
912
[JsonPropertyFormat(Format.DateTime)]
10-
public DateTimeOffset? Before { get; init; }
13+
public string? BeforeString
14+
{
15+
get => Before?.ToString("yyyy-MM-ddTHH:mm:ssZ");
16+
// if TryParse returns false, Before = null and the parse error is suppressed. How should the user be informed of parse errors?
17+
init => Before = value is null ? null : DateTimeOffset.TryParse(value, out DateTimeOffset dto) ? dto : null;
18+
}
1119

1220
[JsonIgnore]
1321
IReadOnlyCollection<string> IIgnoreConfiguration.Shas => Shas;

0 commit comments

Comments
 (0)