Skip to content
Permalink
Browse files

fix about DateTime issues, 1.0.3

  • Loading branch information
neuecc committed Sep 28, 2017
1 parent 3e8f110 commit d203f37215672bc219db16f557e327d662a9195b
@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Utf8Json.AspNetCoreMvcFormatter</id>
<version>1.0.2</version>
<version>1.0.3</version>
<title>Utf8Json AspNetCoreMvcFormatter</title>
<authors>neuecc</authors>
<owners>neuecc</owners>
@@ -13,11 +13,11 @@
<tags>Json, Serialization, Formatter, Serializer, Unity, Xamarin, ASPNET</tags>
<dependencies>
<group targetFramework=".NETFramework4.7">
<dependency id="Utf8Json" version="1.0.2" exclude="Build,Analyzers" />
<dependency id="Utf8Json" version="1.0.3" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.Mvc.Abstractions" version="2.0.0" exclude="Build,Analyzers" />
</group>
<group targetFramework=".NETStandard2.0">
<dependency id="Utf8Json" version="1.0.2" exclude="Build,Analyzers" />
<dependency id="Utf8Json" version="1.0.3" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.Mvc.Abstractions" version="2.0.0" exclude="Build,Analyzers" />
</group>
</dependencies>
@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Utf8Json.ImmutableCollection</id>
<version>1.0.2</version>
<version>1.0.3</version>
<title>Utf8Json Extension Resolver for ImmutableCollection</title>
<authors>neuecc</authors>
<owners>neuecc</owners>
@@ -13,15 +13,15 @@
<tags>Json, Serialization, Formatter, Serializer, Unity, Xamarin</tags>
<dependencies>
<group targetFramework=".NETFramework4.7">
<dependency id="Utf8Json" version="1.0.2" exclude="Build,Analyzers" />
<dependency id="Utf8Json" version="1.0.3" exclude="Build,Analyzers" />
<dependency id="System.Collections.Immutable" version="1.4.0" exclude="Build,Analyzers" />
</group>
<group targetFramework=".NETFramework4.5">
<dependency id="Utf8Json" version="1.0.2" exclude="Build,Analyzers" />
<dependency id="Utf8Json" version="1.0.3" exclude="Build,Analyzers" />
<dependency id="System.Collections.Immutable" version="1.4.0" exclude="Build,Analyzers" />
</group>
<group targetFramework=".NETStandard2.0">
<dependency id="Utf8Json" version="1.0.2" exclude="Build,Analyzers" />
<dependency id="Utf8Json" version="1.0.3" exclude="Build,Analyzers" />
<dependency id="System.Collections.Immutable" version="1.4.0" exclude="Build,Analyzers" />
</group>
</dependencies>
@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Utf8Json.UnityShims</id>
<version>1.0.2</version>
<version>1.0.3</version>
<title>Utf8Json UnityShims</title>
<authors>neuecc</authors>
<owners>neuecc</owners>
@@ -13,15 +13,15 @@
<tags>Json, Serialization, Formatter, Serializer, Unity, Xamarin</tags>
<dependencies>
<group targetFramework=".NETFramework4.7">
<dependency id="Utf8Json" version="1.0.2" exclude="Build,Analyzers" />
<dependency id="Utf8Json" version="1.0.3" exclude="Build,Analyzers" />
<dependency id="System.Runtime.Serialization.Primitives" version="4.3.0" exclude="Build,Analyzers" />
</group>
<group targetFramework=".NETFramework4.5">
<dependency id="Utf8Json" version="1.0.2" exclude="Build,Analyzers" />
<dependency id="Utf8Json" version="1.0.3" exclude="Build,Analyzers" />
<dependency id="System.Runtime.Serialization.Primitives" version="4.3.0" exclude="Build,Analyzers" />
</group>
<group targetFramework=".NETStandard2.0">
<dependency id="Utf8Json" version="1.0.2" exclude="Build,Analyzers" />
<dependency id="Utf8Json" version="1.0.3" exclude="Build,Analyzers" />
<dependency id="System.Runtime.Serialization.Primitives" version="4.3.0" exclude="Build,Analyzers" />
</group>
</dependencies>
@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Utf8Json</id>
<version>1.0.2</version>
<version>1.0.3</version>
<title>Utf8Json</title>
<authors>neuecc</authors>
<owners>neuecc</owners>
@@ -1,4 +1,4 @@
nuget push Utf8Json.1.0.2.nupkg -Source https://www.nuget.org/api/v2/package
nuget push Utf8Json.ImmutableCollection.1.0.2.nupkg -Source https://www.nuget.org/api/v2/package
nuget push Utf8Json.UnityShims.1.0.2.nupkg -Source https://www.nuget.org/api/v2/package
nuget push Utf8Json.AspNetCoreMvcFormatter.1.0.2.nupkg -Source https://www.nuget.org/api/v2/package
nuget push Utf8Json.1.0.3.nupkg -Source https://www.nuget.org/api/v2/package
nuget push Utf8Json.ImmutableCollection.1.0.3.nupkg -Source https://www.nuget.org/api/v2/package
nuget push Utf8Json.UnityShims.1.0.3.nupkg -Source https://www.nuget.org/api/v2/package
nuget push Utf8Json.AspNetCoreMvcFormatter.1.0.3.nupkg -Source https://www.nuget.org/api/v2/package
@@ -11,7 +11,7 @@
<package id="Microsoft.DotNet.InternalAbstractions" version="1.0.0" targetFramework="net461" />
<package id="Microsoft.DotNet.PlatformAbstractions" version="1.1.1" targetFramework="net461" />
<package id="Microsoft.Extensions.DependencyModel" version="1.0.0" targetFramework="net461" />
<package id="Microsoft.NETCore.Platforms" version="1.0.2" targetFramework="net461" />
<package id="Microsoft.NETCore.Platforms" version="1.0.3" targetFramework="net461" />
<package id="Microsoft.Win32.Primitives" version="4.0.1" targetFramework="net461" />
<package id="Microsoft.Win32.Registry" version="4.3.0" targetFramework="net461" />
<package id="NetJSON" version="1.2.1.10" targetFramework="net461" />
@@ -49,12 +49,68 @@ class Program
{
static void Main(string[] args)
{
var f = new Foo() { MyProperty = DateTime.Now };
TestDTUtcNow();
TestDTOUtcNow();
TestDTNow();
TestDTONow();
}

static void TestDTUtcNow()
{
Console.WriteLine("DateTime.UtcNow");
var dto = DateTime.UtcNow;
var serialized = Utf8Json.JsonSerializer.ToJsonString(dto);
var deSerialized = Utf8Json.JsonSerializer.Deserialize<DateTime>(serialized);
var serialized2 = Utf8Json.JsonSerializer.ToJsonString(deSerialized);
if (serialized2 != serialized)
{
Console.WriteLine("Reference: {0:yyyy-MM-ddTHH:mm:ss.fffffffK}", dto);
Console.WriteLine("Output: {0} vs {1}", serialized, serialized2);
}
}


static void TestDTOUtcNow()
{
Console.WriteLine("DateTimeOffset.UtcNow");
var dto = DateTimeOffset.UtcNow;
var serialized = Utf8Json.JsonSerializer.ToJsonString(dto);
var deSerialized = Utf8Json.JsonSerializer.Deserialize<DateTimeOffset>(serialized);
var serialized2 = Utf8Json.JsonSerializer.ToJsonString(deSerialized);
if (serialized2 != serialized)
{
Console.WriteLine("Reference: {0:yyyy-MM-ddTHH:mm:ss.fffffffK}", dto);
Console.WriteLine("Output: {0} vs {1}", serialized, serialized2);
}
}

Console.WriteLine(JsonSerializer.ToJsonString(f));
static void TestDTNow()
{
Console.WriteLine("DateTime.Now");
var dto = DateTime.Now;
var serialized = Utf8Json.JsonSerializer.ToJsonString(dto);
var deSerialized = Utf8Json.JsonSerializer.Deserialize<DateTime>(serialized);
var serialized2 = Utf8Json.JsonSerializer.ToJsonString(deSerialized);
if (serialized2 != serialized)
{
Console.WriteLine("Reference: {0:yyyy-MM-ddTHH:mm:ss.fffffffK}", dto);
Console.WriteLine("Output: {0} vs {1}", serialized, serialized2);
}
}


static void TestDTONow()
{
Console.WriteLine("DateTimeOffset.Now");
var dto = DateTimeOffset.Now;
var serialized = Utf8Json.JsonSerializer.ToJsonString(dto);
var deSerialized = Utf8Json.JsonSerializer.Deserialize<DateTimeOffset>(serialized);
var serialized2 = Utf8Json.JsonSerializer.ToJsonString(deSerialized);
if (serialized2 != serialized)
{
Console.WriteLine("Reference: {0:yyyy-MM-ddTHH:mm:ss.fffffffK}", dto);
Console.WriteLine("Output: {0} vs {1}", serialized, serialized2);
}
}
}

