Skip to content

Commit

Permalink
Revert "Add date kind and offset options (#683)"
Browse files Browse the repository at this point in the history
This reverts commit ac5e7e4.
  • Loading branch information
SimonCropp committed Oct 23, 2022
1 parent ac5e7e4 commit 80c5248
Show file tree
Hide file tree
Showing 33 changed files with 60 additions and 229 deletions.
4 changes: 2 additions & 2 deletions docs/serializer-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -1534,8 +1534,8 @@ The default mapping is:
{typeof(float), (target, _) => ((float) target).ToString(CultureInfo.InvariantCulture)},
{typeof(double), (target, _) => ((double) target).ToString(CultureInfo.InvariantCulture)},
{typeof(Guid), (target, _) => ((Guid) target).ToString()},
{typeof(DateTime), (target, settings) => DateFormatter.ToJsonString((DateTime) target, settings.IsIncludeDateKind)},
{typeof(DateTimeOffset), (target, settings) => DateFormatter.ToJsonString((DateTimeOffset) target, settings.IsIncludeDateOffset)},
{typeof(DateTime), (target, _) => DateFormatter.ToJsonString((DateTime) target)},
{typeof(DateTimeOffset), (target, _) => DateFormatter.ToJsonString((DateTimeOffset) target)},
{
typeof(XmlNode), (target, _) =>
{
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649;xUnit1026;xUnit1013;msb3277;CS0436;CS1573</NoWarn>
<Version>18.0.0-beta.33</Version>
<Version>18.0.0-beta.32</Version>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2000-10-01

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2000-10-01

This file was deleted.

106 changes: 45 additions & 61 deletions src/Verify.Tests/DateFormatterTests.cs
Original file line number Diff line number Diff line change
@@ -1,103 +1,87 @@
[UsesVerify]
public class DateFormatterTests
{
[Theory]
[InlineData(true)]
[InlineData(false)]
public Task DateTimeOtherTimeZoneToJsonString(bool offset)
[Fact]
public Task DateTimeOtherTimeZoneToJsonString()
{
var date = new DateTimeOffset(2000, 10, 1, 0, 0, 0, TimeSpan.FromHours(1.5));
return Verify(DateFormatter.ToJsonString(date, offset))
.UseParameters( offset);
return Verify(DateFormatter.ToJsonString(date));
}

[Theory]
[InlineData( true)]
[InlineData( false)]
public Task DateTimeOtherTimeZoneToParameterString(bool offset)
[Fact]
public Task DateTimeOtherTimeZoneToParameterString()
{
var date = new DateTimeOffset(2000, 10, 1, 0, 0, 0, TimeSpan.FromHours(1.5));
return Verify(DateFormatter.ToParameterString(date, offset))
.UseParameters(offset);
return Verify(DateFormatter.ToParameterString(date));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public Task DateTimeLocalToJsonString(bool kind)
[Fact]
public Task DateTimeLocalToJsonString()
{
var date = new DateTime(2000, 10, 1, 0, 0, 0, DateTimeKind.Local);
return Verify(DateFormatter.ToJsonString(date, kind))
.UseParameters(kind);
return Verify(DateFormatter.ToJsonString(date));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public Task DateTimeLocalToParameterString(bool kind)
[Fact]
public Task DateTimeLocalToParameterString()
{
var date = new DateTime(2000, 10, 1, 0, 0, 0, DateTimeKind.Local);
return Verify(DateFormatter.ToParameterString(date, kind))
.UseParameters(kind);
return Verify(DateFormatter.ToParameterString(date));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public Task DateTimeUnspecifiedToJsonString(bool kind)
[Fact]
public Task DateTimeOffsetLocalToJsonString()
{
var date = new DateTimeOffset(2000, 10, 1, 0, 0, 0, DateTimeOffset.Now.Offset);
return Verify(DateFormatter.ToJsonString(date));
}

[Fact]
public Task DateTimeOffsetLocalToParameterString()
{
var date = new DateTimeOffset(2000, 10, 1, 0, 0, 0, DateTimeOffset.Now.Offset);
return Verify(DateFormatter.ToParameterString(date));
}

[Fact]
public Task DateTimeUnspecifiedToJsonString()
{
var date = new DateTime(2000, 10, 1, 0, 0, 0);
return Verify(DateFormatter.ToJsonString(date, kind))
.UseParameters(kind);
return Verify(DateFormatter.ToJsonString(date));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public Task DateTimeUnspecifiedToParameterString(bool kind)
[Fact]
public Task DateTimeUnspecifiedToParameterString()
{
var date = new DateTime(2000, 10, 1, 0, 0, 0, DateTimeKind.Unspecified);
return Verify(DateFormatter.ToParameterString(date, kind))
.UseParameters(kind);
var date = new DateTime(2000, 10, 1, 0, 0, 0);
return Verify(DateFormatter.ToParameterString(date));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public Task DateTimeUtcToJsonString(bool kind)
[Fact]
public Task DateTimeUtcToJsonString()
{
var date = new DateTime(2000, 10, 1, 0, 0, 0, DateTimeKind.Utc);
return Verify(DateFormatter.ToJsonString(date, kind))
.UseParameters(kind);
return Verify(DateFormatter.ToJsonString(date));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public Task DateTimeUtcToParameterString(bool kind)
[Fact]
public Task DateTimeUtcToParameterString()
{
var date = new DateTime(2000, 10, 1, 0, 0, 0, DateTimeKind.Utc);
return Verify(DateFormatter.ToParameterString(date, kind))
.UseParameters(kind);
return Verify(DateFormatter.ToParameterString(date));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public Task DateTimeOffsetUtcToJsonString(bool offset)
[Fact]
public Task DateTimeOffsetUtcToJsonString()
{
var date = new DateTimeOffset(2000, 10, 1, 0, 0, 0, TimeSpan.Zero);
return Verify(DateFormatter.ToJsonString(date, offset))
.UseParameters(offset);
return Verify(DateFormatter.ToJsonString(date));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public Task DateTimeOffsetUtcToParameterString(bool offset)
[Fact]
public Task DateTimeOffsetUtcToParameterString()
{
var date = new DateTimeOffset(2000, 10, 1, 0, 0, 0, TimeSpan.Zero);
return Verify(DateFormatter.ToParameterString(date, offset))
.UseParameters(offset);
return Verify(DateFormatter.ToParameterString(date));
}
}
4 changes: 0 additions & 4 deletions src/Verify/IVerifySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ public interface IVerifySettings
internal IReadOnlyCollection<object?>? Parameters{ get; }

bool IgnoreParametersForVerified { get; }

bool IsIncludeDateKind { get; }

bool IsIncludeDateOffset { get; }
string? FileName { get; }
string? MethodName { get; }
string? TypeName { get; }
Expand Down
10 changes: 2 additions & 8 deletions src/Verify/Naming/VerifierSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ public static partial class VerifierSettings
#endif
{typeof(float), (_, value) => ((float) value).ToString(CultureInfo.InvariantCulture)},
{typeof(double), (_, value) => ((double) value).ToString(CultureInfo.InvariantCulture)},
{typeof(DateTime), (settings, value) =>
DateFormatter.ToParameterString(
(DateTime) value,
settings.IsIncludeDateOffset)},
{typeof(DateTimeOffset), (settings, value) =>
DateFormatter.ToParameterString(
(DateTimeOffset) value,
settings.IsIncludeDateOffset)}
{typeof(DateTime), (_, value) => DateFormatter.ToParameterString((DateTime) value)},
{typeof(DateTimeOffset), (_, value) => DateFormatter.ToParameterString((DateTimeOffset) value)}
};

public static void NameForParameter<T>(ParameterToName<T> func) =>
Expand Down
79 changes: 4 additions & 75 deletions src/Verify/Serialization/DateFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
static class DateFormatter
{
public static string ToJsonString(DateTimeOffset value, bool offset)
{
var result = GetJsonDatePart(value);
if (offset)
{
result += $" {GetDateOffset(value)}";
}

return result;
}

static string GetJsonDatePart(DateTimeOffset value)
public static string ToJsonString(DateTimeOffset value)
{
if (value.TimeOfDay == TimeSpan.Zero)
{
Expand All @@ -31,18 +20,7 @@ static string GetJsonDatePart(DateTimeOffset value)
return value.ToString("yyyy-MM-dd HH:mm:ss.FFFFFFF", CultureInfo.InvariantCulture);
}

public static string ToParameterString(DateTimeOffset value, bool offset)
{
var result = GetParameterDatePart(value);
if (offset)
{
result += GetDateOffset(value);
}

return result;
}

static string GetParameterDatePart(DateTimeOffset value)
public static string ToParameterString(DateTimeOffset value)
{
if (value.TimeOfDay == TimeSpan.Zero)
{
Expand All @@ -62,19 +40,7 @@ static string GetParameterDatePart(DateTimeOffset value)
return value.ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFF", CultureInfo.InvariantCulture);
}

public static string ToJsonString(DateTime value, bool kind)
{
var result = GetJsonDatePart(value);

if (kind)
{
result += $" {value.Kind}";
}

return result;
}

static string GetJsonDatePart(DateTime value)
public static string ToJsonString(DateTime value)
{
if (value.TimeOfDay == TimeSpan.Zero)
{
Expand All @@ -94,19 +60,7 @@ static string GetJsonDatePart(DateTime value)
return value.ToString("yyyy-MM-dd HH:mm:ss.FFFFFFF", CultureInfo.InvariantCulture);
}

public static string ToParameterString(DateTime value, bool kind)
{
var result = GetParameterDatePart(value);

if (kind)
{
result += value.Kind;
}

return result;
}

static string GetParameterDatePart(DateTime value)
public static string ToParameterString(DateTime value)
{
if (value.TimeOfDay == TimeSpan.Zero)
{
Expand All @@ -125,29 +79,4 @@ static string GetParameterDatePart(DateTime value)

return value.ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFF", CultureInfo.InvariantCulture);
}

static string GetDateOffset(DateTimeOffset value)
{
var offset = value.Offset;

if (offset > TimeSpan.Zero)
{
if(offset.Minutes == 0)
{
return $"+{offset.TotalHours:0}";
}
return $"+{offset.Hours:0}:{offset.Minutes:00}";
}

if (offset < TimeSpan.Zero)
{
if(offset.Minutes == 0)
{
return $"-{offset.Hours:0}";
}
return $"-{offset.Hours:0}:{offset.Minutes:00}";
}

return "+0";
}
}
4 changes: 2 additions & 2 deletions src/Verify/Serialization/VerifierSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public static partial class VerifierSettings
{typeof(float), (target, _) => ((float) target).ToString(CultureInfo.InvariantCulture)},
{typeof(double), (target, _) => ((double) target).ToString(CultureInfo.InvariantCulture)},
{typeof(Guid), (target, _) => ((Guid) target).ToString()},
{typeof(DateTime), (target, settings) => DateFormatter.ToJsonString((DateTime) target, settings.IsIncludeDateKind)},
{typeof(DateTimeOffset), (target, settings) => DateFormatter.ToJsonString((DateTimeOffset) target, settings.IsIncludeDateOffset)},
{typeof(DateTime), (target, _) => DateFormatter.ToJsonString((DateTime) target)},
{typeof(DateTimeOffset), (target, _) => DateFormatter.ToJsonString((DateTimeOffset) target)},
{
typeof(XmlNode), (target, _) =>
{
Expand Down
4 changes: 2 additions & 2 deletions src/Verify/Serialization/VerifyJsonWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public override void WriteValue(DateTimeOffset value)
return;
}

WriteRawValueWithScrubbers(DateFormatter.ToJsonString(value, settings.IsIncludeDateOffset));
WriteRawValueWithScrubbers(DateFormatter.ToJsonString(value));
}

public override void WriteValue(DateTime value)
Expand All @@ -121,7 +121,7 @@ public override void WriteValue(DateTime value)
return;
}

WriteRawValueWithScrubbers(DateFormatter.ToJsonString(value, settings.IsIncludeDateKind));
WriteRawValueWithScrubbers(DateFormatter.ToJsonString(value));
}

public override void WriteValue(TimeSpan value) =>
Expand Down

0 comments on commit 80c5248

Please sign in to comment.