Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @ffenix113 @xernobyl @yaziine
* @xernobyl @JimmyPettersson85 @itsmeadi
19 changes: 19 additions & 0 deletions src/Utils/StreamJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(string json) => JsonConvert.DeserializeObject<T>(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);
Expand Down
10 changes: 10 additions & 0 deletions tests/UtilsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}