@@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Text;
using Utf8Json;
using Jil;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Attributes.Jobs;

namespace PerfBenchmark
{
public struct MyModel
{
public string X { get; set; }
public string Y { get; set; }
public int Z { get; set; }
}
public class JsonSerializeBench
{
[Params(1, 10000)]
public int LoopNum { get; set; }

static string json;
static byte[] jsonBytes;

public JsonSerializeBench()
{
var m = new MyModel();
m.X = $"abcdefg";
m.Y = $"@aiweraw";
m.Z = int.MaxValue;
json = Jil.JSON.Serialize(m);
jsonBytes = Encoding.UTF8.GetBytes(json);
}

[Benchmark]
public void JilSerialize_String()
{
var m = new MyModel();
m.X = $"abcdefg";
m.Y = $"@aiweraw";
m.Z = int.MaxValue;
for (int i = 0; i < LoopNum; i++)
{
Jil.JSON.Serialize(m);
}
}
[Benchmark]
public void JilSerialize_String_UTf8()
{
var m = new MyModel();
m.X = $"abcdefg";
m.Y = $"@aiweraw";
m.Z = int.MaxValue;
for (int i = 0; i < LoopNum; i++)
{
Encoding.UTF8.GetBytes(Jil.JSON.Serialize(m));
}
}
[Benchmark]
public void Utf8JsonSerialize()
{
var m = new MyModel();
m.X = $"abcdefg";
m.Y = $"@aiweraw";
m.Z = int.MaxValue;
for (int i = 0; i < LoopNum; i++)
{
Utf8Json.JsonSerializer.Serialize(m);
}
}
[Benchmark]
public void JilJsonDeserialize_String()
{
for (int i = 0; i < LoopNum; i++)
{
Jil.JSON.Deserialize<MyModel>(json);
}
}
[Benchmark]
public void JilJsonDeserialize_Utf8()
{
for (int i = 0; i < LoopNum; i++)
{
Jil.JSON.Deserialize<MyModel>(Encoding.UTF8.GetString(jsonBytes));
}
}
[Benchmark]
public void Utf8JsonDeserialize()
{
for (int i = 0; i < LoopNum; i++)
{
Utf8Json.JsonSerializer.Deserialize<MyModel>(jsonBytes);
}
}
}
}
@@ -16,6 +16,7 @@ static void Main(string[] args)
{
typeof(SerializeBenchmark),
typeof(DeserializeBenchmark),
typeof(JsonSerializeBench)
});

