From fd8e19be92b1baa8c27c3886bc66d9a5703cf8bb Mon Sep 17 00:00:00 2001 From: Tiago Farto Date: Mon, 15 May 2023 17:02:10 +0100 Subject: [PATCH 1/4] Fixed UTC convertion, added UTC serializer. --- src/Utils/StreamJsonConverter.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Utils/StreamJsonConverter.cs b/src/Utils/StreamJsonConverter.cs index b99683a..0e2172a 100644 --- a/src/Utils/StreamJsonConverter.cs +++ b/src/Utils/StreamJsonConverter.cs @@ -13,6 +13,25 @@ public static class StreamJsonConverter NamingStrategy = new SnakeCaseNamingStrategy(), // this handles ForeignId => foreign_id etc. conversion for us }, NullValueHandling = NullValueHandling.Ignore, + DateTimeZoneHandling = DateTimeZoneHandling.Utc // always convert time to UTC + }; + + public static JsonSerializer Serializer { get; } = JsonSerializer.Create(Settings); + public static string SerializeObject(object obj) => JsonConvert.SerializeObject(obj, Settings); + public static T DeserializeObject(string json) => JsonConvert.DeserializeObject(json, Settings); + } + + public static class StreamJsonConverterUTC + { + private static JsonSerializerSettings Settings = new JsonSerializerSettings + { + DateFormatString = "yyyy-MM-dd'T'HH:mm:ssZ", + ContractResolver = new DefaultContractResolver + { + NamingStrategy = new SnakeCaseNamingStrategy(), // this handles ForeignId => foreign_id etc. conversion for us + }, + NullValueHandling = NullValueHandling.Ignore, + DateTimeZoneHandling = DateTimeZoneHandling.Utc // always convert time to UTC }; public static JsonSerializer Serializer { get; } = JsonSerializer.Create(Settings); From 4796bb206e590936821291aa1a8dc0e1f0210d4a Mon Sep 17 00:00:00 2001 From: Tiago Farto Date: Mon, 15 May 2023 17:06:29 +0100 Subject: [PATCH 2/4] Updated CODEOWNERS --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 79f2f49..b166a3b 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @ffenix113 @xernobyl @yaziine +* @xernobyl @JimmyPettersson85 @itsmeadi From 192e211f0e5ccbcad8fcbddac30bf94e9839bba7 Mon Sep 17 00:00:00 2001 From: Tiago Farto Date: Mon, 15 May 2023 17:06:29 +0100 Subject: [PATCH 3/4] chore: updated CODEOWNERS --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 79f2f49..b166a3b 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @ffenix113 @xernobyl @yaziine +* @xernobyl @JimmyPettersson85 @itsmeadi From 158c8b61975e9e44d906db22c7877543eb53a627 Mon Sep 17 00:00:00 2001 From: Tiago Farto Date: Mon, 15 May 2023 19:28:31 +0100 Subject: [PATCH 4/4] chore: added StreamJsonConverterUTC test --- tests/UtilsTests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/UtilsTests.cs b/tests/UtilsTests.cs index f23f455..cc1404d 100644 --- a/tests/UtilsTests.cs +++ b/tests/UtilsTests.cs @@ -51,5 +51,15 @@ public async Task TestActivityIdSameAsBackend() Assert.AreEqual(ActivityIdGenerator.GenerateId(activity.ForeignId, time).ToString(), activity.Id); } + + [Test] + public async Task TestStreamJsonConverterUTC() + { + var date0 = new DateTime(2023, 5, 10, 12, 30, 15, DateTimeKind.Utc); + var date0AsJsonNewtonsoft = Newtonsoft.Json.JsonConvert.SerializeObject(date0); + var date0AsJson = Stream.Utils.StreamJsonConverterUTC.SerializeObject(date0); + + Assert.AreEqual(date0AsJsonNewtonsoft, date0AsJson); + } } }