mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Fix how JSON serializers handle timezones
This commit is contained in:
parent
9f9becf19f
commit
29809225fb
@ -4,6 +4,7 @@
|
||||
* Make the CDN downloads multi-threaded
|
||||
* Optimize installation of included files
|
||||
* Reinstate a broken feature with disabled mods
|
||||
* Fix how JSON serializers handle dates (UTC all the things!)
|
||||
|
||||
#### Version - 2.0.4.4 - 5/11/2020
|
||||
* BA2s store file names as UTF8 instead of UTF7
|
||||
|
@ -31,10 +31,15 @@ namespace Wabbajack.Common
|
||||
new JsonSerializerSettings {
|
||||
TypeNameHandling = TypeNameHandling.Objects,
|
||||
SerializationBinder = new JsonNameSerializationBinder(),
|
||||
Converters = Converters};
|
||||
Converters = Converters,
|
||||
DateTimeZoneHandling = DateTimeZoneHandling.Utc
|
||||
};
|
||||
|
||||
public static JsonSerializerSettings GenericJsonSettings =>
|
||||
new JsonSerializerSettings();
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
|
||||
};
|
||||
|
||||
|
||||
public static void ToJson<T>(this T obj, string filename)
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Common.Serialization.Json;
|
||||
using Wabbajack.Lib.Downloaders;
|
||||
using Wabbajack.Lib.NexusApi;
|
||||
using Wabbajack.Server.DataLayer;
|
||||
@ -96,5 +97,29 @@ namespace Wabbajack.BuildServer.Test
|
||||
Assert.DoesNotContain(hs3, f => f.NexusGameId == gameId && f.ModId == 1137);
|
||||
|
||||
}
|
||||
|
||||
|
||||
[JsonName("DateBox")]
|
||||
class Box
|
||||
{
|
||||
public DateTime Value
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public async Task DatesConvertProperly()
|
||||
{
|
||||
|
||||
var a = DateTime.Now;
|
||||
var b = DateTime.UtcNow;
|
||||
|
||||
Assert.NotEqual(a, new Box{Value = a}.ToJson().FromJsonString<Box>().Value);
|
||||
Assert.Equal(b, new Box{Value = b}.ToJson().FromJsonString<Box>().Value);
|
||||
Assert.NotEqual(a.Hour, b.Hour);
|
||||
Assert.Equal(b.Hour, new Box{Value = a}.ToJson().FromJsonString<Box>().Value.Hour);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user