// args = new string[] { "0" };
@@ -12,5 +12,5 @@
[assembly: ComVisible(false)]

[assembly: Guid("899f8b6c-c4c7-4e8b-9875-f61fdfb630bd")]
[assembly: AssemblyVersion("1.0.2")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: AssemblyVersion("1.0.3")]
[assembly: AssemblyFileVersion("1.0.3")]
@@ -12,5 +12,5 @@
[assembly: ComVisible(false)]

[assembly: Guid("2e7ac239-3db1-4772-9f47-5f62abb56ed0")]
[assembly: AssemblyVersion("1.0.2")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: AssemblyVersion("1.0.3")]
[assembly: AssemblyFileVersion("1.0.3")]
@@ -12,5 +12,5 @@
[assembly: ComVisible(false)]

[assembly: Guid("bf5d0a42-70b7-417d-af8c-2f7e073057e2")]
[assembly: AssemblyVersion("1.0.2")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: AssemblyVersion("1.0.3")]
[assembly: AssemblyFileVersion("1.0.3")]
@@ -206,10 +206,13 @@ public void Serialize(ref JsonWriter writer, DateTime value, IJsonFormatterResol
switch (value.Kind)
{
case DateTimeKind.Local:
var localOffset = TimeZoneInfo.Local.BaseUtcOffset;
// should not use `BaseUtcOffset` - https://stackoverflow.com/questions/10019267/is-there-a-generic-timezoneinfo-for-central-europe
var localOffset = TimeZoneInfo.Local.GetUtcOffset(value);
var minus = (localOffset < TimeSpan.Zero);
if (minus) localOffset = localOffset.Negate();
var h = localOffset.Hours;
var m = localOffset.Minutes;
writer.WriteRawUnsafe((localOffset < TimeSpan.Zero) ? (byte)'-' : (byte)'+');
writer.WriteRawUnsafe(minus ? (byte)'-' : (byte)'+');
if (h < 10)
{
writer.WriteRawUnsafe((byte)'0');
@@ -12,5 +12,5 @@
[assembly: ComVisible(false)]

[assembly: Guid("929e3779-4c3a-42a3-bc72-3d77511e988f")]
[assembly: AssemblyVersion("1.0.2")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: AssemblyVersion("1.0.3")]
[assembly: AssemblyFileVersion("1.0.3")]

0 comments on commit d203f37

Please sign in to comment.
You can’t perform that action at this time.