Skip to content

Commit 77cffab

Browse files
committed
fix #1227 force all dates to be serialized with InvariantCulture
1 parent 7ddf754 commit 77cffab

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Diff for: src/Nest/Resolvers/ElasticContractResolver.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Linq;
88
using System.Reflection;
99
using System.Collections;
10+
using System.Globalization;
1011
using Nest.Resolvers.Converters;
1112

1213
namespace Nest.Resolvers
@@ -52,7 +53,7 @@ protected override JsonContract CreateContract(Type objectType)
5253
contract.Converter = new AggregationConverter();
5354

5455
else if (objectType == typeof(DateTime) || objectType == typeof(DateTime?))
55-
contract.Converter = new IsoDateTimeConverter();
56+
contract.Converter = new IsoDateTimeConverter() { Culture = CultureInfo.InvariantCulture };
5657

5758
else if (typeof(IHit<object>).IsAssignableFrom(objectType))
5859
contract.Converter = new DefaultHitConverter();

Diff for: src/Tests/Nest.Tests.Unit/Internals/Serialize/SerializeTests.cs

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Diagnostics;
4+
using System.Globalization;
35
using System.Reflection;
6+
using System.Threading;
47
using NUnit.Framework;
58
using Nest.Tests.MockData.Domain;
69
using Elasticsearch.Net;
10+
using FluentAssertions;
711

812
namespace Nest.Tests.Unit.Internals.Serialize
913
{
@@ -48,6 +52,24 @@ public void ClassWithCollectionSerializes()
4852
this.JsonEquals(json, MethodInfo.GetCurrentMethod());
4953
}
5054

55+
[Test]
56+
public void DateTimeIgnoresCurrentCulture()
57+
{
58+
var t = new Thread(() =>
59+
{
60+
var cultureInfo = new CultureInfo("IT-it");
61+
cultureInfo.DateTimeFormat.DateSeparator = ".";
62+
cultureInfo.DateTimeFormat.TimeSeparator = ".";
63+
Thread.CurrentThread.CurrentCulture = cultureInfo;
64+
Thread.CurrentThread.CurrentUICulture = cultureInfo;
65+
66+
var serialized = _client.Serializer.Serialize(new DateTime(2015, 01, 30, 08, 52, 32, 443)).Utf8String();
67+
serialized.Should().EndWith(":32.443\"");
68+
});
69+
t.Start();
70+
t.Join(TimeSpan.FromSeconds(5));
71+
}
72+
5173
[Test]
5274
public void SerializingSearchIsFastEnough()
5375
{

0 commit comments

Comments
 (0)