diff --git a/src/Nest/DSL/Query/RangeQueryDescriptor.cs b/src/Nest/DSL/Query/RangeQueryDescriptor.cs index 5371121a859..d1f2f90bd2c 100644 --- a/src/Nest/DSL/Query/RangeQueryDescriptor.cs +++ b/src/Nest/DSL/Query/RangeQueryDescriptor.cs @@ -188,25 +188,25 @@ public RangeQueryDescriptor LowerOrEquals(string to) public RangeQueryDescriptor Greater(DateTime? from, string format = "yyyy-MM-dd'T'HH:mm:ss.fff") { - this.Self.GreaterThan = from.HasValue ? from.Value.ToString(format) : null; + this.Self.GreaterThan = from.HasValue ? from.Value.ToString(format, CultureInfo.InvariantCulture) : null; return this; } public RangeQueryDescriptor GreaterOrEquals(DateTime? from, string format = "yyyy-MM-dd'T'HH:mm:ss.fff") { - this.Self.GreaterThanOrEqualTo = from.HasValue ? from.Value.ToString(format) : null; + this.Self.GreaterThanOrEqualTo = from.HasValue ? from.Value.ToString(format, CultureInfo.InvariantCulture) : null; return this; } public RangeQueryDescriptor Lower(DateTime? to, string format = "yyyy-MM-dd'T'HH:mm:ss.fff") { - this.Self.LowerThan = to.HasValue ? to.Value.ToString(format) : null; + this.Self.LowerThan = to.HasValue ? to.Value.ToString(format, CultureInfo.InvariantCulture) : null; return this; } public RangeQueryDescriptor LowerOrEquals(DateTime? to, string format = "yyyy-MM-dd'T'HH:mm:ss.fff") { - this.Self.LowerThanOrEqualTo = to.HasValue ? to.Value.ToString(format) : null; + this.Self.LowerThanOrEqualTo = to.HasValue ? to.Value.ToString(format, CultureInfo.InvariantCulture) : null; return this; } diff --git a/src/Nest/Resolvers/ElasticContractResolver.cs b/src/Nest/Resolvers/ElasticContractResolver.cs index 9c7f09e5b5c..ead36a41bd7 100644 --- a/src/Nest/Resolvers/ElasticContractResolver.cs +++ b/src/Nest/Resolvers/ElasticContractResolver.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Reflection; using System.Collections; +using System.Globalization; using Nest.Resolvers.Converters; namespace Nest.Resolvers @@ -52,7 +53,7 @@ protected override JsonContract CreateContract(Type objectType) contract.Converter = new AggregationConverter(); else if (objectType == typeof(DateTime) || objectType == typeof(DateTime?)) - contract.Converter = new IsoDateTimeConverter(); + contract.Converter = new IsoDateTimeConverter() { Culture = CultureInfo.InvariantCulture }; else if (typeof(IHit).IsAssignableFrom(objectType)) contract.Converter = new DefaultHitConverter(); diff --git a/src/Tests/Nest.Tests.Unit/Internals/Serialize/SerializeTests.cs b/src/Tests/Nest.Tests.Unit/Internals/Serialize/SerializeTests.cs index 0bc743a5fa8..a1a981b4a50 100644 --- a/src/Tests/Nest.Tests.Unit/Internals/Serialize/SerializeTests.cs +++ b/src/Tests/Nest.Tests.Unit/Internals/Serialize/SerializeTests.cs @@ -1,9 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.Reflection; +using System.Threading; using NUnit.Framework; using Nest.Tests.MockData.Domain; using Elasticsearch.Net; +using FluentAssertions; namespace Nest.Tests.Unit.Internals.Serialize { @@ -48,6 +52,24 @@ public void ClassWithCollectionSerializes() this.JsonEquals(json, MethodInfo.GetCurrentMethod()); } + [Test] + public void DateTimeIgnoresCurrentCulture() + { + var t = new Thread(() => + { + var cultureInfo = new CultureInfo("IT-it"); + cultureInfo.DateTimeFormat.DateSeparator = "."; + cultureInfo.DateTimeFormat.TimeSeparator = "."; + Thread.CurrentThread.CurrentCulture = cultureInfo; + Thread.CurrentThread.CurrentUICulture = cultureInfo; + + var serialized = _client.Serializer.Serialize(new DateTime(2015, 01, 30, 08, 52, 32, 443)).Utf8String(); + serialized.Should().EndWith(":32.443\""); + }); + t.Start(); + t.Join(TimeSpan.FromSeconds(5)); + } + [Test] public void SerializingSearchIsFastEnough() { diff --git a/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj b/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj index e2073bc986f..3d82e334ba5 100644 --- a/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj +++ b/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj @@ -416,6 +416,7 @@ +