diff --git a/Neo4j.Driver/Neo4j.Driver.IntegrationTests/Types/PointsIT.cs b/Neo4j.Driver/Neo4j.Driver.IntegrationTests/Types/PointsIT.cs index 1dc00ed13..f22721d72 100644 --- a/Neo4j.Driver/Neo4j.Driver.IntegrationTests/Types/PointsIT.cs +++ b/Neo4j.Driver/Neo4j.Driver.IntegrationTests/Types/PointsIT.cs @@ -50,16 +50,16 @@ public void ShouldReceive() var point2 = record[1]; point1.Should().NotBeNull(); - point1.Should().BeOfType().Which.SrId.Should().Be(CartesianSrId); - point1.Should().BeOfType().Which.X.Should().Be(39.111748); - point1.Should().BeOfType().Which.Y.Should().Be(-76.775635); - point1.Should().BeOfType().Which.Z.Should().Be(double.NaN); + point1.Should().BeOfType().Which.SrId.Should().Be(CartesianSrId); + point1.Should().BeOfType().Which.X.Should().Be(39.111748); + point1.Should().BeOfType().Which.Y.Should().Be(-76.775635); + point1.Should().BeOfType().Which.Z.Should().Be(double.NaN); point2.Should().NotBeNull(); - point2.Should().BeAssignableTo().Which.SrId.Should().Be(Cartesian3DSrId); - point2.Should().BeAssignableTo().Which.X.Should().Be(39.111748); - point2.Should().BeAssignableTo().Which.Y.Should().Be(-76.775635); - point2.Should().BeAssignableTo().Which.Z.Should().Be(35.120); + point2.Should().BeAssignableTo().Which.SrId.Should().Be(Cartesian3DSrId); + point2.Should().BeAssignableTo().Which.X.Should().Be(39.111748); + point2.Should().BeAssignableTo().Which.Y.Should().Be(-76.775635); + point2.Should().BeAssignableTo().Which.Z.Should().Be(35.120); } } @@ -68,8 +68,8 @@ public void ShouldSend() { using (var session = Server.Driver.Session(AccessMode.Read)) { - var point1 = new CypherPoint(WGS84SrId, 51.5044585, -0.105658); - var point2 = new CypherPoint(WGS843DSrId, 51.5044585, -0.105658, 35.120); + var point1 = new Point(WGS84SrId, 51.5044585, -0.105658); + var point2 = new Point(WGS843DSrId, 51.5044585, -0.105658, 35.120); var created = session.Run("CREATE (n:Node { location1: $point1, location2: $point2 }) RETURN 1", new {point1, point2}).Single(); created[0].Should().Be(1L); @@ -84,10 +84,10 @@ public void ShouldSend() [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] public void ShouldSendAndReceive() { - TestSendAndReceive(new CypherPoint(WGS84SrId, 51.24923585, 0.92723724)); - TestSendAndReceive(new CypherPoint(WGS843DSrId, 22.86211019, 171.61820439, 0.1230987)); - TestSendAndReceive(new CypherPoint(CartesianSrId, 39.111748, -76.775635)); - TestSendAndReceive(new CypherPoint(Cartesian3DSrId, 39.111748, -76.775635, 19.2937302840)); + TestSendAndReceive(new Point(WGS84SrId, 51.24923585, 0.92723724)); + TestSendAndReceive(new Point(WGS843DSrId, 22.86211019, 171.61820439, 0.1230987)); + TestSendAndReceive(new Point(CartesianSrId, 39.111748, -76.775635)); + TestSendAndReceive(new Point(Cartesian3DSrId, 39.111748, -76.775635, 19.2937302840)); } [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] @@ -106,7 +106,7 @@ public void ShouldSendAndReceiveListRandom() randomPointLists.ForEach(TestSendAndReceiveList); } - private void TestSendAndReceive(CypherPoint point) + private void TestSendAndReceive(Point point) { using (var session = Server.Driver.Session(AccessMode.Read)) { @@ -117,7 +117,7 @@ private void TestSendAndReceive(CypherPoint point) } } - private void TestSendAndReceiveList(IEnumerable points) + private void TestSendAndReceiveList(IEnumerable points) { using (var session = Server.Driver.Session(AccessMode.Read)) { @@ -128,24 +128,24 @@ private void TestSendAndReceiveList(IEnumerable points) } } - private IEnumerable GenerateRandomPointList(int sequence, int count) + private IEnumerable GenerateRandomPointList(int sequence, int count) { return Enumerable.Range(0, count).Select(i => GenerateRandomPoint(sequence)).ToList(); } - private CypherPoint GenerateRandomPoint(int sequence) + private Point GenerateRandomPoint(int sequence) { switch (sequence % 4) { case 0: - return new CypherPoint(WGS84SrId, GenerateRandomDouble(), GenerateRandomDouble()); + return new Point(WGS84SrId, GenerateRandomDouble(), GenerateRandomDouble()); case 1: - return new CypherPoint(WGS843DSrId, GenerateRandomDouble(), GenerateRandomDouble(), + return new Point(WGS843DSrId, GenerateRandomDouble(), GenerateRandomDouble(), GenerateRandomDouble()); case 2: - return new CypherPoint(CartesianSrId, GenerateRandomDouble(), GenerateRandomDouble()); + return new Point(CartesianSrId, GenerateRandomDouble(), GenerateRandomDouble()); case 3: - return new CypherPoint(Cartesian3DSrId, GenerateRandomDouble(), GenerateRandomDouble(), + return new Point(Cartesian3DSrId, GenerateRandomDouble(), GenerateRandomDouble(), GenerateRandomDouble()); default: throw new ArgumentOutOfRangeException(); diff --git a/Neo4j.Driver/Neo4j.Driver.IntegrationTests/Types/TemporalTypesIT.cs b/Neo4j.Driver/Neo4j.Driver.IntegrationTests/Types/TemporalTypesIT.cs index 7a3552018..6a199f56f 100644 --- a/Neo4j.Driver/Neo4j.Driver.IntegrationTests/Types/TemporalTypesIT.cs +++ b/Neo4j.Driver/Neo4j.Driver.IntegrationTests/Types/TemporalTypesIT.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using System.Linq; using FluentAssertions; +using Neo4j.Driver.Internal; using Neo4j.Driver.V1; using Xunit.Abstractions; @@ -26,6 +27,17 @@ namespace Neo4j.Driver.IntegrationTests.Types { public class TemporalTypesIT: DirectDriverTestBase { + private const int NumberOfRandomSequences = 2000; + private const int MinArrayLength = 5; + private const int MaxArrayLength = 1000; + + private readonly IEnumerable _tzNames = new[] + { + "Africa/Harare", "America/Aruba", "Africa/Nairobi", "America/Dawson", "Asia/Beirut", "Asia/Tashkent", + "Canada/Eastern", "Europe/Malta", "Europe/Volgograd", "Indian/Kerguelen", "Etc/GMT+3" + }; + private readonly Random _random = new Random(); + public TemporalTypesIT(ITestOutputHelper output, StandAloneIntegrationTestFixture fixture) : base(output, fixture) { @@ -36,21 +48,21 @@ public TemporalTypesIT(ITestOutputHelper output, StandAloneIntegrationTestFixtur public void ShouldReceiveDuration() { TestReceiveData("RETURN duration({ months: 16, days: 45, seconds: 120, nanoseconds: 187309812 })", - new CypherDuration(16, 45, 120, 187309812)); + new Duration(16, 45, 120, 187309812)); } [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] public void ShouldReceiveDate() { TestReceiveData("RETURN date({ year: 1994, month: 11, day: 15 })", - new CypherDate(1994, 11, 15)); + new LocalDate(1994, 11, 15)); } [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] public void ShouldReceiveTime() { TestReceiveData("RETURN localtime({ hour: 23, minute: 49, second: 59, nanosecond: 999999999 })", - new CypherTime(23, 49, 59, 999999999)); + new LocalTime(23, 49, 59, 999999999)); } [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] @@ -58,7 +70,7 @@ public void ShouldReceiveTimeWithOffset() { TestReceiveData( "RETURN time({ hour: 23, minute: 49, second: 59, nanosecond: 999999999, timezone:'+03:00' })", - new CypherTimeWithOffset(23, 49, 59, 999999999, (int)TimeSpan.FromHours(3).TotalSeconds)); + new OffsetTime(23, 49, 59, 999999999, (int)TimeSpan.FromHours(3).TotalSeconds)); } [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] @@ -66,7 +78,7 @@ public void ShouldReceiveDateTime() { TestReceiveData( "RETURN localdatetime({ year: 1859, month: 5, day: 31, hour: 23, minute: 49, second: 59, nanosecond: 999999999 })", - new CypherDateTime(1859, 5, 31, 23, 49, 59, 999999999)); + new LocalDateTime(1859, 5, 31, 23, 49, 59, 999999999)); } [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] @@ -74,7 +86,7 @@ public void ShouldReceiveDateTimeWithOffset() { TestReceiveData( "RETURN datetime({ year: 1859, month: 5, day: 31, hour: 23, minute: 49, second: 59, nanosecond: 999999999, timezone:'+02:30' })", - new CypherDateTimeWithOffset(1859, 5, 31, 23, 49, 59, 999999999, (int)TimeSpan.FromMinutes(150).TotalSeconds)); + new ZonedDateTime(1859, 5, 31, 23, 49, 59, 999999999, Zone.Of((int)TimeSpan.FromMinutes(150).TotalSeconds))); } [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] @@ -82,13 +94,13 @@ public void ShouldReceiveDateTimeWithZoneId() { TestReceiveData( "RETURN datetime({ year: 1959, month: 5, day: 31, hour: 23, minute: 49, second: 59, nanosecond: 999999999, timezone:'Europe/London' })", - new CypherDateTimeWithZoneId(1959, 5, 31, 23, 49, 59, 999999999, "Europe/London")); + new ZonedDateTime(1959, 5, 31, 23, 49, 59, 999999999, Zone.Of("Europe/London"))); } [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] public void ShouldSendAndReceiveDuration() { - var data = new CypherDuration(14, 35, 75, 789012587); + var data = new Duration(14, 35, 75, 789012587); TestSendAndReceiveData( "CYPHER runtime=interpreted WITH $x AS x RETURN x, x.months, x.days, x.seconds, x.millisecondsOfSecond, x.microsecondsOfSecond, x.nanosecondsOfSecond", @@ -108,7 +120,7 @@ public void ShouldSendAndReceiveDuration() [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] public void ShouldSendAndReceiveDate() { - var data = new CypherDate(1976, 6, 13); + var data = new LocalDate(1976, 6, 13); TestSendAndReceiveData( "CYPHER runtime = interpreted WITH $x AS x RETURN x, x.year, x.month, x.day", @@ -125,7 +137,7 @@ public void ShouldSendAndReceiveDate() [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] public void ShouldSendAndReceiveTime() { - var data = new CypherTime(12, 34, 56, 789012587); + var data = new LocalTime(12, 34, 56, 789012587); TestSendAndReceiveData( "CYPHER runtime=interpreted WITH $x AS x RETURN x, x.hour, x.minute, x.second, x.millisecond, x.microsecond, x.nanosecond", @@ -145,7 +157,7 @@ public void ShouldSendAndReceiveTime() [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] public void ShouldSendAndReceiveTimeWithOffset() { - var data = new CypherTimeWithOffset(12, 34, 56, 789012587, (int)TimeSpan.FromMinutes(90).TotalSeconds); + var data = new OffsetTime(12, 34, 56, 789012587, (int)TimeSpan.FromMinutes(90).TotalSeconds); TestSendAndReceiveData( "CYPHER runtime=interpreted WITH $x AS x RETURN x, x.hour, x.minute, x.second, x.millisecond, x.microsecond, x.nanosecond, x.offset", @@ -166,7 +178,7 @@ public void ShouldSendAndReceiveTimeWithOffset() [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] public void ShouldSendAndReceiveDateTime() { - var data = new CypherDateTime(1976, 6, 13, 12, 34, 56, 789012587); + var data = new LocalDateTime(1976, 6, 13, 12, 34, 56, 789012587); TestSendAndReceiveData( "CYPHER runtime=interpreted WITH $x AS x RETURN x, x.year, x.month, x.day, x.hour, x.minute, x.second, x.millisecond, x.microsecond, x.nanosecond", @@ -189,7 +201,7 @@ public void ShouldSendAndReceiveDateTime() [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] public void ShouldSendAndReceiveDateTimeWithOffset() { - var data = new CypherDateTimeWithOffset(1976, 6, 13, 12, 34, 56, 789012587, (int)TimeSpan.FromMinutes(-90).TotalSeconds); + var data = new ZonedDateTime(1976, 6, 13, 12, 34, 56, 789012587, Zone.Of((int)TimeSpan.FromMinutes(-90).TotalSeconds)); TestSendAndReceiveData( "CYPHER runtime=interpreted WITH $x AS x RETURN x, x.year, x.month, x.day, x.hour, x.minute, x.second, x.millisecond, x.microsecond, x.nanosecond, x.offset", @@ -213,7 +225,7 @@ public void ShouldSendAndReceiveDateTimeWithOffset() [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] public void ShouldSendAndReceiveDateTimeWithZoneId() { - var data = new CypherDateTimeWithZoneId(1959, 5, 31, 23, 49, 59, 999999999, "US/Pacific"); + var data = new ZonedDateTime(1959, 5, 31, 23, 49, 59, 999999999, Zone.Of("US/Pacific")); TestSendAndReceiveData( "CYPHER runtime=interpreted WITH $x AS x RETURN x, x.year, x.month, x.day, x.hour, x.minute, x.second, x.millisecond, x.microsecond, x.nanosecond, x.timezone", @@ -234,7 +246,105 @@ public void ShouldSendAndReceiveDateTimeWithZoneId() }); } - public void TestReceiveData(string query, object expected) + [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] + public void ShouldSendAndReceiveRandomDuration() + { + Enumerable.Range(0, NumberOfRandomSequences).Select(i => RandomDuration()).AsParallel() + .ForAll(TestSendAndReceive); + } + + [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] + public void ShouldSendAndReceiveRandomLocalDate() + { + Enumerable.Range(0, NumberOfRandomSequences).Select(i => RandomLocalDate()).AsParallel() + .ForAll(TestSendAndReceive); + } + + [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] + public void ShouldSendAndReceiveRandomLocalDateTime() + { + Enumerable.Range(0, NumberOfRandomSequences).Select(i => RandomLocalDateTime()).AsParallel() + .ForAll(TestSendAndReceive); + } + + [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] + public void ShouldSendAndReceiveRandomLocalTime() + { + Enumerable.Range(0, NumberOfRandomSequences).Select(i => RandomLocalTime()).AsParallel() + .ForAll(TestSendAndReceive); + } + + [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] + public void ShouldSendAndReceiveRandomOffsetTime() + { + Enumerable.Range(0, NumberOfRandomSequences).Select(i => RandomOffsetTime()).AsParallel() + .ForAll(TestSendAndReceive); + } + + [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] + public void ShouldSendAndReceiveRandomOffsetDateTime() + { + Enumerable.Range(0, NumberOfRandomSequences).Select(i => RandomOffsetDateTime()).AsParallel() + .ForAll(TestSendAndReceive); + } + + [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] + public void ShouldSendAndReceiveRandomZonedDateTime() + { + Enumerable.Range(0, NumberOfRandomSequences).Select(i => RandomZonedDateTime()).AsParallel() + .ForAll(TestSendAndReceive); + } + + [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] + public void ShouldSendAndReceiveArrayOfDuration() + { + TestSendAndReceiveArray(Enumerable.Range(0, _random.Next(MinArrayLength, MaxArrayLength)) + .Select(i => RandomDuration())); + } + + [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] + public void ShouldSendAndReceiveArrayOfLocalDate() + { + TestSendAndReceiveArray(Enumerable.Range(0, _random.Next(MinArrayLength, MaxArrayLength)) + .Select(i => RandomLocalDate())); + } + + [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] + public void ShouldSendAndReceiveArrayOfLocalDateTime() + { + TestSendAndReceiveArray(Enumerable.Range(0, _random.Next(MinArrayLength, MaxArrayLength)) + .Select(i => RandomLocalDateTime())); + } + + [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] + public void ShouldSendAndReceiveArrayOfLocalTime() + { + TestSendAndReceiveArray(Enumerable.Range(0, _random.Next(MinArrayLength, MaxArrayLength)) + .Select(i => RandomLocalTime())); + } + + [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] + public void ShouldSendAndReceiveArrayOfOffsetTime() + { + TestSendAndReceiveArray(Enumerable.Range(0, _random.Next(MinArrayLength, MaxArrayLength)) + .Select(i => RandomOffsetTime())); + } + + [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] + public void ShouldSendAndReceiveArrayOfOffsetDateTime() + { + TestSendAndReceiveArray(Enumerable.Range(0, _random.Next(MinArrayLength, MaxArrayLength)) + .Select(i => RandomOffsetDateTime())); + } + + [RequireServerVersionGreaterThanOrEqualToFact("3.4.0")] + public void ShouldSendAndReceiveArrayOfZonedDateTime() + { + TestSendAndReceiveArray(Enumerable.Range(0, _random.Next(MinArrayLength, MaxArrayLength)) + .Select(i => RandomZonedDateTime())); + } + + private void TestReceiveData(string query, object expected) { using (var session = Server.Driver.Session(AccessMode.Read)) { @@ -259,6 +369,110 @@ private void TestSendAndReceiveData(string query, object toBeSent, object[] expe } } + private void TestSendAndReceive(object value) + { + using (var session = Server.Driver.Session(AccessMode.Read)) + { + var record = session.Run("CREATE (n:Node {value: $value}) RETURN n.value", new { value }).Single(); + + record.Keys.Should().HaveCount(1); + record[0].Should().Be(value); + } + } + + private void TestSendAndReceiveArray(IEnumerable array) + { + var list = array.ToList(); + + using (var session = Server.Driver.Session(AccessMode.Read)) + { + var record = session.Run("CREATE (n:Node {value: $value}) RETURN n.value", new { value = list }).Single(); + + record.Keys.Should().HaveCount(1); + record[0].Should().BeAssignableTo>().Which.Should().BeEquivalentTo(list); + } + } + + #region Random Temporal Value Generation + + private Duration RandomDuration() + { + var sign = _random.Next(0, 1) > 0 ? 1 : -1; + + return new Duration( + sign * _random.Next(0, int.MaxValue), + sign * _random.Next(0, int.MaxValue), + sign * _random.Next(0, int.MaxValue), + sign * _random.Next(TemporalHelpers.MinNanosecond, TemporalHelpers.MaxNanosecond) + ); + } + + private LocalDate RandomLocalDate() + { + return new LocalDate( + _random.Next(TemporalHelpers.MinYear, TemporalHelpers.MaxYear), + _random.Next(TemporalHelpers.MinMonth, TemporalHelpers.MaxMonth), + _random.Next(TemporalHelpers.MinDay, 28) + ); + } + + private LocalDateTime RandomLocalDateTime(bool tzSafe = false) + { + return new LocalDateTime( + tzSafe + ? _random.Next(1950, TemporalHelpers.MaxYear) + : _random.Next(TemporalHelpers.MinYear, TemporalHelpers.MaxYear), + _random.Next(TemporalHelpers.MinMonth, TemporalHelpers.MaxMonth), + _random.Next(TemporalHelpers.MinDay, 28), + tzSafe + ? _random.Next(6, TemporalHelpers.MaxHour) + : _random.Next(TemporalHelpers.MinHour, TemporalHelpers.MaxHour), + _random.Next(TemporalHelpers.MinMinute, TemporalHelpers.MaxMinute), + _random.Next(TemporalHelpers.MinSecond, TemporalHelpers.MaxSecond), + _random.Next(TemporalHelpers.MinNanosecond, TemporalHelpers.MaxNanosecond) + ); + } + + private LocalTime RandomLocalTime() + { + return new LocalTime( + _random.Next(TemporalHelpers.MinHour, TemporalHelpers.MaxHour), + _random.Next(TemporalHelpers.MinMinute, TemporalHelpers.MaxMinute), + _random.Next(TemporalHelpers.MinSecond, TemporalHelpers.MaxSecond), + _random.Next(TemporalHelpers.MinNanosecond, TemporalHelpers.MaxNanosecond) + ); + } + + private OffsetTime RandomOffsetTime() + { + return new OffsetTime( + RandomLocalTime(), + _random.Next(TemporalHelpers.MinOffset, TemporalHelpers.MaxOffset) + ); + } + + private ZonedDateTime RandomOffsetDateTime() + { + return new ZonedDateTime( + RandomLocalDateTime(true), + Zone.Of(_random.Next(TemporalHelpers.MinOffset, TemporalHelpers.MaxOffset)) + ); + } + + private ZonedDateTime RandomZonedDateTime() + { + return new ZonedDateTime( + RandomLocalDateTime(true), + Zone.Of(RandomTZName()) + ); + } + + private string RandomTZName() + { + return _tzNames.ElementAt(_random.Next(0, _tzNames.Count())); + } + + #endregion } } \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/PointHandlerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/PointHandlerTests.cs index bc2f03c9d..440e4c574 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/PointHandlerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/PointHandlerTests.cs @@ -39,7 +39,7 @@ public void ShouldWritePoint2D() var writerMachine = CreateWriterMachine(); var writer = writerMachine.Writer(); - writer.Write(new CypherPoint(7203, 51.5044585, -0.105658)); + writer.Write(new Point(7203, 51.5044585, -0.105658)); var readerMachine = CreateReaderMachine(writerMachine.GetOutput()); var reader = readerMachine.Reader(); @@ -58,7 +58,7 @@ public void ShouldWritePoint3D() var writerMachine = CreateWriterMachine(); var writer = writerMachine.Writer(); - writer.Write(new CypherPoint(7203, 51.5044585, -0.105658, 35.25)); + writer.Write(new Point(7203, 51.5044585, -0.105658, 35.25)); var readerMachine = CreateReaderMachine(writerMachine.GetOutput()); var reader = readerMachine.Reader(); @@ -88,10 +88,10 @@ public void ShouldReadPoint2D() var value = reader.Read(); value.Should().NotBeNull(); - value.Should().BeOfType().Which.SrId.Should().Be(7203); - value.Should().BeOfType().Which.X.Should().Be(51.5044585); - value.Should().BeOfType().Which.Y.Should().Be(-0.105658); - value.Should().BeOfType().Which.Z.Should().Be(double.NaN); + value.Should().BeOfType().Which.SrId.Should().Be(7203); + value.Should().BeOfType().Which.X.Should().Be(51.5044585); + value.Should().BeOfType().Which.Y.Should().Be(-0.105658); + value.Should().BeOfType().Which.Z.Should().Be(double.NaN); } [Fact] @@ -111,10 +111,10 @@ public void ShouldReadPoint3D() var value = reader.Read(); value.Should().NotBeNull(); - value.Should().BeOfType().Which.SrId.Should().Be(7203); - value.Should().BeOfType().Which.X.Should().Be(51.5044585); - value.Should().BeOfType().Which.Y.Should().Be(-0.105658); - value.Should().BeOfType().Which.Z.Should().Be(35.25); + value.Should().BeOfType().Which.SrId.Should().Be(7203); + value.Should().BeOfType().Which.X.Should().Be(51.5044585); + value.Should().BeOfType().Which.Y.Should().Be(-0.105658); + value.Should().BeOfType().Which.Z.Should().Be(35.25); } } } \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DateTimeWithOffsetHandlerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DateTimeWithOffsetHandlerTests.cs deleted file mode 100644 index 097169644..000000000 --- a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DateTimeWithOffsetHandlerTests.cs +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2002-2018 "Neo Technology," -// Network Engine for Objects in Lund AB [http://neotechnology.com] -// -// This file is part of Neo4j. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System; -using System.Collections; -using System.Collections.Generic; -using FluentAssertions; -using FluentAssertions.Primitives; -using Moq; -using Neo4j.Driver.Internal; -using Neo4j.Driver.Internal.IO; -using Neo4j.Driver.Internal.IO.StructHandlers; -using Neo4j.Driver.Internal.Messaging; -using Neo4j.Driver.Internal.Types; -using Neo4j.Driver.V1; -using Xunit; - -namespace Neo4j.Driver.Tests.IO.StructHandlers -{ - public class DateTimeWithOffsetHandlerTests : StructHandlerTests - { - internal override IPackStreamStructHandler HandlerUnderTest => new DateTimeWithOffsetHandler(); - - [Fact] - public void ShouldWriteDateTimeWithOffset() - { - var dateTime = new CypherDateTimeWithOffset(1978, 12, 16, 12, 35, 59, 128000987, - (int) TimeSpan.FromMinutes(-150).TotalSeconds); - var writerMachine = CreateWriterMachine(); - var writer = writerMachine.Writer(); - - writer.Write(dateTime); - - var readerMachine = CreateReaderMachine(writerMachine.GetOutput()); - var reader = readerMachine.Reader(); - - reader.PeekNextType().Should().Be(PackStream.PackType.Struct); - reader.ReadStructHeader().Should().Be(3); - reader.ReadStructSignature().Should().Be((byte) 'F'); - reader.Read().Should().Be(282659759L); - reader.Read().Should().Be(128000987L); - reader.Read().Should().Be(-9000L); - } - - [Fact] - public void ShouldReadDateTimeWithOffset() - { - var writerMachine = CreateWriterMachine(); - var writer = writerMachine.Writer(); - - writer.WriteStructHeader(DateTimeWithOffsetHandler.StructSize, DateTimeWithOffsetHandler.StructType); - writer.Write(282659759); - writer.Write(128000987); - writer.Write(-9000); - - var readerMachine = CreateReaderMachine(writerMachine.GetOutput()); - var reader = readerMachine.Reader(); - var value = reader.Read(); - - value.Should().NotBeNull(); - value.Should().BeOfType().Which.Year.Should().Be(1978); - value.Should().BeOfType().Which.Month.Should().Be(12); - value.Should().BeOfType().Which.Day.Should().Be(16); - value.Should().BeOfType().Which.Hour.Should().Be(12); - value.Should().BeOfType().Which.Minute.Should().Be(35); - value.Should().BeOfType().Which.Second.Should().Be(59); - value.Should().BeOfType().Which.Nanosecond.Should().Be(128000987); - value.Should().BeOfType().Which.OffsetSeconds.Should().Be((int)TimeSpan.FromMinutes(-150).TotalSeconds); - } - - } -} \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DateTimeWithZoneIdHandlerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DateTimeWithZoneIdHandlerTests.cs deleted file mode 100644 index e262b6509..000000000 --- a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DateTimeWithZoneIdHandlerTests.cs +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2002-2018 "Neo Technology," -// Network Engine for Objects in Lund AB [http://neotechnology.com] -// -// This file is part of Neo4j. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System; -using System.Collections; -using System.Collections.Generic; -using FluentAssertions; -using FluentAssertions.Primitives; -using Moq; -using Neo4j.Driver.Internal; -using Neo4j.Driver.Internal.IO; -using Neo4j.Driver.Internal.IO.StructHandlers; -using Neo4j.Driver.Internal.Messaging; -using Neo4j.Driver.Internal.Types; -using Neo4j.Driver.V1; -using Xunit; - -namespace Neo4j.Driver.Tests.IO.StructHandlers -{ - public class DateTimeWithZoneIdHandlerTests : StructHandlerTests - { - internal override IPackStreamStructHandler HandlerUnderTest => new DateTimeWithZoneIdHandler(); - - [Fact] - public void ShouldWriteDateTimeWithZoneId() - { - var dateTime = new CypherDateTimeWithZoneId(1978, 12, 16, 12, 35, 59, 128000987, "Europe/Istanbul"); - var writerMachine = CreateWriterMachine(); - var writer = writerMachine.Writer(); - - writer.Write(dateTime); - - var readerMachine = CreateReaderMachine(writerMachine.GetOutput()); - var reader = readerMachine.Reader(); - - reader.PeekNextType().Should().Be(PackStream.PackType.Struct); - reader.ReadStructHeader().Should().Be(3); - reader.ReadStructSignature().Should().Be((byte) 'f'); - reader.Read().Should().Be(282659759L); - reader.Read().Should().Be(128000987L); - reader.Read().Should().Be("Europe/Istanbul"); - } - - [Fact] - public void ShouldReadDateTimeWithZoneId() - { - var writerMachine = CreateWriterMachine(); - var writer = writerMachine.Writer(); - - writer.WriteStructHeader(DateTimeWithZoneIdHandler.StructSize, DateTimeWithZoneIdHandler.StructType); - writer.Write(282659759); - writer.Write(128000987); - writer.Write("Europe/Istanbul"); - - var readerMachine = CreateReaderMachine(writerMachine.GetOutput()); - var reader = readerMachine.Reader(); - var value = reader.Read(); - - value.Should().NotBeNull(); - value.Should().BeOfType().Which.Year.Should().Be(1978); - value.Should().BeOfType().Which.Month.Should().Be(12); - value.Should().BeOfType().Which.Day.Should().Be(16); - value.Should().BeOfType().Which.Hour.Should().Be(12); - value.Should().BeOfType().Which.Minute.Should().Be(35); - value.Should().BeOfType().Which.Second.Should().Be(59); - value.Should().BeOfType().Which.Nanosecond.Should().Be(128000987); - value.Should().BeOfType().Which.ZoneId.Should().Be("Europe/Istanbul"); - } - - } -} \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DurationHandlerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DurationHandlerTests.cs index ce3324fc9..ebc4c9001 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DurationHandlerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DurationHandlerTests.cs @@ -39,7 +39,7 @@ public void ShouldWriteDuration() var writerMachine = CreateWriterMachine(); var writer = writerMachine.Writer(); - writer.Write(new CypherDuration(10, 4, 300, 120)); + writer.Write(new Duration(10, 4, 300, 120)); var readerMachine = CreateReaderMachine(writerMachine.GetOutput()); var reader = readerMachine.Reader(); @@ -70,10 +70,10 @@ public void ShouldReadDuration() var value = reader.Read(); value.Should().NotBeNull(); - value.Should().BeOfType().Which.Months.Should().Be(21L); - value.Should().BeOfType().Which.Days.Should().Be(8L); - value.Should().BeOfType().Which.Seconds.Should().Be(564L); - value.Should().BeOfType().Which.Nanos.Should().Be(865); + value.Should().BeOfType().Which.Months.Should().Be(21L); + value.Should().BeOfType().Which.Days.Should().Be(8L); + value.Should().BeOfType().Which.Seconds.Should().Be(564L); + value.Should().BeOfType().Which.Nanos.Should().Be(865); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DateHandlerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/LocalDateHandlerTests.cs similarity index 82% rename from Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DateHandlerTests.cs rename to Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/LocalDateHandlerTests.cs index 53865388d..2e22a0057 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DateHandlerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/LocalDateHandlerTests.cs @@ -30,14 +30,14 @@ namespace Neo4j.Driver.Tests.IO.StructHandlers { - public class DateHandlerTests : StructHandlerTests + public class LocalDateHandlerTests : StructHandlerTests { - internal override IPackStreamStructHandler HandlerUnderTest => new DateHandler(); + internal override IPackStreamStructHandler HandlerUnderTest => new LocalDateHandler(); [Fact] public void ShouldWriteDate() { - var date = new CypherDate(1950, 8, 31); + var date = new LocalDate(1950, 8, 31); var writerMachine = CreateWriterMachine(); var writer = writerMachine.Writer(); @@ -58,7 +58,7 @@ public void ShouldReadDate() var writerMachine = CreateWriterMachine(); var writer = writerMachine.Writer(); - writer.WriteStructHeader(DateHandler.StructSize, DateHandler.StructType); + writer.WriteStructHeader(LocalDateHandler.StructSize, LocalDateHandler.StructType); writer.Write(-7063L); var readerMachine = CreateReaderMachine(writerMachine.GetOutput()); @@ -66,9 +66,9 @@ public void ShouldReadDate() var value = reader.Read(); value.Should().NotBeNull(); - value.Should().BeOfType().Which.Year.Should().Be(1950); - value.Should().BeOfType().Which.Month.Should().Be(8); - value.Should().BeOfType().Which.Day.Should().Be(31); + value.Should().BeOfType().Which.Year.Should().Be(1950); + value.Should().BeOfType().Which.Month.Should().Be(8); + value.Should().BeOfType().Which.Day.Should().Be(31); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DateTimeHandlerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/LocalDateTimeHandlerTests.cs similarity index 72% rename from Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DateTimeHandlerTests.cs rename to Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/LocalDateTimeHandlerTests.cs index b81c0212d..eacfa4f8c 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/DateTimeHandlerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/LocalDateTimeHandlerTests.cs @@ -29,14 +29,14 @@ namespace Neo4j.Driver.Tests.IO.StructHandlers { - public class DateTimeHandlerTests : StructHandlerTests + public class LocalDateTimeHandlerTests : StructHandlerTests { - internal override IPackStreamStructHandler HandlerUnderTest => new DateTimeHandler(); + internal override IPackStreamStructHandler HandlerUnderTest => new LocalDateTimeHandler(); [Fact] public void ShouldWriteDateTime() { - var dateTime = new CypherDateTime(1978, 12, 16, 12, 35, 59, 128000987); + var dateTime = new LocalDateTime(1978, 12, 16, 12, 35, 59, 128000987); var writerMachine = CreateWriterMachine(); var writer = writerMachine.Writer(); @@ -58,7 +58,7 @@ public void ShouldReadDateTime() var writerMachine = CreateWriterMachine(); var writer = writerMachine.Writer(); - writer.WriteStructHeader(DateTimeHandler.StructSize, DateTimeHandler.StructType); + writer.WriteStructHeader(LocalDateTimeHandler.StructSize, LocalDateTimeHandler.StructType); writer.Write(282659759); writer.Write(128000987); @@ -67,13 +67,13 @@ public void ShouldReadDateTime() var value = reader.Read(); value.Should().NotBeNull(); - value.Should().BeOfType().Which.Year.Should().Be(1978); - value.Should().BeOfType().Which.Month.Should().Be(12); - value.Should().BeOfType().Which.Day.Should().Be(16); - value.Should().BeOfType().Which.Hour.Should().Be(12); - value.Should().BeOfType().Which.Minute.Should().Be(35); - value.Should().BeOfType().Which.Second.Should().Be(59); - value.Should().BeOfType().Which.Nanosecond.Should().Be(128000987); + value.Should().BeOfType().Which.Year.Should().Be(1978); + value.Should().BeOfType().Which.Month.Should().Be(12); + value.Should().BeOfType().Which.Day.Should().Be(16); + value.Should().BeOfType().Which.Hour.Should().Be(12); + value.Should().BeOfType().Which.Minute.Should().Be(35); + value.Should().BeOfType().Which.Second.Should().Be(59); + value.Should().BeOfType().Which.Nanosecond.Should().Be(128000987); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/TimeHandlerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/LocalTimeHandlerTests.cs similarity index 79% rename from Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/TimeHandlerTests.cs rename to Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/LocalTimeHandlerTests.cs index c14cf6c9a..d827426ee 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/TimeHandlerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/LocalTimeHandlerTests.cs @@ -30,14 +30,14 @@ namespace Neo4j.Driver.Tests.IO.StructHandlers { - public class TimeHandlerTests : StructHandlerTests + public class LocalTimeHandlerTests : StructHandlerTests { - internal override IPackStreamStructHandler HandlerUnderTest => new TimeHandler(); + internal override IPackStreamStructHandler HandlerUnderTest => new LocalTimeHandler(); [Fact] public void ShouldWriteTime() { - var time = new CypherTime(12, 35, 59, 128000987); + var time = new LocalTime(12, 35, 59, 128000987); var writerMachine = CreateWriterMachine(); var writer = writerMachine.Writer(); @@ -58,7 +58,7 @@ public void ShouldReadTime() var writerMachine = CreateWriterMachine(); var writer = writerMachine.Writer(); - writer.WriteStructHeader(TimeHandler.StructSize, TimeHandler.StructType); + writer.WriteStructHeader(LocalTimeHandler.StructSize, LocalTimeHandler.StructType); writer.Write(45359128000987); var readerMachine = CreateReaderMachine(writerMachine.GetOutput()); @@ -66,10 +66,10 @@ public void ShouldReadTime() var value = reader.Read(); value.Should().NotBeNull(); - value.Should().BeOfType().Which.Hour.Should().Be(12); - value.Should().BeOfType().Which.Minute.Should().Be(35); - value.Should().BeOfType().Which.Second.Should().Be(59); - value.Should().BeOfType().Which.Nanosecond.Should().Be(128000987); + value.Should().BeOfType().Which.Hour.Should().Be(12); + value.Should().BeOfType().Which.Minute.Should().Be(35); + value.Should().BeOfType().Which.Second.Should().Be(59); + value.Should().BeOfType().Which.Nanosecond.Should().Be(128000987); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/TimeWithOffsetHandlerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/OffsetTimeHandlerTests.cs similarity index 74% rename from Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/TimeWithOffsetHandlerTests.cs rename to Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/OffsetTimeHandlerTests.cs index f4210865c..a094307d8 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/TimeWithOffsetHandlerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/OffsetTimeHandlerTests.cs @@ -31,14 +31,14 @@ namespace Neo4j.Driver.Tests.IO.StructHandlers { - public class TimeWithOffsetHandlerTests : StructHandlerTests + public class OffsetTimeHandlerTests : StructHandlerTests { - internal override IPackStreamStructHandler HandlerUnderTest => new TimeWithOffsetHandler(); + internal override IPackStreamStructHandler HandlerUnderTest => new OffsetTimeHandler(); [Fact] public void ShouldWriteTimeWithOffset() { - var time = new CypherTimeWithOffset(12, 35, 59, 128000987, (int)TimeSpan.FromMinutes(150).TotalSeconds); + var time = new OffsetTime(12, 35, 59, 128000987, (int)TimeSpan.FromMinutes(150).TotalSeconds); var writerMachine = CreateWriterMachine(); var writer = writerMachine.Writer(); @@ -60,7 +60,7 @@ public void ShouldReadTimeWithOffset() var writerMachine = CreateWriterMachine(); var writer = writerMachine.Writer(); - writer.WriteStructHeader(TimeWithOffsetHandler.StructSize, TimeWithOffsetHandler.StructType); + writer.WriteStructHeader(OffsetTimeHandler.StructSize, OffsetTimeHandler.StructType); writer.Write(45359128000987); writer.Write((int)TimeSpan.FromMinutes(150).TotalSeconds); @@ -69,11 +69,11 @@ public void ShouldReadTimeWithOffset() var value = reader.Read(); value.Should().NotBeNull(); - value.Should().BeOfType().Which.Hour.Should().Be(12); - value.Should().BeOfType().Which.Minute.Should().Be(35); - value.Should().BeOfType().Which.Second.Should().Be(59); - value.Should().BeOfType().Which.Nanosecond.Should().Be(128000987); - value.Should().BeOfType().Which.OffsetSeconds.Should().Be((int)TimeSpan.FromMinutes(150).TotalSeconds); + value.Should().BeOfType().Which.Hour.Should().Be(12); + value.Should().BeOfType().Which.Minute.Should().Be(35); + value.Should().BeOfType().Which.Second.Should().Be(59); + value.Should().BeOfType().Which.Nanosecond.Should().Be(128000987); + value.Should().BeOfType().Which.OffsetSeconds.Should().Be((int)TimeSpan.FromMinutes(150).TotalSeconds); } } diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/SystemDateTimeHandlerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/SystemDateTimeHandlerTests.cs index b3e79b4a1..fc29d0a0b 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/SystemDateTimeHandlerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/SystemDateTimeHandlerTests.cs @@ -36,7 +36,7 @@ public class SystemDateTimeHandlerTests : StructHandlerTests internal override IEnumerable HandlersNeeded => new IPackStreamStructHandler[] { - new DateTimeHandler(), new DateTimeWithOffsetHandler() + new LocalDateTimeHandler(), new ZonedDateTimeHandler() }; [Fact] diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/SystemDateTimeOffsetHandlerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/SystemDateTimeOffsetHandlerTests.cs index c5c0119f1..bd41f01c9 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/SystemDateTimeOffsetHandlerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/SystemDateTimeOffsetHandlerTests.cs @@ -36,7 +36,7 @@ public class SystemDateTimeOffsetHandlerTests : StructHandlerTests internal override IEnumerable HandlersNeeded => new IPackStreamStructHandler[] { - new DateTimeWithOffsetHandler() + new ZonedDateTimeHandler() }; [Fact] diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/SystemTimeSpanHandlerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/SystemTimeSpanHandlerTests.cs index 1ad6e6827..77e77c243 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/SystemTimeSpanHandlerTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/SystemTimeSpanHandlerTests.cs @@ -36,7 +36,7 @@ public class SystemTimeSpanHandlerTests : StructHandlerTests internal override IEnumerable HandlersNeeded => new IPackStreamStructHandler[] { - new TimeHandler() + new LocalTimeHandler() }; [Fact] diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/ZonedDateTimeHandlerTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/ZonedDateTimeHandlerTests.cs new file mode 100644 index 000000000..557ddcff6 --- /dev/null +++ b/Neo4j.Driver/Neo4j.Driver.Tests/IO/StructHandlers/Temporal/ZonedDateTimeHandlerTests.cs @@ -0,0 +1,131 @@ +// Copyright (c) 2002-2018 "Neo Technology," +// Network Engine for Objects in Lund AB [http://neotechnology.com] +// +// This file is part of Neo4j. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using System.Collections; +using System.Collections.Generic; +using FluentAssertions; +using FluentAssertions.Primitives; +using Moq; +using Neo4j.Driver.Internal; +using Neo4j.Driver.Internal.IO; +using Neo4j.Driver.Internal.IO.StructHandlers; +using Neo4j.Driver.Internal.Messaging; +using Neo4j.Driver.Internal.Types; +using Neo4j.Driver.V1; +using Xunit; + +namespace Neo4j.Driver.Tests.IO.StructHandlers +{ + public class ZonedDateTimeHandlerTests : StructHandlerTests + { + internal override IPackStreamStructHandler HandlerUnderTest => new ZonedDateTimeHandler(); + + [Fact] + public void ShouldWriteDateTimeWithOffset() + { + var dateTime = new ZonedDateTime(1978, 12, 16, 12, 35, 59, 128000987, + Zone.Of((int) TimeSpan.FromMinutes(-150).TotalSeconds)); + var writerMachine = CreateWriterMachine(); + var writer = writerMachine.Writer(); + + writer.Write(dateTime); + + var readerMachine = CreateReaderMachine(writerMachine.GetOutput()); + var reader = readerMachine.Reader(); + + reader.PeekNextType().Should().Be(PackStream.PackType.Struct); + reader.ReadStructHeader().Should().Be(3); + reader.ReadStructSignature().Should().Be((byte) 'F'); + reader.Read().Should().Be(282659759L); + reader.Read().Should().Be(128000987L); + reader.Read().Should().Be(-9000L); + } + + [Fact] + public void ShouldReadDateTimeWithOffset() + { + var writerMachine = CreateWriterMachine(); + var writer = writerMachine.Writer(); + + writer.WriteStructHeader(ZonedDateTimeHandler.StructSize, ZonedDateTimeHandler.StructTypeWithOffset); + writer.Write(282659759); + writer.Write(128000987); + writer.Write(-9000); + + var readerMachine = CreateReaderMachine(writerMachine.GetOutput()); + var reader = readerMachine.Reader(); + var value = reader.Read(); + + value.Should().NotBeNull(); + value.Should().BeOfType().Which.Year.Should().Be(1978); + value.Should().BeOfType().Which.Month.Should().Be(12); + value.Should().BeOfType().Which.Day.Should().Be(16); + value.Should().BeOfType().Which.Hour.Should().Be(12); + value.Should().BeOfType().Which.Minute.Should().Be(35); + value.Should().BeOfType().Which.Second.Should().Be(59); + value.Should().BeOfType().Which.Nanosecond.Should().Be(128000987); + value.Should().BeOfType().Which.Zone.Should().BeOfType().Which.OffsetSeconds.Should().Be((int)TimeSpan.FromMinutes(-150).TotalSeconds); + } + + [Fact] + public void ShouldWriteDateTimeWithZoneId() + { + var dateTime = new ZonedDateTime(1978, 12, 16, 12, 35, 59, 128000987, Zone.Of("Europe/Istanbul")); + var writerMachine = CreateWriterMachine(); + var writer = writerMachine.Writer(); + + writer.Write(dateTime); + + var readerMachine = CreateReaderMachine(writerMachine.GetOutput()); + var reader = readerMachine.Reader(); + + reader.PeekNextType().Should().Be(PackStream.PackType.Struct); + reader.ReadStructHeader().Should().Be(3); + reader.ReadStructSignature().Should().Be((byte)'f'); + reader.Read().Should().Be(282659759L); + reader.Read().Should().Be(128000987L); + reader.Read().Should().Be("Europe/Istanbul"); + } + + [Fact] + public void ShouldReadDateTimeWithZoneId() + { + var writerMachine = CreateWriterMachine(); + var writer = writerMachine.Writer(); + + writer.WriteStructHeader(ZonedDateTimeHandler.StructSize, ZonedDateTimeHandler.StructTypeWithId); + writer.Write(282659759); + writer.Write(128000987); + writer.Write("Europe/Istanbul"); + + var readerMachine = CreateReaderMachine(writerMachine.GetOutput()); + var reader = readerMachine.Reader(); + var value = reader.Read(); + + value.Should().NotBeNull(); + value.Should().BeOfType().Which.Year.Should().Be(1978); + value.Should().BeOfType().Which.Month.Should().Be(12); + value.Should().BeOfType().Which.Day.Should().Be(16); + value.Should().BeOfType().Which.Hour.Should().Be(12); + value.Should().BeOfType().Which.Minute.Should().Be(35); + value.Should().BeOfType().Which.Second.Should().Be(59); + value.Should().BeOfType().Which.Nanosecond.Should().Be(128000987); + value.Should().BeOfType().Which.Zone.Should().BeOfType().Which.Id.Should().Be("Europe/Istanbul"); + } + } +} \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherDurationTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Types/DurationTests.cs similarity index 75% rename from Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherDurationTests.cs rename to Neo4j.Driver/Neo4j.Driver.Tests/Types/DurationTests.cs index 5f76a1235..e7c59aabd 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherDurationTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Types/DurationTests.cs @@ -23,13 +23,13 @@ namespace Neo4j.Driver.Tests.Types { - public class CypherDurationTests + public class DurationTests { [Fact] public void ShouldCreateDuration() { - var cypherDuration = new CypherDuration(15, 32, 785, 789215800); + var cypherDuration = new Duration(15, 32, 785, 789215800); cypherDuration.Months.Should().Be(15); cypherDuration.Days.Should().Be(32); @@ -40,7 +40,7 @@ public void ShouldCreateDuration() [Fact] public void ShouldCreateDurationWithSecondsOnly() { - var cypherDuration = new CypherDuration(785); + var cypherDuration = new Duration(785); cypherDuration.Months.Should().Be(0); cypherDuration.Days.Should().Be(0); @@ -51,7 +51,7 @@ public void ShouldCreateDurationWithSecondsOnly() [Fact] public void ShouldCreateDurationWithSecondsAndNanoseconds() { - var cypherDuration = new CypherDuration(785, 789215800); + var cypherDuration = new Duration(785, 789215800); cypherDuration.Months.Should().Be(0); cypherDuration.Days.Should().Be(0); @@ -62,7 +62,7 @@ public void ShouldCreateDurationWithSecondsAndNanoseconds() [Fact] public void ShouldCreateDurationWithDaysSecondsAndNanoseconds() { - var cypherDuration = new CypherDuration(45, 785, 789215800); + var cypherDuration = new Duration(45, 785, 789215800); cypherDuration.Months.Should().Be(0); cypherDuration.Days.Should().Be(45); @@ -80,7 +80,7 @@ public void ShouldCreateDurationWithDaysSecondsAndNanoseconds() [InlineData(0, 0, 0, 5, "P0M0DT0.000000005S")] public void ShouldGenerateCorrectString(int months, int days, int seconds, int nanoseconds, string expected) { - var cypherDuration = new CypherDuration(months, days, seconds, nanoseconds); + var cypherDuration = new Duration(months, days, seconds, nanoseconds); var cypherDurationStr = cypherDuration.ToString(); cypherDurationStr.Should().Be(expected); @@ -89,8 +89,8 @@ public void ShouldGenerateCorrectString(int months, int days, int seconds, int n [Fact] public void ShouldGenerateSameHashcode() { - var duration1 = new CypherDuration(15, 32, 785, 789215800); - var duration2 = new CypherDuration(15, 32, 785, 789215800); + var duration1 = new Duration(15, 32, 785, 789215800); + var duration2 = new Duration(15, 32, 785, 789215800); duration1.GetHashCode().Should().Be(duration2.GetHashCode()); } @@ -98,8 +98,8 @@ public void ShouldGenerateSameHashcode() [Fact] public void ShouldGenerateDifferentHashcode() { - var duration1 = new CypherDuration(15, 32, 785, 789215800); - var duration2 = new CypherDuration(15, 32, 785, 789215801); + var duration1 = new Duration(15, 32, 785, 789215800); + var duration2 = new Duration(15, 32, 785, 789215801); duration1.GetHashCode().Should().NotBe(duration2.GetHashCode()); } @@ -107,8 +107,8 @@ public void ShouldGenerateDifferentHashcode() [Fact] public void ShouldBeEqual() { - var duration1 = new CypherDuration(15, 32, 785, 789215800); - var duration2 = new CypherDuration(15, 32, 785, 789215800); + var duration1 = new Duration(15, 32, 785, 789215800); + var duration2 = new Duration(15, 32, 785, 789215800); duration1.Equals(duration2).Should().BeTrue(); } @@ -116,8 +116,8 @@ public void ShouldBeEqual() [Fact] public void ShouldNotBeEqual() { - var duration1 = new CypherDuration(15, 32, 785, 789215800); - var duration2 = new CypherDuration(15, 32, 786, 789215800); + var duration1 = new Duration(15, 32, 785, 789215800); + var duration2 = new Duration(15, 32, 786, 789215800); duration1.Equals(duration2).Should().BeFalse(); } @@ -125,7 +125,7 @@ public void ShouldNotBeEqual() [Fact] public void ShouldNotBeEqualToAnotherType() { - var duration = new CypherDuration(15, 32, 785, 789215800); + var duration = new Duration(15, 32, 785, 789215800); var other = "some string"; duration.Equals(other).Should().BeFalse(); @@ -134,7 +134,7 @@ public void ShouldNotBeEqualToAnotherType() [Fact] public void ShouldNotBeEqualToNull() { - var duration = new CypherDuration(15, 32, 785, 789215800); + var duration = new Duration(15, 32, 785, 789215800); var other = (object) null; duration.Equals(other).Should().BeFalse(); @@ -143,7 +143,7 @@ public void ShouldNotBeEqualToNull() [Fact] public void ShouldThrowOnCompareToOtherType() { - var duration1 = new CypherDuration(0, 0, 0, 0); + var duration1 = new Duration(0, 0, 0, 0); var ex = Record.Exception(() => duration1.CompareTo(new DateTime(1947, 12, 17))); @@ -153,7 +153,7 @@ public void ShouldThrowOnCompareToOtherType() [Fact] public void ShouldReportLargerOnCompareToNull() { - var duration1 = new CypherDuration(0, 0, 0, 0); + var duration1 = new Duration(0, 0, 0, 0); var comp = duration1.CompareTo(null); @@ -163,8 +163,8 @@ public void ShouldReportLargerOnCompareToNull() [Fact] public void ShouldReportLargerOnCompareTo() { - var duration1 = new CypherDuration(1, 12, 500, 999999999); - var duration2 = new CypherDuration(1, 12, 500, 0); + var duration1 = new Duration(1, 12, 500, 999999999); + var duration2 = new Duration(1, 12, 500, 0); var comp = duration1.CompareTo(duration2); @@ -174,8 +174,8 @@ public void ShouldReportLargerOnCompareTo() [Fact] public void ShouldReportLargerOnCompareToAbsolute() { - var duration1 = new CypherDuration(0, 1, 0, 1); - var duration2 = new CypherDuration(0, 0, 86400, 0); + var duration1 = new Duration(0, 1, 0, 1); + var duration2 = new Duration(0, 0, 86400, 0); var comp = duration1.CompareTo(duration2); @@ -185,8 +185,8 @@ public void ShouldReportLargerOnCompareToAbsolute() [Fact] public void ShouldReportEqualOnCompareTo() { - var duration1 = new CypherDuration(1, 12, 500, 999999999); - var duration2 = new CypherDuration(1, 12, 500, 999999999); + var duration1 = new Duration(1, 12, 500, 999999999); + var duration2 = new Duration(1, 12, 500, 999999999); var comp = duration1.CompareTo(duration2); @@ -196,8 +196,8 @@ public void ShouldReportEqualOnCompareTo() [Fact] public void ShouldReportEqualOnCompareToAbsolute() { - var duration1 = new CypherDuration(0, 1, 0, 999999999); - var duration2 = new CypherDuration(0, 0, 86400, 999999999); + var duration1 = new Duration(0, 1, 0, 999999999); + var duration2 = new Duration(0, 0, 86400, 999999999); var comp = duration1.CompareTo(duration2); @@ -207,8 +207,8 @@ public void ShouldReportEqualOnCompareToAbsolute() [Fact] public void ShouldReportSmallerOnCompareTo() { - var duration1 = new CypherDuration(1, 12, 500, 999999999); - var duration2 = new CypherDuration(1, 12, 501, 0); + var duration1 = new Duration(1, 12, 500, 999999999); + var duration2 = new Duration(1, 12, 501, 0); var comp = duration1.CompareTo(duration2); @@ -218,8 +218,8 @@ public void ShouldReportSmallerOnCompareTo() [Fact] public void ShouldReportSmallerOnCompareToAbsolute() { - var duration1 = new CypherDuration(0, 1, 0, 999999999); - var duration2 = new CypherDuration(0, 0, 86401, 999999999); + var duration1 = new Duration(0, 1, 0, 999999999); + var duration2 = new Duration(0, 0, 86401, 999999999); var comp = duration1.CompareTo(duration2); @@ -229,7 +229,7 @@ public void ShouldReportSmallerOnCompareToAbsolute() [Fact] public void ShouldBeConvertableToString() { - var duration = new CypherDuration(12, 15, 59, 660000999); + var duration = new Duration(12, 15, 59, 660000999); var durationStr1 = Convert.ToString(duration); var durationStr2 = Convert.ChangeType(duration, typeof(string)); @@ -240,7 +240,7 @@ public void ShouldBeConvertableToString() [Fact] public void ShouldThrowWhenConversionIsNotSupported() { - var duration = new CypherDuration(12, 15, 59, 660000999); + var duration = new Duration(12, 15, 59, 660000999); var conversions = new Action[] { () => Convert.ToDateTime(duration), diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherDateTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Types/LocalDateTests.cs similarity index 79% rename from Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherDateTests.cs rename to Neo4j.Driver/Neo4j.Driver.Tests/Types/LocalDateTests.cs index 51d9e8a25..3b3425a5a 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherDateTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Types/LocalDateTests.cs @@ -23,13 +23,13 @@ namespace Neo4j.Driver.Tests.Types { - public class CypherDateTests + public class LocalDateTests { [Fact] public void ShouldCreateDateWithDateTimeComponents() { - var cypherDate = new CypherDate(1947, 12, 17); + var cypherDate = new LocalDate(1947, 12, 17); cypherDate.DateTime.Should().Be(new DateTime(1947, 12, 17)); } @@ -38,7 +38,7 @@ public void ShouldCreateDateWithDateTimeComponents() public void ShouldCreateDateWithDateTime() { var date = new DateTime(1947, 12, 17); - var cypherDate = new CypherDate(date); + var cypherDate = new LocalDate(date); cypherDate.DateTime.Should().Be(date); } @@ -48,7 +48,7 @@ public void ShouldCreateDateWithDateTime() [InlineData(1000000000)] public void ShouldThrowOnInvalidYear(int year) { - var ex = Record.Exception(() => new CypherDate(year, 1, 1)); + var ex = Record.Exception(() => new LocalDate(year, 1, 1)); ex.Should().NotBeNull().And.BeOfType(); } @@ -58,7 +58,7 @@ public void ShouldThrowOnInvalidYear(int year) [InlineData(13)] public void ShouldThrowOnInvalidMonth(int month) { - var ex = Record.Exception(() => new CypherDate(1990, month, 1)); + var ex = Record.Exception(() => new LocalDate(1990, month, 1)); ex.Should().NotBeNull().And.BeOfType(); } @@ -71,7 +71,7 @@ public void ShouldThrowOnInvalidMonth(int month) [InlineData(2018, 12, -1)] public void ShouldThrowOnInvalidDay(int year, int month, int day) { - var ex = Record.Exception(() => new CypherDate(year, month, day)); + var ex = Record.Exception(() => new LocalDate(year, month, day)); ex.Should().NotBeNull().And.BeOfType(); } @@ -84,7 +84,7 @@ public void ShouldThrowOnInvalidDay(int year, int month, int day) [InlineData(9999999)] public void ShouldThrowOnOverflow(int year) { - var date = new CypherDate(year, 1, 1); + var date = new LocalDate(year, 1, 1); var ex = Record.Exception(() => date.DateTime); ex.Should().NotBeNull().And.BeOfType(); @@ -100,7 +100,7 @@ public void ShouldThrowOnOverflow(int year) [InlineData(-999999, 1, 1, "-999999-01-01")] public void ShouldGenerateCorrectString(int year, int month, int day, string expected) { - var cypherDate = new CypherDate(year, month, day); + var cypherDate = new LocalDate(year, month, day); var cypherDateStr = cypherDate.ToString(); cypherDateStr.Should().Be(expected); @@ -109,8 +109,8 @@ public void ShouldGenerateCorrectString(int year, int month, int day, string exp [Fact] public void ShouldGenerateSameHashcode() { - var date1 = new CypherDate(1947, 12, 17); - var date2 = new CypherDate(new DateTime(1947, 12, 17)); + var date1 = new LocalDate(1947, 12, 17); + var date2 = new LocalDate(new DateTime(1947, 12, 17)); date1.GetHashCode().Should().Be(date2.GetHashCode()); } @@ -118,8 +118,8 @@ public void ShouldGenerateSameHashcode() [Fact] public void ShouldGenerateDifferentHashcode() { - var date1 = new CypherDate(1947, 12, 18); - var date2 = new CypherDate(new DateTime(1947, 12, 17)); + var date1 = new LocalDate(1947, 12, 18); + var date2 = new LocalDate(new DateTime(1947, 12, 17)); date1.GetHashCode().Should().NotBe(date2.GetHashCode()); } @@ -127,8 +127,8 @@ public void ShouldGenerateDifferentHashcode() [Fact] public void ShouldBeEqual() { - var date1 = new CypherDate(1947, 12, 17); - var date2 = new CypherDate(new DateTime(1947, 12, 17)); + var date1 = new LocalDate(1947, 12, 17); + var date2 = new LocalDate(new DateTime(1947, 12, 17)); date1.Equals(date2).Should().BeTrue(); } @@ -136,8 +136,8 @@ public void ShouldBeEqual() [Fact] public void ShouldNotBeEqual() { - var date1 = new CypherDate(1947, 12, 17); - var date2 = new CypherDate(new DateTime(1947, 12, 18)); + var date1 = new LocalDate(1947, 12, 17); + var date2 = new LocalDate(new DateTime(1947, 12, 18)); date1.Equals(date2).Should().BeFalse(); } @@ -145,7 +145,7 @@ public void ShouldNotBeEqual() [Fact] public void ShouldNotBeEqualToAnotherType() { - var date = new CypherDate(1947, 12, 17); + var date = new LocalDate(1947, 12, 17); var other = "some string"; date.Equals(other).Should().BeFalse(); @@ -154,7 +154,7 @@ public void ShouldNotBeEqualToAnotherType() [Fact] public void ShouldNotBeEqualToNull() { - var date = new CypherDate(1947, 12, 17); + var date = new LocalDate(1947, 12, 17); var other = (object) null; date.Equals(other).Should().BeFalse(); @@ -163,7 +163,7 @@ public void ShouldNotBeEqualToNull() [Fact] public void ShouldThrowOnCompareToOtherType() { - var date1 = new CypherDate(1947, 12, 17); + var date1 = new LocalDate(1947, 12, 17); var ex = Record.Exception(() => date1.CompareTo(new DateTime(1947, 12, 17))); @@ -173,7 +173,7 @@ public void ShouldThrowOnCompareToOtherType() [Fact] public void ShouldReportLargerOnCompareToNull() { - var date1 = new CypherDate(1947, 12, 17); + var date1 = new LocalDate(1947, 12, 17); var comp = date1.CompareTo(null); @@ -183,8 +183,8 @@ public void ShouldReportLargerOnCompareToNull() [Fact] public void ShouldReportLargerOnCompareTo() { - var date1 = new CypherDate(1947, 12, 17); - var date2 = new CypherDate(1947, 12, 16); + var date1 = new LocalDate(1947, 12, 17); + var date2 = new LocalDate(1947, 12, 16); var comp = date1.CompareTo(date2); @@ -194,8 +194,8 @@ public void ShouldReportLargerOnCompareTo() [Fact] public void ShouldReportEqualOnCompareTo() { - var date1 = new CypherDate(1947, 12, 17); - var date2 = new CypherDate(1947, 12, 17); + var date1 = new LocalDate(1947, 12, 17); + var date2 = new LocalDate(1947, 12, 17); var comp = date1.CompareTo(date2); @@ -205,8 +205,8 @@ public void ShouldReportEqualOnCompareTo() [Fact] public void ShouldReportSmallerOnCompareTo() { - var date1 = new CypherDate(1947, 12, 16); - var date2 = new CypherDate(1947, 12, 17); + var date1 = new LocalDate(1947, 12, 16); + var date2 = new LocalDate(1947, 12, 17); var comp = date1.CompareTo(date2); @@ -217,7 +217,7 @@ public void ShouldReportSmallerOnCompareTo() public void ShouldBeConvertableToDateTime() { var date = new DateTime(1947, 12, 16); - var date1 = new CypherDate(date); + var date1 = new LocalDate(date); var date2 = Convert.ToDateTime(date1); var date3 = Convert.ChangeType(date1, typeof(DateTime)); @@ -228,7 +228,7 @@ public void ShouldBeConvertableToDateTime() [Fact] public void ShouldBeConvertableToString() { - var date = new CypherDate(1947, 12, 16); + var date = new LocalDate(1947, 12, 16); var dateStr1 = Convert.ToString(date); var dateStr2 = Convert.ChangeType(date, typeof(string)); @@ -239,7 +239,7 @@ public void ShouldBeConvertableToString() [Fact] public void ShouldThrowWhenConversionIsNotSupported() { - var date = new CypherDate(1947, 12, 16); + var date = new LocalDate(1947, 12, 16); var conversions = new Action[] { () => Convert.ToBoolean(date), diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherDateTimeTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Types/LocalDateTimeTests.cs similarity index 75% rename from Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherDateTimeTests.cs rename to Neo4j.Driver/Neo4j.Driver.Tests/Types/LocalDateTimeTests.cs index 7e6519e5d..eb4baefaf 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherDateTimeTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Types/LocalDateTimeTests.cs @@ -24,13 +24,13 @@ namespace Neo4j.Driver.Tests.Types { - public class CypherDateTimeTests + public class LocalDateTimeTests { [Fact] public void ShouldCreateDateTimeWithDateTimeComponents() { - var cypherDateTime = new CypherDateTime(1947, 12, 17, 23, 49, 54); + var cypherDateTime = new LocalDateTime(1947, 12, 17, 23, 49, 54); cypherDateTime.DateTime.Should().Be(new DateTime(1947, 12, 17, 23, 49, 54)); } @@ -38,7 +38,7 @@ public void ShouldCreateDateTimeWithDateTimeComponents() [Fact] public void ShouldCreateDateTimeWithDateTimeComponentsWithNanoseconds() { - var cypherDateTime = new CypherDateTime(1947, 12, 17, 23, 49, 54, 192794500); + var cypherDateTime = new LocalDateTime(1947, 12, 17, 23, 49, 54, 192794500); cypherDateTime.DateTime.Should().Be(new DateTime(1947, 12, 17, 23, 49, 54).AddTicks(1927945)); } @@ -47,7 +47,7 @@ public void ShouldCreateDateTimeWithDateTimeComponentsWithNanoseconds() public void ShouldCreateDateTimeWithDateTime() { var dateTime = new DateTime(1947, 12, 17, 23, 49, 54, 120, DateTimeKind.Local); - var cypherDateTime = new CypherDateTime(dateTime); + var cypherDateTime = new LocalDateTime(dateTime); cypherDateTime.DateTime.Should().Be(dateTime); } @@ -57,7 +57,7 @@ public void ShouldCreateDateTimeWithDateTime() [InlineData(1000000000)] public void ShouldThrowOnInvalidYear(int year) { - var ex = Record.Exception(() => new CypherDateTime(year, 1, 1, 0, 0, 0)); + var ex = Record.Exception(() => new LocalDateTime(year, 1, 1, 0, 0, 0)); ex.Should().NotBeNull().And.BeOfType(); } @@ -67,7 +67,7 @@ public void ShouldThrowOnInvalidYear(int year) [InlineData(13)] public void ShouldThrowOnInvalidMonth(int month) { - var ex = Record.Exception(() => new CypherDateTime(1990, month, 1, 0, 0, 0)); + var ex = Record.Exception(() => new LocalDateTime(1990, month, 1, 0, 0, 0)); ex.Should().NotBeNull().And.BeOfType(); } @@ -80,7 +80,7 @@ public void ShouldThrowOnInvalidMonth(int month) [InlineData(2018, 12, -1)] public void ShouldThrowOnInvalidDay(int year, int month, int day) { - var ex = Record.Exception(() => new CypherDateTime(year, month, day, 0, 0, 0)); + var ex = Record.Exception(() => new LocalDateTime(year, month, day, 0, 0, 0)); ex.Should().NotBeNull().And.BeOfType(); } @@ -90,7 +90,7 @@ public void ShouldThrowOnInvalidDay(int year, int month, int day) [InlineData(24)] public void ShouldThrowOnInvalidHour(int hour) { - var ex = Record.Exception(() => new CypherDateTime(1990, 1, 1, hour, 0, 0)); + var ex = Record.Exception(() => new LocalDateTime(1990, 1, 1, hour, 0, 0)); ex.Should().NotBeNull().And.BeOfType(); } @@ -101,7 +101,7 @@ public void ShouldThrowOnInvalidHour(int hour) [InlineData(61)] public void ShouldThrowOnInvalidMinute(int minute) { - var ex = Record.Exception(() => new CypherDateTime(1990, 1, 1, 0, minute, 0)); + var ex = Record.Exception(() => new LocalDateTime(1990, 1, 1, 0, minute, 0)); ex.Should().NotBeNull().And.BeOfType(); } @@ -112,7 +112,7 @@ public void ShouldThrowOnInvalidMinute(int minute) [InlineData(61)] public void ShouldThrowOnInvalidSecond(int second) { - var ex = Record.Exception(() => new CypherDateTime(1990, 1, 1, 0, 0, second)); + var ex = Record.Exception(() => new LocalDateTime(1990, 1, 1, 0, 0, second)); ex.Should().NotBeNull().And.BeOfType(); } @@ -122,7 +122,7 @@ public void ShouldThrowOnInvalidSecond(int second) [InlineData(999_999_999 + 1)] public void ShouldThrowOnInvalidNanosecond(int nanosecond) { - var ex = Record.Exception(() => new CypherDateTime(1990, 1, 1, 0, 0, 0, nanosecond)); + var ex = Record.Exception(() => new LocalDateTime(1990, 1, 1, 0, 0, 0, nanosecond)); ex.Should().NotBeNull().And.BeOfType(); } @@ -135,7 +135,7 @@ public void ShouldThrowOnInvalidNanosecond(int nanosecond) [InlineData(9999999)] public void ShouldThrowOnOverflow(int year) { - var dateTime = new CypherDateTime(year, 1, 1, 0, 0, 0, 0); + var dateTime = new LocalDateTime(year, 1, 1, 0, 0, 0, 0); var ex = Record.Exception(() => dateTime.DateTime); ex.Should().NotBeNull().And.BeOfType(); @@ -150,7 +150,7 @@ public void ShouldThrowOnOverflow(int year) [InlineData(999000001)] public void ShouldThrowOnTruncation(int nanosecond) { - var dateTime = new CypherDateTime(1, 1, 1, 0, 0, 0, nanosecond); + var dateTime = new LocalDateTime(1, 1, 1, 0, 0, 0, nanosecond); var ex = Record.Exception(() => dateTime.DateTime); ex.Should().NotBeNull().And.BeOfType(); @@ -166,7 +166,7 @@ public void ShouldThrowOnTruncation(int nanosecond) [InlineData(-999999, 1, 1, 5, 1, 25, 1, "-999999-01-01T05:01:25.000000001")] public void ShouldGenerateCorrectString(int year, int month, int day, int hour, int minute, int second, int nanosecond, string expected) { - var cypherDateTime = new CypherDateTime(year, month, day, hour, minute, second, nanosecond); + var cypherDateTime = new LocalDateTime(year, month, day, hour, minute, second, nanosecond); var cypherDateTimeStr = cypherDateTime.ToString(); cypherDateTimeStr.Should().Be(expected); @@ -175,8 +175,8 @@ public void ShouldGenerateCorrectString(int year, int month, int day, int hour, [Fact] public void ShouldGenerateSameHashcode() { - var dateTime1 = new CypherDateTime(1947, 12, 17, 15, 12, 01, 789000000); - var dateTime2 = new CypherDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 789, DateTimeKind.Local)); + var dateTime1 = new LocalDateTime(1947, 12, 17, 15, 12, 01, 789000000); + var dateTime2 = new LocalDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 789, DateTimeKind.Local)); dateTime1.GetHashCode().Should().Be(dateTime2.GetHashCode()); } @@ -184,8 +184,8 @@ public void ShouldGenerateSameHashcode() [Fact] public void ShouldGenerateDifferentHashcode() { - var dateTime1 = new CypherDateTime(1947, 12, 17, 15, 12, 01, 789000000); - var dateTime2 = new CypherDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 790)); + var dateTime1 = new LocalDateTime(1947, 12, 17, 15, 12, 01, 789000000); + var dateTime2 = new LocalDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 790)); dateTime1.GetHashCode().Should().NotBe(dateTime2.GetHashCode()); } @@ -193,8 +193,8 @@ public void ShouldGenerateDifferentHashcode() [Fact] public void ShouldBeEqual() { - var dateTime1 = new CypherDateTime(1947, 12, 17, 15, 12, 01, 789000000); - var dateTime2 = new CypherDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 789, DateTimeKind.Local)); + var dateTime1 = new LocalDateTime(1947, 12, 17, 15, 12, 01, 789000000); + var dateTime2 = new LocalDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 789, DateTimeKind.Local)); dateTime1.Equals(dateTime2).Should().BeTrue(); } @@ -202,8 +202,8 @@ public void ShouldBeEqual() [Fact] public void ShouldNotBeEqual() { - var dateTime1 = new CypherDateTime(1947, 12, 17, 15, 12, 01, 789000000); - var dateTime2 = new CypherDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 788)); + var dateTime1 = new LocalDateTime(1947, 12, 17, 15, 12, 01, 789000000); + var dateTime2 = new LocalDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 788)); dateTime1.Equals(dateTime2).Should().BeFalse(); } @@ -211,7 +211,7 @@ public void ShouldNotBeEqual() [Fact] public void ShouldNotBeEqualToAnotherType() { - var dateTime = new CypherDateTime(1947, 12, 17, 15, 12, 01, 789000000); + var dateTime = new LocalDateTime(1947, 12, 17, 15, 12, 01, 789000000); var other = "some string"; dateTime.Equals(other).Should().BeFalse(); @@ -220,7 +220,7 @@ public void ShouldNotBeEqualToAnotherType() [Fact] public void ShouldNotBeEqualToNull() { - var dateTime = new CypherDateTime(1947, 12, 17, 15, 12, 01, 789000000); + var dateTime = new LocalDateTime(1947, 12, 17, 15, 12, 01, 789000000); var other = (object)null; dateTime.Equals(other).Should().BeFalse(); @@ -229,7 +229,7 @@ public void ShouldNotBeEqualToNull() [Fact] public void ShouldThrowOnCompareToOtherType() { - var dateTime1 = new CypherDateTime(1947, 12, 17, 0, 0, 0, 0); + var dateTime1 = new LocalDateTime(1947, 12, 17, 0, 0, 0, 0); var ex = Record.Exception(() => dateTime1.CompareTo(new DateTime(1947, 12, 17))); @@ -239,7 +239,7 @@ public void ShouldThrowOnCompareToOtherType() [Fact] public void ShouldReportLargerOnCompareToNull() { - var dateTime1 = new CypherDateTime(1947, 12, 17, 0, 0, 0, 0); + var dateTime1 = new LocalDateTime(1947, 12, 17, 0, 0, 0, 0); var comp = dateTime1.CompareTo(null); @@ -249,8 +249,8 @@ public void ShouldReportLargerOnCompareToNull() [Fact] public void ShouldReportLargerOnCompareTo() { - var dateTime1 = new CypherDateTime(1947, 12, 17, 0, 0, 0, 0); - var dateTime2 = new CypherDateTime(1947, 12, 16, 23, 59, 59, 999999999); + var dateTime1 = new LocalDateTime(1947, 12, 17, 0, 0, 0, 0); + var dateTime2 = new LocalDateTime(1947, 12, 16, 23, 59, 59, 999999999); var comp = dateTime1.CompareTo(dateTime2); @@ -260,8 +260,8 @@ public void ShouldReportLargerOnCompareTo() [Fact] public void ShouldReportEqualOnCompareTo() { - var dateTime1 = new CypherDateTime(1947, 12, 16, 23, 59, 59, 999999999); - var dateTime2 = new CypherDateTime(1947, 12, 16, 23, 59, 59, 999999999); + var dateTime1 = new LocalDateTime(1947, 12, 16, 23, 59, 59, 999999999); + var dateTime2 = new LocalDateTime(1947, 12, 16, 23, 59, 59, 999999999); var comp = dateTime1.CompareTo(dateTime2); @@ -271,8 +271,8 @@ public void ShouldReportEqualOnCompareTo() [Fact] public void ShouldReportSmallerOnCompareTo() { - var dateTime1 = new CypherDateTime(1947, 12, 16, 23, 59, 59, 999999999); - var dateTime2 = new CypherDateTime(1947, 12, 17, 0, 59, 59, 999999999); + var dateTime1 = new LocalDateTime(1947, 12, 16, 23, 59, 59, 999999999); + var dateTime2 = new LocalDateTime(1947, 12, 17, 0, 59, 59, 999999999); var comp = dateTime1.CompareTo(dateTime2); @@ -283,7 +283,7 @@ public void ShouldReportSmallerOnCompareTo() public void ShouldBeConvertableToDateTime() { var date = new DateTime(1947, 12, 16, 12, 15, 59, 660); - var date1 = new CypherDateTime(date); + var date1 = new LocalDateTime(date); var date2 = Convert.ToDateTime(date1); var date3 = Convert.ChangeType(date1, typeof(DateTime)); @@ -294,7 +294,7 @@ public void ShouldBeConvertableToDateTime() [Fact] public void ShouldBeConvertableToString() { - var date = new CypherDateTime(1947, 12, 16, 12, 15, 59, 660000999); + var date = new LocalDateTime(1947, 12, 16, 12, 15, 59, 660000999); var dateStr1 = Convert.ToString(date); var dateStr2 = Convert.ChangeType(date, typeof(string)); @@ -305,7 +305,7 @@ public void ShouldBeConvertableToString() [Fact] public void ShouldThrowWhenConversionIsNotSupported() { - var date = new CypherDateTime(1947, 12, 16, 12, 15, 59, 660000999); + var date = new LocalDateTime(1947, 12, 16, 12, 15, 59, 660000999); var conversions = new Action[] { () => Convert.ToBoolean(date), diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherTimeTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Types/LocalTimeTests.cs similarity index 75% rename from Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherTimeTests.cs rename to Neo4j.Driver/Neo4j.Driver.Tests/Types/LocalTimeTests.cs index 01364ed6e..2543da4ed 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherTimeTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Types/LocalTimeTests.cs @@ -23,13 +23,13 @@ namespace Neo4j.Driver.Tests.Types { - public class CypherTimeTests + public class LocalTimeTests { [Fact] public void ShouldCreateTimeWithTimeComponents() { - var cypherTime = new CypherTime(13, 15, 59); + var cypherTime = new LocalTime(13, 15, 59); cypherTime.Time.Should().Be(new TimeSpan(13, 15, 59)); } @@ -38,7 +38,7 @@ public void ShouldCreateTimeWithTimeComponents() public void ShouldCreateTimeWithTimeSpan() { var time = new TimeSpan(0, 13, 59, 59, 255); - var cypherTime = new CypherTime(time); + var cypherTime = new LocalTime(time); cypherTime.Time.Should().Be(time); } @@ -48,7 +48,7 @@ public void ShouldCreateTimeWithTimeSpan() [InlineData(24)] public void ShouldThrowOnInvalidHour(int hour) { - var ex = Record.Exception(() => new CypherTime(hour, 0, 0, 0)); + var ex = Record.Exception(() => new LocalTime(hour, 0, 0, 0)); ex.Should().NotBeNull().And.BeOfType(); } @@ -59,7 +59,7 @@ public void ShouldThrowOnInvalidHour(int hour) [InlineData(61)] public void ShouldThrowOnInvalidMinute(int minute) { - var ex = Record.Exception(() => new CypherTime(0, minute, 0, 0)); + var ex = Record.Exception(() => new LocalTime(0, minute, 0, 0)); ex.Should().NotBeNull().And.BeOfType(); } @@ -70,7 +70,7 @@ public void ShouldThrowOnInvalidMinute(int minute) [InlineData(61)] public void ShouldThrowOnInvalidSecond(int second) { - var ex = Record.Exception(() => new CypherTime(0, 0, second, 0)); + var ex = Record.Exception(() => new LocalTime(0, 0, second, 0)); ex.Should().NotBeNull().And.BeOfType(); } @@ -80,7 +80,7 @@ public void ShouldThrowOnInvalidSecond(int second) [InlineData(999_999_999 + 1)] public void ShouldThrowOnInvalidNanosecond(int nanosecond) { - var ex = Record.Exception(() => new CypherTime(0, 0, 0, nanosecond)); + var ex = Record.Exception(() => new LocalTime(0, 0, 0, nanosecond)); ex.Should().NotBeNull().And.BeOfType(); } @@ -94,7 +94,7 @@ public void ShouldThrowOnInvalidNanosecond(int nanosecond) [InlineData(999000001)] public void ShouldThrowOnTruncation(int nanosecond) { - var time = new CypherTime(0, 0, 0, nanosecond); + var time = new LocalTime(0, 0, 0, nanosecond); var ex = Record.Exception(() => time.Time); ex.Should().NotBeNull().And.BeOfType(); @@ -106,7 +106,7 @@ public void ShouldThrowOnTruncation(int nanosecond) [InlineData(0, 1, 2, 5001, "00:01:02.000005001")] public void ShouldGenerateCorrectString(int hour, int minute, int second, int nanosecond, string expected) { - var cypherTime = new CypherTime(hour, minute, second, nanosecond); + var cypherTime = new LocalTime(hour, minute, second, nanosecond); var cypherTimeStr = cypherTime.ToString(); cypherTimeStr.Should().Be(expected); @@ -115,9 +115,9 @@ public void ShouldGenerateCorrectString(int hour, int minute, int second, int na [Fact] public void ShouldGenerateSameHashcode() { - var time1 = new CypherTime(12, 49, 55, 123000000); - var time2 = new CypherTime(new DateTime(2017, 1, 1, 12, 49, 55, 123)); - var time3 = new CypherTime(new TimeSpan(0, 12, 49, 55, 123)); + var time1 = new LocalTime(12, 49, 55, 123000000); + var time2 = new LocalTime(new DateTime(2017, 1, 1, 12, 49, 55, 123)); + var time3 = new LocalTime(new TimeSpan(0, 12, 49, 55, 123)); time1.GetHashCode().Should().Be(time2.GetHashCode()).And.Be(time3.GetHashCode()); } @@ -125,9 +125,9 @@ public void ShouldGenerateSameHashcode() [Fact] public void ShouldGenerateDifferentHashcode() { - var time1 = new CypherTime(12, 49, 55, 123000001); - var time2 = new CypherTime(new DateTime(2017, 1, 1, 12, 49, 55, 123)); - var time3 = new CypherTime(new TimeSpan(0, 12, 49, 55, 124)); + var time1 = new LocalTime(12, 49, 55, 123000001); + var time2 = new LocalTime(new DateTime(2017, 1, 1, 12, 49, 55, 123)); + var time3 = new LocalTime(new TimeSpan(0, 12, 49, 55, 124)); time1.GetHashCode().Should().NotBe(time2.GetHashCode()).And.NotBe(time3.GetHashCode()); } @@ -135,9 +135,9 @@ public void ShouldGenerateDifferentHashcode() [Fact] public void ShouldBeEqual() { - var time1 = new CypherTime(12, 49, 55, 123000000); - var time2 = new CypherTime(new DateTime(2017, 1, 1, 12, 49, 55, 123)); - var time3 = new CypherTime(new TimeSpan(0, 12, 49, 55, 123)); + var time1 = new LocalTime(12, 49, 55, 123000000); + var time2 = new LocalTime(new DateTime(2017, 1, 1, 12, 49, 55, 123)); + var time3 = new LocalTime(new TimeSpan(0, 12, 49, 55, 123)); time1.Equals(time2).Should().BeTrue(); time1.Equals(time3).Should().BeTrue(); @@ -146,9 +146,9 @@ public void ShouldBeEqual() [Fact] public void ShouldNotBeEqual() { - var time1 = new CypherTime(12, 49, 55, 123000001); - var time2 = new CypherTime(new DateTime(2017, 1, 1, 12, 49, 55, 123)); - var time3 = new CypherTime(new TimeSpan(0, 12, 49, 55, 125)); + var time1 = new LocalTime(12, 49, 55, 123000001); + var time2 = new LocalTime(new DateTime(2017, 1, 1, 12, 49, 55, 123)); + var time3 = new LocalTime(new TimeSpan(0, 12, 49, 55, 125)); time1.Equals(time2).Should().BeFalse(); time1.Equals(time3).Should().BeFalse(); @@ -157,7 +157,7 @@ public void ShouldNotBeEqual() [Fact] public void ShouldNotBeEqualToAnotherType() { - var time = new CypherTime(12, 49, 55, 123000001); + var time = new LocalTime(12, 49, 55, 123000001); var other = "some string"; time.Equals(other).Should().BeFalse(); @@ -166,7 +166,7 @@ public void ShouldNotBeEqualToAnotherType() [Fact] public void ShouldNotBeEqualToNull() { - var time = new CypherTime(12, 49, 55, 123000001); + var time = new LocalTime(12, 49, 55, 123000001); var other = (object)null; time.Equals(other).Should().BeFalse(); @@ -175,7 +175,7 @@ public void ShouldNotBeEqualToNull() [Fact] public void ShouldThrowOnCompareToOtherType() { - var time1 = new CypherTime(0, 0, 0, 0); + var time1 = new LocalTime(0, 0, 0, 0); var ex = Record.Exception(() => time1.CompareTo(new DateTime(1947, 12, 17))); @@ -185,7 +185,7 @@ public void ShouldThrowOnCompareToOtherType() [Fact] public void ShouldReportLargerOnCompareToNull() { - var time1 = new CypherTime(0, 0, 0, 0); + var time1 = new LocalTime(0, 0, 0, 0); var comp = time1.CompareTo(null); @@ -195,8 +195,8 @@ public void ShouldReportLargerOnCompareToNull() [Fact] public void ShouldReportLargerOnCompareTo() { - var time1 = new CypherTime(23, 59, 59, 999999999); - var time2 = new CypherTime(23, 59, 59, 0); + var time1 = new LocalTime(23, 59, 59, 999999999); + var time2 = new LocalTime(23, 59, 59, 0); var comp = time1.CompareTo(time2); @@ -206,8 +206,8 @@ public void ShouldReportLargerOnCompareTo() [Fact] public void ShouldReportEqualOnCompareTo() { - var time1 = new CypherTime(23, 59, 59, 999999999); - var time2 = new CypherTime(23, 59, 59, 999999999); + var time1 = new LocalTime(23, 59, 59, 999999999); + var time2 = new LocalTime(23, 59, 59, 999999999); var comp = time1.CompareTo(time2); @@ -217,8 +217,8 @@ public void ShouldReportEqualOnCompareTo() [Fact] public void ShouldReportSmallerOnCompareTo() { - var time1 = new CypherTime(0, 59, 59, 999999999); - var time2 = new CypherTime(23, 59, 59, 999999999); + var time1 = new LocalTime(0, 59, 59, 999999999); + var time2 = new LocalTime(23, 59, 59, 999999999); var comp = time1.CompareTo(time2); @@ -229,7 +229,7 @@ public void ShouldReportSmallerOnCompareTo() public void ShouldBeConvertableToDateTime() { var time = new TimeSpan(0, 12, 15, 59, 660); - var time1 = new CypherTime(DateTime.Today.Add(time)); + var time1 = new LocalTime(DateTime.Today.Add(time)); var time2 = Convert.ToDateTime(time1); var time3 = (DateTime)Convert.ChangeType(time1, typeof(DateTime)); @@ -242,7 +242,7 @@ public void ShouldBeConvertableToTimeSpan() { var time = new TimeSpan(0, 12, 15, 59, 660); var date = DateTime.Today.Add(time); - var time1 = new CypherTime(date); + var time1 = new LocalTime(date); var time2 = (TimeSpan)Convert.ChangeType(time1, typeof(TimeSpan)); time2.Should().Be(time); @@ -251,7 +251,7 @@ public void ShouldBeConvertableToTimeSpan() [Fact] public void ShouldBeConvertableToString() { - var time = new CypherTime(12, 15, 59, 660000999); + var time = new LocalTime(12, 15, 59, 660000999); var timeStr1 = Convert.ToString(time); var timeStr2 = Convert.ChangeType(time, typeof(string)); @@ -262,7 +262,7 @@ public void ShouldBeConvertableToString() [Fact] public void ShouldThrowWhenConversionIsNotSupported() { - var time = new CypherTime(12, 15, 59, 660000999); + var time = new LocalTime(12, 15, 59, 660000999); var conversions = new Action[] { () => Convert.ToBoolean(time), diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherTimeWithOffsetTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Types/OffsetTimeTests.cs similarity index 69% rename from Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherTimeWithOffsetTests.cs rename to Neo4j.Driver/Neo4j.Driver.Tests/Types/OffsetTimeTests.cs index 199a7565b..7b61292c6 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherTimeWithOffsetTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Types/OffsetTimeTests.cs @@ -23,13 +23,13 @@ namespace Neo4j.Driver.Tests.Types { - public class CypherTimeWithOffsetTests + public class OffsetTimeTests { [Fact] public void ShouldCreateTimeWithOffsetWithTimeComponents() { - var cypherTime = new CypherTimeWithOffset(13, 15, 59, 1500); + var cypherTime = new OffsetTime(13, 15, 59, 1500); cypherTime.Time.Should().Be(new TimeSpan(13, 15, 59)); cypherTime.Offset.Should().Be(TimeSpan.FromSeconds(1500)); @@ -39,7 +39,7 @@ public void ShouldCreateTimeWithOffsetWithTimeComponents() public void ShouldCreateTimeWithOffsetWithTimeSpan() { var time = new TimeSpan(0, 13, 59, 59, 255); - var cypherTime = new CypherTimeWithOffset(time, TimeSpan.FromSeconds(1500)); + var cypherTime = new OffsetTime(time, TimeSpan.FromSeconds(1500)); cypherTime.Time.Should().Be(time); cypherTime.Offset.Should().Be(TimeSpan.FromSeconds(1500)); @@ -49,7 +49,7 @@ public void ShouldCreateTimeWithOffsetWithTimeSpan() public void ShouldCreateTimeWithOffsetWithDateTime() { var time = new DateTime(1, 1, 1, 13, 59, 59, 25); - var cypherTime = new CypherTimeWithOffset(time, TimeSpan.FromSeconds(1500)); + var cypherTime = new OffsetTime(time, TimeSpan.FromSeconds(1500)); cypherTime.Time.Should().Be(time.TimeOfDay); cypherTime.Offset.Should().Be(TimeSpan.FromSeconds(1500)); @@ -60,7 +60,7 @@ public void ShouldCreateTimeWithOffsetWithDateTime() [InlineData(24)] public void ShouldThrowOnInvalidHour(int hour) { - var ex = Record.Exception(() => new CypherTimeWithOffset(hour, 0, 0, 0)); + var ex = Record.Exception(() => new OffsetTime(hour, 0, 0, 0)); ex.Should().NotBeNull().And.BeOfType(); } @@ -71,7 +71,7 @@ public void ShouldThrowOnInvalidHour(int hour) [InlineData(61)] public void ShouldThrowOnInvalidMinute(int minute) { - var ex = Record.Exception(() => new CypherTimeWithOffset(0, minute, 0, 0)); + var ex = Record.Exception(() => new OffsetTime(0, minute, 0, 0)); ex.Should().NotBeNull().And.BeOfType(); } @@ -82,7 +82,7 @@ public void ShouldThrowOnInvalidMinute(int minute) [InlineData(61)] public void ShouldThrowOnInvalidSecond(int second) { - var ex = Record.Exception(() => new CypherTimeWithOffset(0, 0, second, 0)); + var ex = Record.Exception(() => new OffsetTime(0, 0, second, 0)); ex.Should().NotBeNull().And.BeOfType(); } @@ -92,7 +92,7 @@ public void ShouldThrowOnInvalidSecond(int second) [InlineData(999_999_999 + 1)] public void ShouldThrowOnInvalidNanosecond(int nanosecond) { - var ex = Record.Exception(() => new CypherTimeWithOffset(0, 0, 0, nanosecond, 0)); + var ex = Record.Exception(() => new OffsetTime(0, 0, 0, nanosecond, 0)); ex.Should().NotBeNull().And.BeOfType(); } @@ -102,7 +102,7 @@ public void ShouldThrowOnInvalidNanosecond(int nanosecond) [InlineData(64801)] public void ShouldThrowOnInvalidOffset(int offset) { - var ex = Record.Exception(() => new CypherTimeWithOffset(0, 0, 0, 0, offset)); + var ex = Record.Exception(() => new OffsetTime(0, 0, 0, 0, offset)); ex.Should().NotBeNull().And.BeOfType(); } @@ -116,7 +116,7 @@ public void ShouldThrowOnInvalidOffset(int offset) [InlineData(999000001)] public void ShouldThrowOnTruncation(int nanosecond) { - var time = new CypherTimeWithOffset(0, 0, 0, nanosecond, 0); + var time = new OffsetTime(0, 0, 0, nanosecond, 0); var ex = Record.Exception(() => time.Time); ex.Should().NotBeNull().And.BeOfType(); @@ -132,7 +132,7 @@ public void ShouldThrowOnTruncation(int nanosecond) [InlineData(0, 1, 2, 750000000, 0, "00:01:02.750000000Z")] public void ShouldGenerateCorrectString(int hour, int minute, int second, int nanosecond, int offsetSeconds, string expected) { - var cypherTime = new CypherTimeWithOffset(hour, minute, second, nanosecond, offsetSeconds); + var cypherTime = new OffsetTime(hour, minute, second, nanosecond, offsetSeconds); var cypherTimeStr = cypherTime.ToString(); cypherTimeStr.Should().Be(expected); @@ -141,9 +141,9 @@ public void ShouldGenerateCorrectString(int hour, int minute, int second, int na [Fact] public void ShouldGenerateSameHashcode() { - var time1 = new CypherTimeWithOffset(12, 49, 55, 123000000, 1500); - var time2 = new CypherTimeWithOffset(new DateTime(2017, 1, 1, 12, 49, 55, 123), TimeSpan.FromSeconds(1500)); - var time3 = new CypherTimeWithOffset(new TimeSpan(0, 12, 49, 55, 123), TimeSpan.FromSeconds(1500)); + var time1 = new OffsetTime(12, 49, 55, 123000000, 1500); + var time2 = new OffsetTime(new DateTime(2017, 1, 1, 12, 49, 55, 123), TimeSpan.FromSeconds(1500)); + var time3 = new OffsetTime(new TimeSpan(0, 12, 49, 55, 123), TimeSpan.FromSeconds(1500)); time1.GetHashCode().Should().Be(time2.GetHashCode()).And.Be(time3.GetHashCode()); } @@ -151,9 +151,9 @@ public void ShouldGenerateSameHashcode() [Fact] public void ShouldGenerateDifferentHashcode() { - var time1 = new CypherTimeWithOffset(12, 49, 55, 123000000, 1500); - var time2 = new CypherTimeWithOffset(new DateTime(2017, 1, 1, 12, 49, 55, 123), TimeSpan.FromSeconds(1800)); - var time3 = new CypherTimeWithOffset(new TimeSpan(0, 12, 49, 55, 125), TimeSpan.FromSeconds(1500)); + var time1 = new OffsetTime(12, 49, 55, 123000000, 1500); + var time2 = new OffsetTime(new DateTime(2017, 1, 1, 12, 49, 55, 123), TimeSpan.FromSeconds(1800)); + var time3 = new OffsetTime(new TimeSpan(0, 12, 49, 55, 125), TimeSpan.FromSeconds(1500)); time1.GetHashCode().Should().NotBe(time2.GetHashCode()).And.NotBe(time3.GetHashCode()); } @@ -161,9 +161,9 @@ public void ShouldGenerateDifferentHashcode() [Fact] public void ShouldBeEqual() { - var time1 = new CypherTimeWithOffset(12, 49, 55, 123000000, 1500); - var time2 = new CypherTimeWithOffset(new DateTime(2017, 1, 1, 12, 49, 55, 123), TimeSpan.FromSeconds(1500)); - var time3 = new CypherTimeWithOffset(new TimeSpan(0, 12, 49, 55, 123), TimeSpan.FromSeconds(1500)); + var time1 = new OffsetTime(12, 49, 55, 123000000, 1500); + var time2 = new OffsetTime(new DateTime(2017, 1, 1, 12, 49, 55, 123), TimeSpan.FromSeconds(1500)); + var time3 = new OffsetTime(new TimeSpan(0, 12, 49, 55, 123), TimeSpan.FromSeconds(1500)); time1.Equals(time2).Should().BeTrue(); time1.Equals(time3).Should().BeTrue(); @@ -172,9 +172,9 @@ public void ShouldBeEqual() [Fact] public void ShouldNotBeEqual() { - var time1 = new CypherTimeWithOffset(12, 49, 55, 123000000, 1800); - var time2 = new CypherTimeWithOffset(new DateTime(2017, 1, 1, 12, 49, 55, 123), TimeSpan.FromSeconds(1200)); - var time3 = new CypherTimeWithOffset(new TimeSpan(0, 12, 49, 55, 125), TimeSpan.FromSeconds(1500)); + var time1 = new OffsetTime(12, 49, 55, 123000000, 1800); + var time2 = new OffsetTime(new DateTime(2017, 1, 1, 12, 49, 55, 123), TimeSpan.FromSeconds(1200)); + var time3 = new OffsetTime(new TimeSpan(0, 12, 49, 55, 125), TimeSpan.FromSeconds(1500)); time1.Equals(time2).Should().BeFalse(); time1.Equals(time3).Should().BeFalse(); @@ -183,7 +183,7 @@ public void ShouldNotBeEqual() [Fact] public void ShouldNotBeEqualToAnotherType() { - var time = new CypherTimeWithOffset(12, 49, 55, 123000000, 1800); + var time = new OffsetTime(12, 49, 55, 123000000, 1800); var other = "some string"; time.Equals(other).Should().BeFalse(); @@ -192,7 +192,7 @@ public void ShouldNotBeEqualToAnotherType() [Fact] public void ShouldNotBeEqualToNull() { - var time = new CypherTimeWithOffset(12, 49, 55, 123000000, 1800); + var time = new OffsetTime(12, 49, 55, 123000000, 1800); var other = (object)null; time.Equals(other).Should().BeFalse(); @@ -201,7 +201,7 @@ public void ShouldNotBeEqualToNull() [Fact] public void ShouldThrowOnCompareToOtherType() { - var time1 = new CypherTimeWithOffset(0, 0, 0, 0, 1800); + var time1 = new OffsetTime(0, 0, 0, 0, 1800); var ex = Record.Exception(() => time1.CompareTo(new DateTime(1947, 12, 17))); @@ -211,7 +211,7 @@ public void ShouldThrowOnCompareToOtherType() [Fact] public void ShouldReportLargerOnCompareToNull() { - var time1 = new CypherTimeWithOffset(0, 0, 0, 0, 1800); + var time1 = new OffsetTime(0, 0, 0, 0, 1800); var comp = time1.CompareTo(null); @@ -221,8 +221,8 @@ public void ShouldReportLargerOnCompareToNull() [Fact] public void ShouldReportLargerOnCompareTo() { - var time1 = new CypherTimeWithOffset(0, 0, 0, 0, 1800); - var time2 = new CypherTimeWithOffset(23, 59, 59, 999999999, 1800); + var time1 = new OffsetTime(0, 0, 0, 0, 1800); + var time2 = new OffsetTime(23, 59, 59, 999999999, 1800); var comp = time1.CompareTo(time2); @@ -232,8 +232,8 @@ public void ShouldReportLargerOnCompareTo() [Fact] public void ShouldReportLargerOnCompareToDiffOffset() { - var time1 = new CypherTimeWithOffset(23, 59, 59, 999999999, 1700); - var time2 = new CypherTimeWithOffset(23, 59, 59, 999999999, 1750); + var time1 = new OffsetTime(23, 59, 59, 999999999, 1700); + var time2 = new OffsetTime(23, 59, 59, 999999999, 1750); var comp = time1.CompareTo(time2); @@ -243,8 +243,8 @@ public void ShouldReportLargerOnCompareToDiffOffset() [Fact] public void ShouldReportEqualOnCompareTo() { - var time1 = new CypherTimeWithOffset(23, 59, 59, 999999999, 1800); - var time2 = new CypherTimeWithOffset(23, 59, 59, 999999999, 1800); + var time1 = new OffsetTime(23, 59, 59, 999999999, 1800); + var time2 = new OffsetTime(23, 59, 59, 999999999, 1800); var comp = time1.CompareTo(time2); @@ -254,8 +254,8 @@ public void ShouldReportEqualOnCompareTo() [Fact] public void ShouldReportEqualOnCompareToDiffOffset() { - var time1 = new CypherTimeWithOffset(23, 59, 59, 999999999, 1800); - var time2 = new CypherTimeWithOffset(0, 59, 59, 999999999, 5400); + var time1 = new OffsetTime(23, 59, 59, 999999999, 1800); + var time2 = new OffsetTime(0, 59, 59, 999999999, 5400); var comp = time1.CompareTo(time2); @@ -265,8 +265,8 @@ public void ShouldReportEqualOnCompareToDiffOffset() [Fact] public void ShouldReportSmallerOnCompareTo() { - var time1 = new CypherTimeWithOffset(0, 59, 59, 999999999, 1800); - var time2 = new CypherTimeWithOffset(23, 59, 59, 999999999, 1800); + var time1 = new OffsetTime(0, 59, 59, 999999999, 1800); + var time2 = new OffsetTime(23, 59, 59, 999999999, 1800); var comp = time1.CompareTo(time2); @@ -276,8 +276,8 @@ public void ShouldReportSmallerOnCompareTo() [Fact] public void ShouldReportSmallerOnCompareToDiffOffset() { - var time1 = new CypherTimeWithOffset(23, 59, 59, 999999999, 1800); - var time2 = new CypherTimeWithOffset(23, 59, 59, 999999999, -1799); + var time1 = new OffsetTime(23, 59, 59, 999999999, 1800); + var time2 = new OffsetTime(23, 59, 59, 999999999, -1799); var comp = time1.CompareTo(time2); @@ -287,7 +287,7 @@ public void ShouldReportSmallerOnCompareToDiffOffset() [Fact] public void ShouldBeConvertableToString() { - var time = new CypherTimeWithOffset(12, 15, 59, 660000999, 1800); + var time = new OffsetTime(12, 15, 59, 660000999, 1800); var timeStr1 = Convert.ToString(time); var timeStr2 = Convert.ChangeType(time, typeof(string)); @@ -298,7 +298,7 @@ public void ShouldBeConvertableToString() [Fact] public void ShouldThrowWhenConversionIsNotSupported() { - var time = new CypherTimeWithOffset(12, 15, 59, 660000999, 1800); + var time = new OffsetTime(12, 15, 59, 660000999, 1800); var conversions = new Action[] { () => Convert.ToDateTime(time), diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherPointTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Types/PointTests.cs similarity index 64% rename from Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherPointTests.cs rename to Neo4j.Driver/Neo4j.Driver.Tests/Types/PointTests.cs index 8c6f82e59..eb8c992d5 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherPointTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Types/PointTests.cs @@ -23,13 +23,13 @@ namespace Neo4j.Driver.Tests.Types { - public class CypherPointTests + public class PointTests { [Fact] public void ShouldCreate2DPoints() { - var point = new CypherPoint(1, 2.0, 3.0); + var point = new Point(1, 2.0, 3.0); point.Dimension.Should().Be(2); point.SrId.Should().Be(1); @@ -40,7 +40,7 @@ public void ShouldCreate2DPoints() [Fact] public void ShouldCreate3DPoints() { - var point = new CypherPoint(1, 2.0, 3.0, 4.0); + var point = new Point(1, 2.0, 3.0, 4.0); point.Dimension.Should().Be(3); point.SrId.Should().Be(1); @@ -52,7 +52,7 @@ public void ShouldCreate3DPoints() [Fact] public void ShouldCreate3DPointsWithNan() { - var point = new CypherPoint(1, 2.0, 3.0, double.NaN); + var point = new Point(1, 2.0, 3.0, double.NaN); point.Dimension.Should().Be(3); point.SrId.Should().Be(1); @@ -64,7 +64,7 @@ public void ShouldCreate3DPointsWithNan() [Fact] public void ShouldGenerateCorrectStringWhen2D() { - var point = new CypherPoint(1, 135.37340722, 11.92245761); + var point = new Point(1, 135.37340722, 11.92245761); var pointStr = point.ToString(); pointStr.Should().Be("Point{srId=1, x=135.37340722, y=11.92245761}"); @@ -73,7 +73,7 @@ public void ShouldGenerateCorrectStringWhen2D() [Fact] public void ShouldGenerateCorrectStringWhen3D() { - var point = new CypherPoint(1, 135.37340722, 11.92245761, 35.1201208); + var point = new Point(1, 135.37340722, 11.92245761, 35.1201208); var pointStr = point.ToString(); pointStr.Should().Be("Point{srId=1, x=135.37340722, y=11.92245761, z=35.1201208}"); @@ -82,8 +82,8 @@ public void ShouldGenerateCorrectStringWhen3D() [Fact] public void ShouldGenerateDifferentHashCodes2D() { - var point1 = new CypherPoint(1, 135.37340722, 11.92245761); - var point2 = new CypherPoint(1, 135.37340722, 11.92245762); + var point1 = new Point(1, 135.37340722, 11.92245761); + var point2 = new Point(1, 135.37340722, 11.92245762); point1.GetHashCode().Should().NotBe(point2.GetHashCode()); } @@ -91,8 +91,8 @@ public void ShouldGenerateDifferentHashCodes2D() [Fact] public void ShouldGenerateIdenticalHashCodes2D() { - var point1 = new CypherPoint(1, 135.37340722, 11.92245761); - var point2 = new CypherPoint(1, 135.37340722, 11.92245761); + var point1 = new Point(1, 135.37340722, 11.92245761); + var point2 = new Point(1, 135.37340722, 11.92245761); point1.GetHashCode().Should().Be(point2.GetHashCode()); } @@ -100,8 +100,8 @@ public void ShouldGenerateIdenticalHashCodes2D() [Fact] public void ShouldGenerateDifferentHashCodes3D() { - var point1 = new CypherPoint(1, 135.37340722, 11.92245761, 35.1201208); - var point2 = new CypherPoint(1, 135.37340722, 11.92245761, 35.1201209); + var point1 = new Point(1, 135.37340722, 11.92245761, 35.1201208); + var point2 = new Point(1, 135.37340722, 11.92245761, 35.1201209); point1.GetHashCode().Should().NotBe(point2.GetHashCode()); } @@ -109,8 +109,8 @@ public void ShouldGenerateDifferentHashCodes3D() [Fact] public void ShouldGenerateIdenticalHashCodes3D() { - var point1 = new CypherPoint(1, 135.37340722, 11.92245761, 35.1201208); - var point2 = new CypherPoint(1, 135.37340722, 11.92245761, 35.1201208); + var point1 = new Point(1, 135.37340722, 11.92245761, 35.1201208); + var point2 = new Point(1, 135.37340722, 11.92245761, 35.1201208); point1.GetHashCode().Should().Be(point2.GetHashCode()); } @@ -118,8 +118,8 @@ public void ShouldGenerateIdenticalHashCodes3D() [Fact] public void ShouldGenerateIdenticalHashCodes3DWhenZisNaN() { - var point1 = new CypherPoint(1, 135.37340722, 11.92245761, double.NaN); - var point2 = new CypherPoint(1, 135.37340722, 11.92245761, double.NaN); + var point1 = new Point(1, 135.37340722, 11.92245761, double.NaN); + var point2 = new Point(1, 135.37340722, 11.92245761, double.NaN); point1.GetHashCode().Should().Be(point2.GetHashCode()); } @@ -127,8 +127,8 @@ public void ShouldGenerateIdenticalHashCodes3DWhenZisNaN() [Fact] public void ShouldGenerateDifferentHashCodes2DAnd3D() { - var point1 = new CypherPoint(1, 135.37340722, 11.92245761); - var point2 = new CypherPoint(1, 135.37340722, 11.92245761, double.NaN); + var point1 = new Point(1, 135.37340722, 11.92245761); + var point2 = new Point(1, 135.37340722, 11.92245761, double.NaN); point1.GetHashCode().Should().NotBe(point2.GetHashCode()); } @@ -136,8 +136,8 @@ public void ShouldGenerateDifferentHashCodes2DAnd3D() [Fact] public void ShouldNotBeEqual2D() { - var point1 = new CypherPoint(1, 135.37340722, 11.92245761); - var point2 = new CypherPoint(1, 135.37340722, 11.92245762); + var point1 = new Point(1, 135.37340722, 11.92245761); + var point2 = new Point(1, 135.37340722, 11.92245762); point1.Equals(point2).Should().BeFalse(); } @@ -145,8 +145,8 @@ public void ShouldNotBeEqual2D() [Fact] public void ShouldBeEqual2D() { - var point1 = new CypherPoint(1, 135.37340722, 11.92245761); - var point2 = new CypherPoint(1, 135.37340722, 11.92245761); + var point1 = new Point(1, 135.37340722, 11.92245761); + var point2 = new Point(1, 135.37340722, 11.92245761); point1.Equals(point2).Should().BeTrue(); } @@ -154,8 +154,8 @@ public void ShouldBeEqual2D() [Fact] public void ShouldNotBeEqual3D() { - var point1 = new CypherPoint(1, 135.37340722, 11.92245761, 35.1201208); - var point2 = new CypherPoint(1, 135.37340722, 11.92245761, 35.1201209); + var point1 = new Point(1, 135.37340722, 11.92245761, 35.1201208); + var point2 = new Point(1, 135.37340722, 11.92245761, 35.1201209); point1.Equals(point2).Should().BeFalse(); } @@ -163,8 +163,8 @@ public void ShouldNotBeEqual3D() [Fact] public void ShouldBeEqual3D() { - var point1 = new CypherPoint(1, 135.37340722, 11.92245761, 35.1201208); - var point2 = new CypherPoint(1, 135.37340722, 11.92245761, 35.1201208); + var point1 = new Point(1, 135.37340722, 11.92245761, 35.1201208); + var point2 = new Point(1, 135.37340722, 11.92245761, 35.1201208); point1.Equals(point2).Should().BeTrue(); } @@ -172,8 +172,8 @@ public void ShouldBeEqual3D() [Fact] public void ShouldBeEqual3DWhenZisNaN() { - var point1 = new CypherPoint(1, 135.37340722, 11.92245761, double.NaN); - var point2 = new CypherPoint(1, 135.37340722, 11.92245761, double.NaN); + var point1 = new Point(1, 135.37340722, 11.92245761, double.NaN); + var point2 = new Point(1, 135.37340722, 11.92245761, double.NaN); point1.Equals(point2).Should().BeTrue(); } @@ -181,8 +181,8 @@ public void ShouldBeEqual3DWhenZisNaN() [Fact] public void ShouldNotBeEqual2DAnd3D() { - var point1 = new CypherPoint(1, 135.37340722, 11.92245761); - var point2 = new CypherPoint(1, 135.37340722, 11.92245761, double.NaN); + var point1 = new Point(1, 135.37340722, 11.92245761); + var point2 = new Point(1, 135.37340722, 11.92245761, double.NaN); point1.Equals(point2).Should().BeFalse(); } @@ -190,7 +190,7 @@ public void ShouldNotBeEqual2DAnd3D() [Fact] public void ShouldNotBeEqualToNull() { - var point1 = new CypherPoint(1, 135.37340722, 11.92245761); + var point1 = new Point(1, 135.37340722, 11.92245761); point1.Equals(null).Should().BeFalse(); } @@ -198,7 +198,7 @@ public void ShouldNotBeEqualToNull() [Fact] public void ShouldNotBeEqualToOtherType() { - var point1 = new CypherPoint(1, 135.37340722, 11.92245761); + var point1 = new Point(1, 135.37340722, 11.92245761); point1.Equals(new Node(1, new List(), new Dictionary())).Should().BeFalse(); point1.Equals(1).Should().BeFalse(); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherDateTimeWithOffsetTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Types/ZonedDateTimeWithOffsetTests.cs similarity index 71% rename from Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherDateTimeWithOffsetTests.cs rename to Neo4j.Driver/Neo4j.Driver.Tests/Types/ZonedDateTimeWithOffsetTests.cs index 4777e76ed..5dd629b8b 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherDateTimeWithOffsetTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Types/ZonedDateTimeWithOffsetTests.cs @@ -24,13 +24,13 @@ namespace Neo4j.Driver.Tests.Types { - public class CypherDateTimeWithOffsetTests + public class ZonedDateTimeWithOffsetTests { [Fact] public void ShouldCreateDateTimeWithOffsetWithDateTimeComponents() { - var cypherDateTime = new CypherDateTimeWithOffset(1947, 12, 17, 23, 49, 54, 1500); + var cypherDateTime = new ZonedDateTime(1947, 12, 17, 23, 49, 54, Zone.Of(1500)); cypherDateTime.DateTime.Should().Be(new DateTime(1947, 12, 17, 23, 49, 54)); cypherDateTime.Offset.Should().Be(TimeSpan.FromSeconds(1500)); @@ -39,7 +39,7 @@ public void ShouldCreateDateTimeWithOffsetWithDateTimeComponents() [Fact] public void ShouldCreateDateTimeWithOffsetWithDateTimeComponentsWithNanoseconds() { - var cypherDateTime = new CypherDateTimeWithOffset(1947, 12, 17, 23, 49, 54, 192794500, 1500); + var cypherDateTime = new ZonedDateTime(1947, 12, 17, 23, 49, 54, 192794500, Zone.Of(1500)); cypherDateTime.DateTime.Should().Be(new DateTime(1947, 12, 17, 23, 49, 54).AddTicks(1927945)); cypherDateTime.Offset.Should().Be(TimeSpan.FromSeconds(1500)); @@ -49,7 +49,7 @@ public void ShouldCreateDateTimeWithOffsetWithDateTimeComponentsWithNanoseconds( public void ShouldCreateDateTimeWithOffsetWithDateTime() { var dateTime = new DateTime(1947, 12, 17, 23, 49, 54, 120); - var cypherDateTime = new CypherDateTimeWithOffset(dateTime, TimeSpan.FromSeconds(1500)); + var cypherDateTime = new ZonedDateTime(dateTime, TimeSpan.FromSeconds(1500)); cypherDateTime.DateTime.Should().Be(dateTime); cypherDateTime.Offset.Should().Be(TimeSpan.FromSeconds(1500)); @@ -59,7 +59,7 @@ public void ShouldCreateDateTimeWithOffsetWithDateTime() public void ShouldCreateDateTimeWithOffsetWithDateTimeOffset() { var dateTime = new DateTimeOffset(1947, 12, 17, 23, 49, 54, 120, TimeSpan.FromSeconds(1500)); - var cypherDateTime = new CypherDateTimeWithOffset(dateTime); + var cypherDateTime = new ZonedDateTime(dateTime); cypherDateTime.DateTime.Should().Be(dateTime.DateTime); cypherDateTime.Offset.Should().Be(dateTime.Offset); @@ -70,7 +70,7 @@ public void ShouldCreateDateTimeWithOffsetWithDateTimeOffset() [InlineData(1000000000)] public void ShouldThrowOnInvalidYear(int year) { - var ex = Record.Exception(() => new CypherDateTimeWithOffset(year, 1, 1, 0, 0, 0, 0)); + var ex = Record.Exception(() => new ZonedDateTime(year, 1, 1, 0, 0, 0, Zone.Of(0))); ex.Should().NotBeNull().And.BeOfType(); } @@ -80,7 +80,7 @@ public void ShouldThrowOnInvalidYear(int year) [InlineData(13)] public void ShouldThrowOnInvalidMonth(int month) { - var ex = Record.Exception(() => new CypherDateTimeWithOffset(1990, month, 1, 0, 0, 0, 0)); + var ex = Record.Exception(() => new ZonedDateTime(1990, month, 1, 0, 0, 0, Zone.Of(0))); ex.Should().NotBeNull().And.BeOfType(); } @@ -93,7 +93,7 @@ public void ShouldThrowOnInvalidMonth(int month) [InlineData(2018, 12, -1)] public void ShouldThrowOnInvalidDay(int year, int month, int day) { - var ex = Record.Exception(() => new CypherDateTimeWithOffset(year, month, day, 0, 0, 0, 0)); + var ex = Record.Exception(() => new ZonedDateTime(year, month, day, 0, 0, 0, Zone.Of(0))); ex.Should().NotBeNull().And.BeOfType(); } @@ -103,7 +103,7 @@ public void ShouldThrowOnInvalidDay(int year, int month, int day) [InlineData(24)] public void ShouldThrowOnInvalidHour(int hour) { - var ex = Record.Exception(() => new CypherDateTimeWithOffset(1990, 1, 1, hour, 0, 0, 0)); + var ex = Record.Exception(() => new ZonedDateTime(1990, 1, 1, hour, 0, 0, Zone.Of(0))); ex.Should().NotBeNull().And.BeOfType(); } @@ -114,7 +114,7 @@ public void ShouldThrowOnInvalidHour(int hour) [InlineData(61)] public void ShouldThrowOnInvalidMinute(int minute) { - var ex = Record.Exception(() => new CypherDateTimeWithOffset(1990, 1, 1, 0, minute, 0, 0)); + var ex = Record.Exception(() => new ZonedDateTime(1990, 1, 1, 0, minute, 0, Zone.Of(0))); ex.Should().NotBeNull().And.BeOfType(); } @@ -125,7 +125,7 @@ public void ShouldThrowOnInvalidMinute(int minute) [InlineData(61)] public void ShouldThrowOnInvalidSecond(int second) { - var ex = Record.Exception(() => new CypherDateTimeWithOffset(1990, 1, 1, 0, 0, second, 0)); + var ex = Record.Exception(() => new ZonedDateTime(1990, 1, 1, 0, 0, second, Zone.Of(0))); ex.Should().NotBeNull().And.BeOfType(); } @@ -135,7 +135,7 @@ public void ShouldThrowOnInvalidSecond(int second) [InlineData(999_999_999 + 1)] public void ShouldThrowOnInvalidNanosecond(int nanosecond) { - var ex = Record.Exception(() => new CypherDateTimeWithOffset(1990, 1, 1, 0, 0, 0, nanosecond, 0)); + var ex = Record.Exception(() => new ZonedDateTime(1990, 1, 1, 0, 0, 0, nanosecond, Zone.Of(0))); ex.Should().NotBeNull().And.BeOfType(); } @@ -145,7 +145,7 @@ public void ShouldThrowOnInvalidNanosecond(int nanosecond) [InlineData(64801)] public void ShouldThrowOnInvalidOffset(int offset) { - var ex = Record.Exception(() => new CypherDateTimeWithOffset(1990, 1, 1, 0, 0, 0, 0, offset)); + var ex = Record.Exception(() => new ZonedDateTime(1990, 1, 1, 0, 0, 0, 0, Zone.Of(offset))); ex.Should().NotBeNull().And.BeOfType(); } @@ -154,7 +154,7 @@ public void ShouldThrowOnInvalidOffset(int offset) public void ShouldConvertToDateTimeOffset() { var dateTime = new DateTimeOffset(1947, 12, 17, 23, 49, 54, 120, TimeSpan.FromSeconds(1500)); - var cypherDateTime = new CypherDateTimeWithOffset(dateTime); + var cypherDateTime = new ZonedDateTime(dateTime); cypherDateTime.DateTimeOffset.Should().Be(dateTime); } @@ -167,7 +167,7 @@ public void ShouldConvertToDateTimeOffset() [InlineData(9999999)] public void ShouldThrowOnOverflow(int year) { - var dateTime = new CypherDateTimeWithOffset(year, 1, 1, 0, 0, 0, 0, 0); + var dateTime = new ZonedDateTime(year, 1, 1, 0, 0, 0, 0, Zone.Of(0)); var ex = Record.Exception(() => dateTime.DateTime); ex.Should().NotBeNull().And.BeOfType(); @@ -182,7 +182,7 @@ public void ShouldThrowOnOverflow(int year) [InlineData(999000001)] public void ShouldThrowOnTruncation(int nanosecond) { - var dateTime = new CypherDateTimeWithOffset(1, 1, 1, 0, 0, 0, nanosecond, 0); + var dateTime = new ZonedDateTime(1, 1, 1, 0, 0, 0, nanosecond, Zone.Of(0)); var ex = Record.Exception(() => dateTime.DateTime); ex.Should().NotBeNull().And.BeOfType(); @@ -201,7 +201,7 @@ public void ShouldThrowOnTruncation(int nanosecond) public void ShouldGenerateCorrectString(int year, int month, int day, int hour, int minute, int second, int nanosecond, int offsetSeconds, string expected) { var cypherDateTime = - new CypherDateTimeWithOffset(year, month, day, hour, minute, second, nanosecond, offsetSeconds); + new ZonedDateTime(year, month, day, hour, minute, second, nanosecond, Zone.Of(offsetSeconds)); var cypherDateTimeStr = cypherDateTime.ToString(); cypherDateTimeStr.Should().Be(expected); @@ -210,8 +210,8 @@ public void ShouldGenerateCorrectString(int year, int month, int day, int hour, [Fact] public void ShouldGenerateSameHashcode() { - var dateTime1 = new CypherDateTimeWithOffset(1947, 12, 17, 15, 12, 01, 789000000, 1800); - var dateTime2 = new CypherDateTimeWithOffset(new DateTime(1947, 12, 17, 15, 12, 01, 789), 1800); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 15, 12, 01, 789000000, Zone.Of(1800)); + var dateTime2 = new ZonedDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 789), 1800); dateTime1.GetHashCode().Should().Be(dateTime2.GetHashCode()); } @@ -219,8 +219,8 @@ public void ShouldGenerateSameHashcode() [Fact] public void ShouldGenerateDifferentHashcode() { - var dateTime1 = new CypherDateTimeWithOffset(1947, 12, 17, 15, 12, 01, 789000000, 1801); - var dateTime2 = new CypherDateTimeWithOffset(new DateTime(1947, 12, 17, 15, 12, 01, 790), 1800); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 15, 12, 01, 789000000, Zone.Of(1801)); + var dateTime2 = new ZonedDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 790), 1800); dateTime1.GetHashCode().Should().NotBe(dateTime2.GetHashCode()); } @@ -228,8 +228,8 @@ public void ShouldGenerateDifferentHashcode() [Fact] public void ShouldBeEqual() { - var dateTime1 = new CypherDateTimeWithOffset(1947, 12, 17, 15, 12, 01, 789000000, 1800); - var dateTime2 = new CypherDateTimeWithOffset(new DateTime(1947, 12, 17, 15, 12, 01, 789), 1800); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 15, 12, 01, 789000000, Zone.Of(1800)); + var dateTime2 = new ZonedDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 789), 1800); dateTime1.Should().Be(dateTime2); } @@ -237,8 +237,8 @@ public void ShouldBeEqual() [Fact] public void ShouldNotBeEqual() { - var dateTime1 = new CypherDateTimeWithOffset(1947, 12, 17, 15, 12, 01, 789000000, 1801); - var dateTime2 = new CypherDateTimeWithOffset(new DateTime(1947, 12, 17, 15, 12, 01, 790), 1800); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 15, 12, 01, 789000000, Zone.Of(1801)); + var dateTime2 = new ZonedDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 790), 1800); dateTime1.Should().NotBe(dateTime2); } @@ -246,7 +246,7 @@ public void ShouldNotBeEqual() [Fact] public void ShouldNotBeEqualToAnotherType() { - var dateTime = new CypherDateTimeWithOffset(1947, 12, 17, 15, 12, 01, 789000000, 1800); + var dateTime = new ZonedDateTime(1947, 12, 17, 15, 12, 01, 789000000, Zone.Of(1800)); var other = "some string"; dateTime.Equals(other).Should().BeFalse(); @@ -255,7 +255,7 @@ public void ShouldNotBeEqualToAnotherType() [Fact] public void ShouldNotBeEqualToNull() { - var dateTime = new CypherDateTimeWithOffset(1947, 12, 17, 15, 12, 01, 789000000, 1800); + var dateTime = new ZonedDateTime(1947, 12, 17, 15, 12, 01, 789000000, Zone.Of(1800)); var other = (object)null; dateTime.Equals(other).Should().BeFalse(); @@ -264,7 +264,7 @@ public void ShouldNotBeEqualToNull() [Fact] public void ShouldThrowOnCompareToOtherType() { - var dateTime1 = new CypherDateTimeWithOffset(1947, 12, 17, 0, 0, 0, 0, 1800); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 0, 0, 0, 0, Zone.Of(1800)); var ex = Record.Exception(() => dateTime1.CompareTo(new DateTime(1947, 12, 17))); @@ -274,7 +274,7 @@ public void ShouldThrowOnCompareToOtherType() [Fact] public void ShouldReportLargerOnCompareToNull() { - var dateTime1 = new CypherDateTimeWithOffset(1947, 12, 17, 0, 0, 0, 0, 1800); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 0, 0, 0, 0, Zone.Of(1800)); var comp = dateTime1.CompareTo(null); @@ -284,8 +284,8 @@ public void ShouldReportLargerOnCompareToNull() [Fact] public void ShouldReportLargerOnCompareTo() { - var dateTime1 = new CypherDateTimeWithOffset(1947, 12, 17, 0, 0, 0, 0, 1800); - var dateTime2 = new CypherDateTimeWithOffset(1947, 12, 16, 23, 59, 59, 999999999, 1800); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 0, 0, 0, 0, Zone.Of(1800)); + var dateTime2 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999999, Zone.Of(1800)); var comp = dateTime1.CompareTo(dateTime2); @@ -295,8 +295,8 @@ public void ShouldReportLargerOnCompareTo() [Fact] public void ShouldReportLargerOnCompareToDiffOffset() { - var dateTime1 = new CypherDateTimeWithOffset(1947, 12, 17, 23, 59, 59, 999999999, 1800); - var dateTime2 = new CypherDateTimeWithOffset(1947, 12, 16, 23, 59, 59, 999999999, 1750); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 23, 59, 59, 999999999, Zone.Of(1800)); + var dateTime2 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999999, Zone.Of(1750)); var comp = dateTime1.CompareTo(dateTime2); @@ -306,8 +306,8 @@ public void ShouldReportLargerOnCompareToDiffOffset() [Fact] public void ShouldReportEqualOnCompareTo() { - var dateTime1 = new CypherDateTimeWithOffset(1947, 12, 16, 23, 59, 59, 999999999, 1800); - var dateTime2 = new CypherDateTimeWithOffset(1947, 12, 16, 23, 59, 59, 999999999, 1800); + var dateTime1 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999999, Zone.Of(1800)); + var dateTime2 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999999, Zone.Of(1800)); var comp = dateTime1.CompareTo(dateTime2); @@ -317,8 +317,8 @@ public void ShouldReportEqualOnCompareTo() [Fact] public void ShouldReportEqualOnCompareToDiffOffset() { - var dateTime1 = new CypherDateTimeWithOffset(1947, 12, 16, 23, 59, 59, 999999999, 1800); - var dateTime2 = new CypherDateTimeWithOffset(1947, 12, 17, 0, 59, 59, 999999999, 5400); + var dateTime1 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999999, Zone.Of(1800)); + var dateTime2 = new ZonedDateTime(1947, 12, 17, 0, 59, 59, 999999999, Zone.Of(5400)); var comp = dateTime1.CompareTo(dateTime2); @@ -328,8 +328,8 @@ public void ShouldReportEqualOnCompareToDiffOffset() [Fact] public void ShouldReportSmallerOnCompareTo() { - var dateTime1 = new CypherDateTimeWithOffset(1947, 12, 16, 23, 59, 59, 999999999, 1800); - var dateTime2 = new CypherDateTimeWithOffset(1947, 12, 17, 0, 59, 59, 999999999, 1800); + var dateTime1 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999999, Zone.Of(1800)); + var dateTime2 = new ZonedDateTime(1947, 12, 17, 0, 59, 59, 999999999, Zone.Of(1800)); var comp = dateTime1.CompareTo(dateTime2); @@ -339,8 +339,8 @@ public void ShouldReportSmallerOnCompareTo() [Fact] public void ShouldReportSmallerOnCompareToDiffOffset() { - var dateTime1 = new CypherDateTimeWithOffset(1947, 12, 16, 23, 59, 59, 999999999, 1800); - var dateTime2 = new CypherDateTimeWithOffset(1947, 12, 16, 23, 59, 59, 999999999, -1799); + var dateTime1 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999999, Zone.Of(1800)); + var dateTime2 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999999, Zone.Of(-1799)); var comp = dateTime1.CompareTo(dateTime2); @@ -351,7 +351,7 @@ public void ShouldReportSmallerOnCompareToDiffOffset() public void ShouldBeConvertableToDateTime() { var date = new DateTime(1947, 12, 16, 12, 15, 59, 660); - var date1 = new CypherDateTimeWithOffset(date, 3600); + var date1 = new ZonedDateTime(date, 3600); var date2 = Convert.ToDateTime(date1); var date3 = Convert.ChangeType(date1, typeof(DateTime)); @@ -363,7 +363,7 @@ public void ShouldBeConvertableToDateTime() public void ShouldBeConvertableToDateTimeOffset() { var date = new DateTime(1947, 12, 16, 12, 15, 59, 660); - var date1 = new CypherDateTimeWithOffset(date, 3600); + var date1 = new ZonedDateTime(date, 3600); var date2 = Convert.ChangeType(date1, typeof(DateTimeOffset)); date2.Should().Be(new DateTimeOffset(date, TimeSpan.FromSeconds(3600))); @@ -372,7 +372,7 @@ public void ShouldBeConvertableToDateTimeOffset() [Fact] public void ShouldBeConvertableToString() { - var date = new CypherDateTimeWithOffset(1947, 12, 16, 12, 15, 59, 660000999, 3600); + var date = new ZonedDateTime(1947, 12, 16, 12, 15, 59, 660000999, Zone.Of(3600)); var dateStr1 = Convert.ToString(date); var dateStr2 = Convert.ChangeType(date, typeof(string)); @@ -383,7 +383,7 @@ public void ShouldBeConvertableToString() [Fact] public void ShouldThrowWhenConversionIsNotSupported() { - var date = new CypherDateTimeWithOffset(1947, 12, 16, 12, 15, 59, 660000999, 3600); + var date = new ZonedDateTime(1947, 12, 16, 12, 15, 59, 660000999, Zone.Of(3600)); var conversions = new Action[] { () => Convert.ToBoolean(date), diff --git a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherDateTimeWithZoneIdTests.cs b/Neo4j.Driver/Neo4j.Driver.Tests/Types/ZonedDateTimeWithZoneIdTests.cs similarity index 67% rename from Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherDateTimeWithZoneIdTests.cs rename to Neo4j.Driver/Neo4j.Driver.Tests/Types/ZonedDateTimeWithZoneIdTests.cs index 28242f802..f53fa8fac 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests/Types/CypherDateTimeWithZoneIdTests.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests/Types/ZonedDateTimeWithZoneIdTests.cs @@ -24,38 +24,38 @@ namespace Neo4j.Driver.Tests.Types { - public class CypherDateTimeWithZoneIdTests + public class ZonedDateTimeWithZoneIdTests { [Fact] public void ShouldCreateDateTimeWithZoneIdWithDateTimeComponents() { - var cypherDateTime = new CypherDateTimeWithZoneId(1947, 12, 17, 23, 49, 54, "Europe/Rome"); + var cypherDateTime = new ZonedDateTime(1947, 12, 17, 23, 49, 54, Zone.Of("Europe/Rome")); cypherDateTime.DateTime.Should().Be(new DateTime(1947, 12, 17, 23, 49, 54)); cypherDateTime.Offset.Should().Be(TimeSpan.FromHours(1)); - cypherDateTime.ZoneId.Should().Be("Europe/Rome"); + cypherDateTime.Zone.Should().Be(Zone.Of("Europe/Rome")); } [Fact] public void ShouldCreateDateTimeWithZoneIdWithDateTimeComponentsWithNanoseconds() { - var cypherDateTime = new CypherDateTimeWithZoneId(1947, 12, 17, 23, 49, 54, 192794500, "Europe/Rome"); + var cypherDateTime = new ZonedDateTime(1947, 12, 17, 23, 49, 54, 192794500, Zone.Of("Europe/Rome")); cypherDateTime.DateTime.Should().Be(new DateTime(1947, 12, 17, 23, 49, 54).AddTicks(1927945)); cypherDateTime.Offset.Should().Be(TimeSpan.FromHours(1)); - cypherDateTime.ZoneId.Should().Be("Europe/Rome"); + cypherDateTime.Zone.Should().Be(Zone.Of("Europe/Rome")); } [Fact] public void ShouldCreateDateTimeWithZoneIdWithDateTime() { var dateTime = new DateTime(1947, 12, 17, 23, 49, 54, 120); - var cypherDateTime = new CypherDateTimeWithZoneId(dateTime, "Europe/Rome"); + var cypherDateTime = new ZonedDateTime(dateTime, "Europe/Rome"); cypherDateTime.DateTime.Should().Be(dateTime); cypherDateTime.Offset.Should().Be(TimeSpan.FromHours(1)); - cypherDateTime.ZoneId.Should().Be("Europe/Rome"); + cypherDateTime.Zone.Should().Be(Zone.Of("Europe/Rome")); } [Theory] @@ -63,7 +63,7 @@ public void ShouldCreateDateTimeWithZoneIdWithDateTime() [InlineData(1000000000)] public void ShouldThrowOnInvalidYear(int year) { - var ex = Record.Exception(() => new CypherDateTimeWithZoneId(year, 1, 1, 0, 0, 0, "Europe/Amsterdam")); + var ex = Record.Exception(() => new ZonedDateTime(year, 1, 1, 0, 0, 0, Zone.Of("Europe/Amsterdam"))); ex.Should().NotBeNull().And.BeOfType(); } @@ -73,7 +73,7 @@ public void ShouldThrowOnInvalidYear(int year) [InlineData(13)] public void ShouldThrowOnInvalidMonth(int month) { - var ex = Record.Exception(() => new CypherDateTimeWithZoneId(1990, month, 1, 0, 0, 0, "Europe/Istanbul")); + var ex = Record.Exception(() => new ZonedDateTime(1990, month, 1, 0, 0, 0, Zone.Of("Europe/Istanbul"))); ex.Should().NotBeNull().And.BeOfType(); } @@ -86,7 +86,7 @@ public void ShouldThrowOnInvalidMonth(int month) [InlineData(2018, 12, -1)] public void ShouldThrowOnInvalidDay(int year, int month, int day) { - var ex = Record.Exception(() => new CypherDateTimeWithZoneId(year, month, day, 0, 0, 0, "Europe/Istanbul")); + var ex = Record.Exception(() => new ZonedDateTime(year, month, day, 0, 0, 0, Zone.Of("Europe/Istanbul"))); ex.Should().NotBeNull().And.BeOfType(); } @@ -96,7 +96,7 @@ public void ShouldThrowOnInvalidDay(int year, int month, int day) [InlineData(24)] public void ShouldThrowOnInvalidHour(int hour) { - var ex = Record.Exception(() => new CypherDateTimeWithZoneId(1990, 1, 1, hour, 0, 0, "Europe/Istanbul")); + var ex = Record.Exception(() => new ZonedDateTime(1990, 1, 1, hour, 0, 0, Zone.Of("Europe/Istanbul"))); ex.Should().NotBeNull().And.BeOfType(); } @@ -107,7 +107,7 @@ public void ShouldThrowOnInvalidHour(int hour) [InlineData(61)] public void ShouldThrowOnInvalidMinute(int minute) { - var ex = Record.Exception(() => new CypherDateTimeWithZoneId(1990, 1, 1, 0, minute, 0, "Europe/Paris")); + var ex = Record.Exception(() => new ZonedDateTime(1990, 1, 1, 0, minute, 0, Zone.Of("Europe/Paris"))); ex.Should().NotBeNull().And.BeOfType(); } @@ -118,7 +118,7 @@ public void ShouldThrowOnInvalidMinute(int minute) [InlineData(61)] public void ShouldThrowOnInvalidSecond(int second) { - var ex = Record.Exception(() => new CypherDateTimeWithZoneId(1990, 1, 1, 0, 0, second, "Europe/Rome")); + var ex = Record.Exception(() => new ZonedDateTime(1990, 1, 1, 0, 0, second, Zone.Of("Europe/Rome"))); ex.Should().NotBeNull().And.BeOfType(); } @@ -128,7 +128,7 @@ public void ShouldThrowOnInvalidSecond(int second) [InlineData(999_999_999 + 1)] public void ShouldThrowOnInvalidNanosecond(int nanosecond) { - var ex = Record.Exception(() => new CypherDateTimeWithZoneId(1990, 1, 1, 0, 0, 0, nanosecond, "Europe/Athens")); + var ex = Record.Exception(() => new ZonedDateTime(1990, 1, 1, 0, 0, 0, nanosecond, Zone.Of("Europe/Athens"))); ex.Should().NotBeNull().And.BeOfType(); } @@ -141,7 +141,7 @@ public void ShouldThrowOnInvalidNanosecond(int nanosecond) [InlineData(9999999)] public void ShouldThrowOnOverflow(int year) { - var dateTime = new CypherDateTimeWithZoneId(year, 1, 1, 0, 0, 0, 0, "Europe/London"); + var dateTime = new ZonedDateTime(year, 1, 1, 0, 0, 0, 0, Zone.Of("Europe/London")); var ex = Record.Exception(() => dateTime.DateTime); ex.Should().NotBeNull().And.BeOfType(); @@ -156,7 +156,7 @@ public void ShouldThrowOnOverflow(int year) [InlineData(999000001)] public void ShouldThrowOnTruncation(int nanosecond) { - var dateTime = new CypherDateTimeWithZoneId(1, 1, 1, 0, 0, 0, nanosecond, "Europe/London"); + var dateTime = new ZonedDateTime(1, 1, 1, 0, 0, 0, nanosecond, Zone.Of("Europe/London")); var ex = Record.Exception(() => dateTime.DateTime); ex.Should().NotBeNull().And.BeOfType(); @@ -172,7 +172,7 @@ public void ShouldThrowOnTruncation(int nanosecond) [InlineData(-999999, 1, 1, 5, 1, 25, 1, "Asia/Seoul", "-999999-01-01T05:01:25.000000001[Asia/Seoul]")] public void ShouldGenerateCorrectString(int year, int month, int day, int hour, int minute, int second, int nanosecond, string zoneId, string expected) { - var cypherDateTime = new CypherDateTimeWithZoneId(year, month, day, hour, minute, second, nanosecond, zoneId); + var cypherDateTime = new ZonedDateTime(year, month, day, hour, minute, second, nanosecond, Zone.Of(zoneId)); var cypherDateTimeStr = cypherDateTime.ToString(); cypherDateTimeStr.Should().Be(expected); @@ -181,8 +181,8 @@ public void ShouldGenerateCorrectString(int year, int month, int day, int hour, [Fact] public void ShouldGenerateSameHashcode() { - var dateTime1 = new CypherDateTimeWithZoneId(1947, 12, 17, 15, 12, 01, 789000000, "Europe/Rome"); - var dateTime2 = new CypherDateTimeWithZoneId(new DateTime(1947, 12, 17, 15, 12, 01, 789), "Europe/Rome"); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 15, 12, 01, 789000000, Zone.Of("Europe/Rome")); + var dateTime2 = new ZonedDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 789), "Europe/Rome"); dateTime1.GetHashCode().Should().Be(dateTime2.GetHashCode()); } @@ -190,8 +190,8 @@ public void ShouldGenerateSameHashcode() [Fact] public void ShouldGenerateDifferentHashcode() { - var dateTime1 = new CypherDateTimeWithZoneId(1947, 12, 17, 15, 12, 01, 789000000, "Europe/Rome"); - var dateTime2 = new CypherDateTimeWithZoneId(new DateTime(1947, 12, 17, 15, 12, 01, 790), "Europe/Rome"); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 15, 12, 01, 789000000, Zone.Of("Europe/Rome")); + var dateTime2 = new ZonedDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 790), "Europe/Rome"); dateTime1.GetHashCode().Should().NotBe(dateTime2.GetHashCode()); } @@ -199,8 +199,8 @@ public void ShouldGenerateDifferentHashcode() [Fact] public void ShouldBeEqual() { - var dateTime1 = new CypherDateTimeWithZoneId(1947, 12, 17, 15, 12, 01, 789000000, "Europe/Rome"); - var dateTime2 = new CypherDateTimeWithZoneId(new DateTime(1947, 12, 17, 15, 12, 01, 789), "Europe/Rome"); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 15, 12, 01, 789000000, Zone.Of("Europe/Rome")); + var dateTime2 = new ZonedDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 789), "Europe/Rome"); dateTime1.Should().Be(dateTime2); } @@ -208,8 +208,8 @@ public void ShouldBeEqual() [Fact] public void ShouldNotBeEqual() { - var dateTime1 = new CypherDateTimeWithZoneId(1947, 12, 17, 15, 12, 01, 789000000, "Europe/Rome"); - var dateTime2 = new CypherDateTimeWithZoneId(new DateTime(1947, 12, 17, 15, 12, 01, 790), "Europe/Rome"); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 15, 12, 01, 789000000, Zone.Of("Europe/Rome")); + var dateTime2 = new ZonedDateTime(new DateTime(1947, 12, 17, 15, 12, 01, 790), "Europe/Rome"); dateTime1.Should().NotBe(dateTime2); } @@ -217,7 +217,7 @@ public void ShouldNotBeEqual() [Fact] public void ShouldNotBeEqualToAnotherType() { - var dateTime = new CypherDateTimeWithZoneId(1947, 12, 17, 15, 12, 01, 789000000, "Europe/Rome"); + var dateTime = new ZonedDateTime(1947, 12, 17, 15, 12, 01, 789000000, Zone.Of("Europe/Rome")); var other = "some string"; dateTime.Equals(other).Should().BeFalse(); @@ -226,7 +226,7 @@ public void ShouldNotBeEqualToAnotherType() [Fact] public void ShouldNotBeEqualToNull() { - var dateTime = new CypherDateTimeWithZoneId(1947, 12, 17, 15, 12, 01, 789000000, "Europe/Rome"); + var dateTime = new ZonedDateTime(1947, 12, 17, 15, 12, 01, 789000000, Zone.Of("Europe/Rome")); var other = (object)null; dateTime.Equals(other).Should().BeFalse(); @@ -235,7 +235,7 @@ public void ShouldNotBeEqualToNull() [Fact] public void ShouldThrowOnCompareToOtherType() { - var dateTime1 = new CypherDateTimeWithZoneId(1947, 12, 17, 0, 0, 0, 0, "Europe/Amsterdam"); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 0, 0, 0, 0, Zone.Of("Europe/Amsterdam")); var ex = Record.Exception(() => dateTime1.CompareTo(new DateTime(1947, 12, 17))); @@ -245,7 +245,7 @@ public void ShouldThrowOnCompareToOtherType() [Fact] public void ShouldReportLargerOnCompareToNull() { - var dateTime1 = new CypherDateTimeWithZoneId(1947, 12, 17, 0, 0, 0, 0, "Europe/Amsterdam"); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 0, 0, 0, 0, Zone.Of("Europe/Amsterdam")); var comp = dateTime1.CompareTo(null); @@ -255,8 +255,8 @@ public void ShouldReportLargerOnCompareToNull() [Fact] public void ShouldReportLargerOnCompareTo() { - var dateTime1 = new CypherDateTimeWithZoneId(1947, 12, 17, 0, 0, 0, 0, "Europe/Amsterdam"); - var dateTime2 = new CypherDateTimeWithZoneId(1947, 12, 16, 23, 59, 59, 999999900, "Europe/Amsterdam"); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 0, 0, 0, 0, Zone.Of("Europe/Amsterdam")); + var dateTime2 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999900, Zone.Of("Europe/Amsterdam")); var comp = dateTime1.CompareTo(dateTime2); @@ -266,8 +266,8 @@ public void ShouldReportLargerOnCompareTo() [Fact] public void ShouldReportLargerOnCompareToDiffOffset() { - var dateTime1 = new CypherDateTimeWithZoneId(1947, 12, 17, 23, 59, 59, 999999900, "Europe/Amsterdam"); - var dateTime2 = new CypherDateTimeWithZoneId(1947, 12, 16, 23, 59, 59, 999999900, "Europe/London"); + var dateTime1 = new ZonedDateTime(1947, 12, 17, 23, 59, 59, 999999900, Zone.Of("Europe/Amsterdam")); + var dateTime2 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999900, Zone.Of("Europe/London")); var comp = dateTime1.CompareTo(dateTime2); @@ -277,8 +277,8 @@ public void ShouldReportLargerOnCompareToDiffOffset() [Fact] public void ShouldReportEqualOnCompareTo() { - var dateTime1 = new CypherDateTimeWithZoneId(1947, 12, 16, 23, 59, 59, 999999900, "Europe/Amsterdam"); - var dateTime2 = new CypherDateTimeWithZoneId(1947, 12, 16, 23, 59, 59, 999999900, "Europe/Amsterdam"); + var dateTime1 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999900, Zone.Of("Europe/Amsterdam")); + var dateTime2 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999900, Zone.Of("Europe/Amsterdam")); var comp = dateTime1.CompareTo(dateTime2); @@ -288,8 +288,8 @@ public void ShouldReportEqualOnCompareTo() [Fact] public void ShouldReportEqualOnCompareToDiffOffset() { - var dateTime1 = new CypherDateTimeWithZoneId(1947, 12, 16, 23, 59, 59, 999999900, "Europe/London"); - var dateTime2 = new CypherDateTimeWithZoneId(1947, 12, 17, 0, 59, 59, 999999900, "Europe/Amsterdam"); + var dateTime1 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999900, Zone.Of("Europe/London")); + var dateTime2 = new ZonedDateTime(1947, 12, 17, 0, 59, 59, 999999900, Zone.Of("Europe/Amsterdam")); var comp = dateTime1.CompareTo(dateTime2); @@ -299,8 +299,8 @@ public void ShouldReportEqualOnCompareToDiffOffset() [Fact] public void ShouldReportSmallerOnCompareTo() { - var dateTime1 = new CypherDateTimeWithZoneId(1947, 12, 16, 23, 59, 59, 999999900, "Europe/Amsterdam"); - var dateTime2 = new CypherDateTimeWithZoneId(1947, 12, 17, 0, 59, 59, 999999900, "Europe/Amsterdam"); + var dateTime1 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999900, Zone.Of("Europe/Amsterdam")); + var dateTime2 = new ZonedDateTime(1947, 12, 17, 0, 59, 59, 999999900, Zone.Of("Europe/Amsterdam")); var comp = dateTime1.CompareTo(dateTime2); @@ -310,8 +310,8 @@ public void ShouldReportSmallerOnCompareTo() [Fact] public void ShouldReportSmallerOnCompareToDiffOffset() { - var dateTime1 = new CypherDateTimeWithZoneId(1947, 12, 16, 23, 59, 59, 999999900, "Europe/Amsterdam"); - var dateTime2 = new CypherDateTimeWithZoneId(1947, 12, 16, 23, 59, 59, 999999900, "Europe/London"); + var dateTime1 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999900, Zone.Of("Europe/Amsterdam")); + var dateTime2 = new ZonedDateTime(1947, 12, 16, 23, 59, 59, 999999900, Zone.Of("Europe/London")); var comp = dateTime1.CompareTo(dateTime2); @@ -322,7 +322,7 @@ public void ShouldReportSmallerOnCompareToDiffOffset() public void ShouldBeConvertableToDateTime() { var date = new DateTime(1947, 12, 16, 12, 15, 59, 660); - var date1 = new CypherDateTimeWithZoneId(date, "Europe/Rome"); + var date1 = new ZonedDateTime(date, "Europe/Rome"); var date2 = Convert.ToDateTime(date1); var date3 = Convert.ChangeType(date1, typeof(DateTime)); @@ -334,7 +334,7 @@ public void ShouldBeConvertableToDateTime() public void ShouldBeConvertableToDateTimeOffset() { var date = new DateTime(1947, 12, 16, 12, 15, 59, 660); - var date1 = new CypherDateTimeWithZoneId(date, "Europe/Rome"); + var date1 = new ZonedDateTime(date, "Europe/Rome"); var date2 = Convert.ChangeType(date1, typeof(DateTimeOffset)); date2.Should().Be(new DateTimeOffset(date, TimeSpan.FromSeconds(3600))); @@ -343,7 +343,7 @@ public void ShouldBeConvertableToDateTimeOffset() [Fact] public void ShouldBeConvertableToString() { - var date = new CypherDateTimeWithOffset(1947, 12, 16, 12, 15, 59, 660000999, 3600); + var date = new ZonedDateTime(1947, 12, 16, 12, 15, 59, 660000999, Zone.Of(3600)); var dateStr1 = Convert.ToString(date); var dateStr2 = Convert.ChangeType(date, typeof(string)); @@ -354,7 +354,7 @@ public void ShouldBeConvertableToString() [Fact] public void ShouldThrowWhenConversionIsNotSupported() { - var date = new CypherDateTimeWithZoneId(1947, 12, 16, 12, 15, 59, 660000999, ""); + var date = new ZonedDateTime(1947, 12, 16, 12, 15, 59, 660000999, Zone.Of("America/Dominica")); var conversions = new Action[] { () => Convert.ToBoolean(date), diff --git a/Neo4j.Driver/Neo4j.Driver/Internal/Helpers/TemporalHelpers.cs b/Neo4j.Driver/Neo4j.Driver/Internal/Helpers/TemporalHelpers.cs index dc388a91c..76b9ff931 100644 --- a/Neo4j.Driver/Neo4j.Driver/Internal/Helpers/TemporalHelpers.cs +++ b/Neo4j.Driver/Neo4j.Driver/Internal/Helpers/TemporalHelpers.cs @@ -83,28 +83,28 @@ public static long ToEpochDays(this IHasDateComponents date) return ComputeEpochDays(date.Year, date.Month, date.Day); } - public static long ToNanos(this CypherDuration duration) + public static long ToNanos(this Duration duration) { return (duration.Months * 30 * TemporalHelpers.NanosPerDay) + (duration.Days * TemporalHelpers.NanosPerDay) + (duration.Seconds * TemporalHelpers.NanosPerSecond) + duration.Nanos; } - public static CypherTime NanoOfDayToTime(long nanoOfDay) + public static LocalTime NanoOfDayToTime(long nanoOfDay) { ComponentsOfNanoOfDay(nanoOfDay, out var hour, out var minute, out var second, out var nanosecond); - return new CypherTime(hour, minute, second, nanosecond); + return new LocalTime(hour, minute, second, nanosecond); } - public static CypherDate EpochDaysToDate(long epochDays) + public static LocalDate EpochDaysToDate(long epochDays) { ComponentsOfEpochDays(epochDays, out var year, out var month, out var day); - return new CypherDate(year, month, day); + return new LocalDate(year, month, day); } - public static CypherDateTime EpochSecondsAndNanoToDateTime(long epochSeconds, int nano) + public static LocalDateTime EpochSecondsAndNanoToDateTime(long epochSeconds, int nano) { var epochDay = FloorDiv(epochSeconds, SecondsPerDay); var secondsOfDay = FloorMod(epochSeconds, SecondsPerDay); @@ -113,7 +113,7 @@ public static CypherDateTime EpochSecondsAndNanoToDateTime(long epochSeconds, in ComponentsOfEpochDays(epochDay, out var year, out var month, out var day); ComponentsOfNanoOfDay(nanoOfDay, out var hour, out var minute, out var second, out var nanosecond); - return new CypherDateTime(year, month, day, hour, minute, second, nanosecond); + return new LocalDateTime(year, month, day, hour, minute, second, nanosecond); } private static long ComputeEpochDays(int year, int month, int day) @@ -225,7 +225,7 @@ public static void AssertNoTruncation(IHasTimeComponents time, string target) if (time.Nanosecond % NanosecondsPerTick > 0) { throw new ValueTruncationException( - $"Conversion of this instance into {target} will cause a truncation of ${time.Nanosecond % TemporalHelpers.NanosecondsPerTick}ns."); + $"Conversion of this instance into {target} will cause a truncation of {time.Nanosecond % TemporalHelpers.NanosecondsPerTick}ns."); } } @@ -244,6 +244,11 @@ public static string ToIsoTimeString(int hour, int minute, int second, int nanos return $"{hour:D2}:{minute:D2}:{second:D2}.{nanosecond:D9}"; } + public static string ToIsoTimeZoneId(string id) + { + return $"[{id}]"; + } + public static string ToIsoTimeZoneOffset(int offsetSeconds) { if (offsetSeconds == 0) diff --git a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/PointHandler.cs b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/PointHandler.cs index 08259fd3d..f96208557 100644 --- a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/PointHandler.cs +++ b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/PointHandler.cs @@ -33,7 +33,7 @@ internal class PointHandler : IPackStreamStructHandler public IEnumerable ReadableStructs => new[] {Point2DStructType, Point3DStructType}; - public IEnumerable WritableTypes => new[] {typeof(CypherPoint)}; + public IEnumerable WritableTypes => new[] {typeof(Point)}; public object Read(IPackStreamReader reader, byte signature, long size) { @@ -46,7 +46,7 @@ public object Read(IPackStreamReader reader, byte signature, long size) var x = reader.ReadDouble(); var y = reader.ReadDouble(); - return new CypherPoint(srId, x, y); + return new Point(srId, x, y); } case Point3DStructType: { @@ -56,7 +56,7 @@ public object Read(IPackStreamReader reader, byte signature, long size) var y = reader.ReadDouble(); var z = reader.ReadDouble(); - return new CypherPoint(srId, x, y, z); + return new Point(srId, x, y, z); } default: throw new ProtocolException( @@ -66,11 +66,11 @@ public object Read(IPackStreamReader reader, byte signature, long size) public void Write(IPackStreamWriter writer, object value) { - var point = value.CastOrThrow(); + var point = value.CastOrThrow(); switch (point.Dimension) { - case CypherPoint.TwoD: + case Point.TwoD: { writer.WriteStructHeader(Point2DStructSize, Point2DStructType); writer.Write(point.SrId); @@ -79,7 +79,7 @@ public void Write(IPackStreamWriter writer, object value) break; } - case CypherPoint.ThreeD: + case Point.ThreeD: { writer.WriteStructHeader(Point3DStructSize, Point3DStructType); writer.Write(point.SrId); diff --git a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DateTimeWithOffsetHandler.cs b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DateTimeWithOffsetHandler.cs deleted file mode 100644 index 9df52fb87..000000000 --- a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DateTimeWithOffsetHandler.cs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2002-2018 "Neo Technology," -// Network Engine for Objects in Lund AB [http://neotechnology.com] -// -// This file is part of Neo4j. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System; -using System.Collections.Generic; -using Neo4j.Driver.V1; - -namespace Neo4j.Driver.Internal.IO.StructHandlers -{ - internal class DateTimeWithOffsetHandler : IPackStreamStructHandler - { - public const byte StructType = (byte) 'F'; - public const int StructSize = 3; - - public IEnumerable ReadableStructs => new[] {StructType}; - - public IEnumerable WritableTypes => new[] {typeof(CypherDateTimeWithOffset)}; - - public object Read(IPackStreamReader reader, byte signature, long size) - { - PackStream.EnsureStructSize("DateTimeWithOffset", StructSize, size); - - var epochSecondsUtc = reader.ReadLong(); - var nanosOfSecond = reader.ReadInteger(); - var offsetSeconds = reader.ReadInteger(); - - return new CypherDateTimeWithOffset( - TemporalHelpers.EpochSecondsAndNanoToDateTime(epochSecondsUtc, nanosOfSecond), offsetSeconds); - } - - public void Write(IPackStreamWriter writer, object value) - { - var dateTime = value.CastOrThrow(); - - writer.WriteStructHeader(StructSize, StructType); - writer.Write(dateTime.ToEpochSeconds()); - writer.Write(dateTime.Nanosecond); - writer.Write(dateTime.OffsetSeconds); - } - } -} \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DateTimeWithZoneIdHandler.cs b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DateTimeWithZoneIdHandler.cs deleted file mode 100644 index 62380e6d7..000000000 --- a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DateTimeWithZoneIdHandler.cs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2002-2018 "Neo Technology," -// Network Engine for Objects in Lund AB [http://neotechnology.com] -// -// This file is part of Neo4j. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System; -using System.Collections.Generic; -using Neo4j.Driver.V1; - -namespace Neo4j.Driver.Internal.IO.StructHandlers -{ - internal class DateTimeWithZoneIdHandler : IPackStreamStructHandler - { - public const byte StructType = (byte) 'f'; - public const int StructSize = 3; - - public IEnumerable ReadableStructs => new[] {StructType}; - - public IEnumerable WritableTypes => new[] {typeof(CypherDateTimeWithZoneId)}; - - public object Read(IPackStreamReader reader, byte signature, long size) - { - PackStream.EnsureStructSize("DateTimeWithZoneId", StructSize, size); - - var epochSecondsUtc = reader.ReadLong(); - var nanosOfSecond = reader.ReadInteger(); - var zoneId = reader.ReadString(); - - return new CypherDateTimeWithZoneId( - TemporalHelpers.EpochSecondsAndNanoToDateTime(epochSecondsUtc, nanosOfSecond), zoneId); - } - - public void Write(IPackStreamWriter writer, object value) - { - var dateTime = value.CastOrThrow(); - - writer.WriteStructHeader(StructSize, StructType); - writer.Write(dateTime.ToEpochSeconds()); - writer.Write(dateTime.Nanosecond); - writer.Write(dateTime.ZoneId); - } - } -} \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DurationHandler.cs b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DurationHandler.cs index 10288c19b..2fd6415d9 100644 --- a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DurationHandler.cs +++ b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DurationHandler.cs @@ -28,7 +28,7 @@ internal class DurationHandler: IPackStreamStructHandler public IEnumerable ReadableStructs => new[] {StructType}; - public IEnumerable WritableTypes => new[] {typeof(CypherDuration)}; + public IEnumerable WritableTypes => new[] {typeof(Duration)}; public object Read(IPackStreamReader reader, byte signature, long size) { @@ -39,12 +39,12 @@ public object Read(IPackStreamReader reader, byte signature, long size) var seconds = reader.ReadLong(); var nanos = reader.ReadInteger(); - return new CypherDuration(months, days, seconds, nanos); + return new Duration(months, days, seconds, nanos); } public void Write(IPackStreamWriter writer, object value) { - var duration = value.CastOrThrow(); + var duration = value.CastOrThrow(); writer.WriteStructHeader(StructSize, StructType); writer.Write(duration.Months); diff --git a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DateHandler.cs b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/LocalDateHandler.cs similarity index 92% rename from Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DateHandler.cs rename to Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/LocalDateHandler.cs index 17525a425..7b7e00dde 100644 --- a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DateHandler.cs +++ b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/LocalDateHandler.cs @@ -21,14 +21,14 @@ namespace Neo4j.Driver.Internal.IO.StructHandlers { - internal class DateHandler : IPackStreamStructHandler + internal class LocalDateHandler : IPackStreamStructHandler { public const byte StructType = (byte) 'D'; public const int StructSize = 1; public IEnumerable ReadableStructs => new[] {StructType}; - public IEnumerable WritableTypes => new[] {typeof(CypherDate)}; + public IEnumerable WritableTypes => new[] {typeof(LocalDate)}; public object Read(IPackStreamReader reader, byte signature, long size) { @@ -41,7 +41,7 @@ public object Read(IPackStreamReader reader, byte signature, long size) public void Write(IPackStreamWriter writer, object value) { - var date = value.CastOrThrow(); + var date = value.CastOrThrow(); writer.WriteStructHeader(StructSize, StructType); writer.Write(date.ToEpochDays()); diff --git a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DateTimeHandler.cs b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/LocalDateTimeHandler.cs similarity index 92% rename from Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DateTimeHandler.cs rename to Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/LocalDateTimeHandler.cs index befd8c882..c50245323 100644 --- a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/DateTimeHandler.cs +++ b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/LocalDateTimeHandler.cs @@ -21,14 +21,14 @@ namespace Neo4j.Driver.Internal.IO.StructHandlers { - internal class DateTimeHandler: IPackStreamStructHandler + internal class LocalDateTimeHandler: IPackStreamStructHandler { public const byte StructType = (byte) 'd'; public const int StructSize = 2; public IEnumerable ReadableStructs => new[] {StructType}; - public IEnumerable WritableTypes => new[] {typeof(CypherDateTime)}; + public IEnumerable WritableTypes => new[] {typeof(LocalDateTime)}; public object Read(IPackStreamReader reader, byte signature, long size) { @@ -42,7 +42,7 @@ public object Read(IPackStreamReader reader, byte signature, long size) public void Write(IPackStreamWriter writer, object value) { - var dateTime = value.CastOrThrow(); + var dateTime = value.CastOrThrow(); writer.WriteStructHeader(StructSize, StructType); writer.Write(dateTime.ToEpochSeconds()); diff --git a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/TimeHandler.cs b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/LocalTimeHandler.cs similarity index 92% rename from Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/TimeHandler.cs rename to Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/LocalTimeHandler.cs index e2d4de248..3d010b97d 100644 --- a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/TimeHandler.cs +++ b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/LocalTimeHandler.cs @@ -21,14 +21,14 @@ namespace Neo4j.Driver.Internal.IO.StructHandlers { - internal class TimeHandler : IPackStreamStructHandler + internal class LocalTimeHandler : IPackStreamStructHandler { public const byte StructType = (byte) 't'; public const int StructSize = 1; public IEnumerable ReadableStructs => new[] {StructType}; - public IEnumerable WritableTypes => new[] {typeof(CypherTime)}; + public IEnumerable WritableTypes => new[] {typeof(LocalTime)}; public object Read(IPackStreamReader reader, byte signature, long size) { @@ -41,7 +41,7 @@ public object Read(IPackStreamReader reader, byte signature, long size) public void Write(IPackStreamWriter writer, object value) { - var time = value.CastOrThrow(); + var time = value.CastOrThrow(); writer.WriteStructHeader(StructSize, StructType); writer.Write(time.ToNanoOfDay()); diff --git a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/TimeWithOffsetHandler.cs b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/OffsetTimeHandler.cs similarity index 85% rename from Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/TimeWithOffsetHandler.cs rename to Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/OffsetTimeHandler.cs index 977ff6c58..f9bc79ace 100644 --- a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/TimeWithOffsetHandler.cs +++ b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/OffsetTimeHandler.cs @@ -21,14 +21,14 @@ namespace Neo4j.Driver.Internal.IO.StructHandlers { - internal class TimeWithOffsetHandler : IPackStreamStructHandler + internal class OffsetTimeHandler : IPackStreamStructHandler { public const byte StructType = (byte) 'T'; public const int StructSize = 2; public IEnumerable ReadableStructs => new[] {StructType}; - public IEnumerable WritableTypes => new[] {typeof(CypherTimeWithOffset)}; + public IEnumerable WritableTypes => new[] {typeof(OffsetTime)}; public object Read(IPackStreamReader reader, byte signature, long size) { @@ -37,12 +37,12 @@ public object Read(IPackStreamReader reader, byte signature, long size) var nanosOfDay = reader.ReadLong(); var offsetSeconds = reader.ReadInteger(); - return new CypherTimeWithOffset(TemporalHelpers.NanoOfDayToTime(nanosOfDay), offsetSeconds); + return new OffsetTime(TemporalHelpers.NanoOfDayToTime(nanosOfDay), offsetSeconds); } public void Write(IPackStreamWriter writer, object value) { - var time = value.CastOrThrow(); + var time = value.CastOrThrow(); writer.WriteStructHeader(StructSize, StructType); writer.Write(time.ToNanoOfDay()); diff --git a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/SystemDateTimeHandler.cs b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/SystemDateTimeHandler.cs index bccf2516a..be2fb072f 100644 --- a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/SystemDateTimeHandler.cs +++ b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/SystemDateTimeHandler.cs @@ -33,10 +33,10 @@ public override void Write(IPackStreamWriter writer, object value) { case DateTimeKind.Local: case DateTimeKind.Unspecified: - writer.Write(new CypherDateTime(dateTime)); + writer.Write(new LocalDateTime(dateTime)); break; case DateTimeKind.Utc: - writer.Write(new CypherDateTimeWithOffset(dateTime, 0)); + writer.Write(new ZonedDateTime(dateTime, 0)); break; default: throw new ProtocolException( diff --git a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/SystemDateTimeOffsetHandler.cs b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/SystemDateTimeOffsetHandler.cs index 18a6ccd46..1f257716c 100644 --- a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/SystemDateTimeOffsetHandler.cs +++ b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/SystemDateTimeOffsetHandler.cs @@ -29,7 +29,7 @@ public override void Write(IPackStreamWriter writer, object value) { var dateTime = value.CastOrThrow(); - writer.Write(new CypherDateTimeWithOffset(dateTime)); + writer.Write(new ZonedDateTime(dateTime)); } } } \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/SystemTimeSpanHandler.cs b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/SystemTimeSpanHandler.cs index 6fe4abacf..5fc632392 100644 --- a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/SystemTimeSpanHandler.cs +++ b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/SystemTimeSpanHandler.cs @@ -35,7 +35,7 @@ public override void Write(IPackStreamWriter writer, object value) $"TimeSpan instance ({time}) passed to {nameof(SystemDateTimeHandler)} is not a valid time of day!"); } - writer.Write(new CypherTime(time)); + writer.Write(new LocalTime(time)); } } } \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/ZonedDateTimeHandler.cs b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/ZonedDateTimeHandler.cs new file mode 100644 index 000000000..ba005603b --- /dev/null +++ b/Neo4j.Driver/Neo4j.Driver/Internal/IO/StructHandlers/Temporal/ZonedDateTimeHandler.cs @@ -0,0 +1,81 @@ +// Copyright (c) 2002-2018 "Neo Technology," +// Network Engine for Objects in Lund AB [http://neotechnology.com] +// +// This file is part of Neo4j. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using System.Collections.Generic; +using Neo4j.Driver.V1; + +namespace Neo4j.Driver.Internal.IO.StructHandlers +{ + internal class ZonedDateTimeHandler : IPackStreamStructHandler + { + public const byte StructTypeWithOffset = (byte) 'F'; + public const byte StructTypeWithId = (byte)'f'; + public const int StructSize = 3; + + public IEnumerable ReadableStructs => new[] {StructTypeWithId, StructTypeWithOffset}; + + public IEnumerable WritableTypes => new[] {typeof(ZonedDateTime)}; + + public object Read(IPackStreamReader reader, byte signature, long size) + { + PackStream.EnsureStructSize($"ZonedDateTime[{(char)signature}]", StructSize, size); + + var epochSecondsUtc = reader.ReadLong(); + var nanosOfSecond = reader.ReadInteger(); + + switch (signature) + { + case StructTypeWithId: + return new ZonedDateTime( + TemporalHelpers.EpochSecondsAndNanoToDateTime(epochSecondsUtc, nanosOfSecond), + Zone.Of(reader.ReadString())); + case StructTypeWithOffset: + return new ZonedDateTime( + TemporalHelpers.EpochSecondsAndNanoToDateTime(epochSecondsUtc, nanosOfSecond), + Zone.Of(reader.ReadInteger())); + default: + throw new ProtocolException( + $"Unsupported struct signature {signature} passed to {nameof(ZonedDateTimeHandler)}!"); + } + } + + public void Write(IPackStreamWriter writer, object value) + { + var dateTime = value.CastOrThrow(); + + switch (dateTime.Zone) + { + case ZoneId zone: + writer.WriteStructHeader(StructSize, StructTypeWithId); + writer.Write(dateTime.ToEpochSeconds()); + writer.Write(dateTime.Nanosecond); + writer.Write(zone.Id); + break; + case ZoneOffset zone: + writer.WriteStructHeader(StructSize, StructTypeWithOffset); + writer.Write(dateTime.ToEpochSeconds()); + writer.Write(dateTime.Nanosecond); + writer.Write(zone.OffsetSeconds); + break; + default: + throw new ProtocolException( + $"{GetType().Name}: Zone('{dateTime.Zone.GetType().Name}') is not supported."); + } + } + } +} \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver/Internal/Protocol/BoltProtocolV2PackStreamFactory.cs b/Neo4j.Driver/Neo4j.Driver/Internal/Protocol/BoltProtocolV2PackStreamFactory.cs index 2112277df..bff272c26 100644 --- a/Neo4j.Driver/Neo4j.Driver/Internal/Protocol/BoltProtocolV2PackStreamFactory.cs +++ b/Neo4j.Driver/Neo4j.Driver/Internal/Protocol/BoltProtocolV2PackStreamFactory.cs @@ -29,12 +29,11 @@ internal BoltProtocolV2PackStreamFactory() AddHandler(); // Add V2 Temporal Types - AddHandler(); - AddHandler(); - AddHandler(); - AddHandler(); - AddHandler(); - AddHandler(); + AddHandler(); + AddHandler(); + AddHandler(); + AddHandler(); + AddHandler(); AddHandler(); // Add BCL Handlers diff --git a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherDateTimeWithZoneId.cs b/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherDateTimeWithZoneId.cs deleted file mode 100644 index 3680f5365..000000000 --- a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherDateTimeWithZoneId.cs +++ /dev/null @@ -1,418 +0,0 @@ -// Copyright (c) 2002-2018 "Neo Technology," -// Network Engine for Objects in Lund AB [http://neotechnology.com] -// -// This file is part of Neo4j. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System; -using Neo4j.Driver.Internal; -using Neo4j.Driver.Internal.Types; -using TimeZoneConverter; - -namespace Neo4j.Driver.V1 -{ - /// - /// Represents a date time value with a time zone, specified as a zone id - /// - public struct CypherDateTimeWithZoneId : IValue, IEquatable, IComparable, IComparable, IConvertible, IHasDateTimeComponents - { - /// - /// Initializes a new instance of from given value - /// Please note that is ignored with this constructor - /// - /// - /// - public CypherDateTimeWithZoneId(DateTimeOffset dateTimeOffset, string zoneId) - : this(dateTimeOffset.DateTime, zoneId) - { - - } - - /// - /// Initializes a new instance of from given value - /// - /// - /// - public CypherDateTimeWithZoneId(DateTime dateTime, string zoneId) - : this(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, - TemporalHelpers.ExtractNanosecondFromTicks(dateTime.Ticks), zoneId) - { - - } - - /// - /// Initializes a new instance of from individual date time component values - /// - /// - /// - /// - /// - /// - /// - /// - public CypherDateTimeWithZoneId(int year, int month, int day, int hour, int minute, int second, string zoneId) - : this(year, month, day, hour, minute, second, 0, zoneId) - { - - } - - /// - /// Initializes a new instance of from individual date time component values - /// - /// - /// - /// - /// - /// - /// - /// - /// - public CypherDateTimeWithZoneId(int year, int month, int day, int hour, int minute, int second, - int nanosecond, string zoneId) - { - Throw.ArgumentOutOfRangeException.IfValueNotBetween(year, TemporalHelpers.MinYear, TemporalHelpers.MaxYear, nameof(year)); - Throw.ArgumentOutOfRangeException.IfValueNotBetween(month, TemporalHelpers.MinMonth, TemporalHelpers.MaxMonth, nameof(month)); - Throw.ArgumentOutOfRangeException.IfValueNotBetween(day, TemporalHelpers.MinDay, TemporalHelpers.MaxDayOfMonth(year, month), nameof(day)); - Throw.ArgumentOutOfRangeException.IfValueNotBetween(hour, TemporalHelpers.MinHour, TemporalHelpers.MaxHour, nameof(hour)); - Throw.ArgumentOutOfRangeException.IfValueNotBetween(minute, TemporalHelpers.MinMinute, TemporalHelpers.MaxMinute, nameof(minute)); - Throw.ArgumentOutOfRangeException.IfValueNotBetween(second, TemporalHelpers.MinSecond, TemporalHelpers.MaxSecond, nameof(second)); - Throw.ArgumentOutOfRangeException.IfValueNotBetween(nanosecond, TemporalHelpers.MinNanosecond, TemporalHelpers.MaxNanosecond, nameof(nanosecond)); - - Year = year; - Month = month; - Day = day; - Hour = hour; - Minute = minute; - Second = second; - Nanosecond = nanosecond; - ZoneId = zoneId; - } - - internal CypherDateTimeWithZoneId(IHasDateTimeComponents dateTime, string zoneId) - : this(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, - dateTime.Nanosecond, zoneId) - { - - } - - /// - /// Gets the year component of this instance. - /// - public int Year { get; } - - /// - /// Gets the month component of this instance. - /// - public int Month { get; } - - /// - /// Gets the day of month component of this instance. - /// - public int Day { get; } - - /// - /// Gets the hour component of this instance. - /// - public int Hour { get; } - - /// - /// Gets the minute component of this instance. - /// - public int Minute { get; } - - /// - /// Gets the second component of this instance. - /// - public int Second { get; } - - /// - /// Gets the nanosecond component of this instance. - /// - public int Nanosecond { get; } - - /// - /// Zone identifier - /// - public string ZoneId { get; } - - /// - /// Gets a value that represents the date and time of this instance. - /// - /// If the value cannot be represented with DateTime - /// If a truncation occurs during conversion - public DateTime DateTime - { - get - { - TemporalHelpers.AssertNoTruncation(this, nameof(DateTime)); - TemporalHelpers.AssertNoOverflow(this, nameof(DateTime)); - - return new DateTime(Year, Month, Day, Hour, Minute, Second).AddTicks( - TemporalHelpers.ExtractTicksFromNanosecond(Nanosecond)); - } - } - - /// - /// Gets a value that represents the corresponding offset of the time - /// zone at the date and time of this instance. - /// - public TimeSpan Offset => TemporalHelpers.GetTimeZoneInfo(ZoneId).GetUtcOffset(DateTime); - - /// - /// Gets a copy of this date value. - /// - /// Equivalent value - /// If a truncation occurs during conversion - public DateTimeOffset DateTimeOffset => new DateTimeOffset(DateTime, Offset); - - /// - /// Returns a value indicating whether the value of this instance is equal to the - /// value of the specified instance. - /// - /// The object to compare to this instance. - /// true if the value parameter equals the value of - /// this instance; otherwise, false - public bool Equals(CypherDateTimeWithZoneId other) - { - return Year == other.Year && Month == other.Month && Day == other.Day && Hour == other.Hour && - Minute == other.Minute && Second == other.Second && Nanosecond == other.Nanosecond && - string.Equals(ZoneId, other.ZoneId); - } - - /// - /// Returns a value indicating whether this instance is equal to a specified object. - /// - /// The object to compare to this instance. - /// true if value is an instance of and - /// equals the value of this instance; otherwise, false - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is CypherDateTimeWithZoneId && Equals((CypherDateTimeWithZoneId) obj); - } - - /// - /// Returns the hash code for this instance. - /// - /// A 32-bit signed integer hash code. - public override int GetHashCode() - { - unchecked - { - var hashCode = Year; - hashCode = (hashCode * 397) ^ Month; - hashCode = (hashCode * 397) ^ Day; - hashCode = (hashCode * 397) ^ Hour; - hashCode = (hashCode * 397) ^ Minute; - hashCode = (hashCode * 397) ^ Second; - hashCode = (hashCode * 397) ^ Nanosecond; - hashCode = (hashCode * 397) ^ (ZoneId != null ? ZoneId.GetHashCode() : 0); - return hashCode; - } - } - - /// - /// Converts the value of the current object to its equivalent string representation. - /// - /// String representation of this Point. - public override string ToString() - { - return - $"{TemporalHelpers.ToIsoDateString(Year, Month, Day)}T{TemporalHelpers.ToIsoTimeString(Hour, Minute, Second, Nanosecond)}[{ZoneId}]"; - } - - /// - /// Compares the value of this instance to a specified value and returns an integer - /// that indicates whether this instance is earlier than, the same as, or later than the specified - /// DateTime value. - /// - /// The object to compare to the current instance. - /// A signed number indicating the relative values of this instance and the value parameter. - public int CompareTo(CypherDateTimeWithZoneId other) - { - var thisEpochSeconds = this.ToEpochSeconds() - (int)Offset.TotalSeconds; - var otherEpochSeconds = other.ToEpochSeconds() - (int)other.Offset.TotalSeconds; - var epochComparison = thisEpochSeconds.CompareTo(otherEpochSeconds); - if (epochComparison != 0) return epochComparison; - return Nanosecond.CompareTo(other.Nanosecond); - } - - /// - /// Compares the value of this instance to a specified object which is expected to be a - /// value, and returns an integer that indicates whether this instance is earlier than, the same as, - /// or later than the specified value. - /// - /// The object to compare to the current instance. - /// A signed number indicating the relative values of this instance and the value parameter. - public int CompareTo(object obj) - { - if (ReferenceEquals(null, obj)) return 1; - if (!(obj is CypherDateTimeWithZoneId)) throw new ArgumentException($"Object must be of type {nameof(CypherDateTimeWithZoneId)}"); - return CompareTo((CypherDateTimeWithZoneId) obj); - } - - /// - /// Determines whether one specified is earlier than another specified - /// . - /// - /// The first object to compare. - /// The second object to compare. - /// - public static bool operator <(CypherDateTimeWithZoneId left, CypherDateTimeWithZoneId right) - { - return left.CompareTo(right) < 0; - } - - /// - /// Determines whether one specified is later than another specified - /// . - /// - /// The first object to compare. - /// The second object to compare. - /// - public static bool operator >(CypherDateTimeWithZoneId left, CypherDateTimeWithZoneId right) - { - return left.CompareTo(right) > 0; - } - - /// - /// Determines whether one specified represents a duration that is the - /// same as or later than the other specified - /// - /// The first object to compare. - /// The second object to compare. - /// - public static bool operator <=(CypherDateTimeWithZoneId left, CypherDateTimeWithZoneId right) - { - return left.CompareTo(right) <= 0; - } - - /// - /// Determines whether one specified represents a duration that is the - /// same as or earlier than the other specified - /// - /// The first object to compare. - /// The second object to compare. - /// - public static bool operator >=(CypherDateTimeWithZoneId left, CypherDateTimeWithZoneId right) - { - return left.CompareTo(right) >= 0; - } - - - #region IConvertible Implementation - - TypeCode IConvertible.GetTypeCode() - { - return TypeCode.Object; - } - - bool IConvertible.ToBoolean(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to boolean is not supported."); - } - - char IConvertible.ToChar(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to char is not supported."); - } - - sbyte IConvertible.ToSByte(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to sbyte is not supported."); - } - - byte IConvertible.ToByte(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to byte is not supported."); - } - - short IConvertible.ToInt16(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to short is not supported."); - } - - ushort IConvertible.ToUInt16(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned short is not supported."); - } - - int IConvertible.ToInt32(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to int is not supported."); - } - - uint IConvertible.ToUInt32(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned int is not supported."); - } - - long IConvertible.ToInt64(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to long is not supported."); - } - - ulong IConvertible.ToUInt64(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned long is not supported."); - } - - float IConvertible.ToSingle(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to single is not supported."); - } - - double IConvertible.ToDouble(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to double is not supported."); - } - - decimal IConvertible.ToDecimal(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to decimal is not supported."); - } - - DateTime IConvertible.ToDateTime(IFormatProvider provider) - { - return DateTimeOffset.DateTime; - } - - string IConvertible.ToString(IFormatProvider provider) - { - return ToString(); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider provider) - { - if (conversionType == typeof(DateTime)) - { - return DateTimeOffset.DateTime; - } - - if (conversionType == typeof(string)) - { - return ToString(); - } - - if (conversionType == typeof(DateTimeOffset)) - { - return DateTimeOffset; - } - - throw new InvalidCastException($"Conversion of {GetType().Name} to {conversionType.Name} is not supported."); - } - - #endregion - } -} \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherDuration.cs b/Neo4j.Driver/Neo4j.Driver/V1/Types/Duration.cs similarity index 55% rename from Neo4j.Driver/Neo4j.Driver/V1/Types/CypherDuration.cs rename to Neo4j.Driver/Neo4j.Driver/V1/Types/Duration.cs index 62359a181..a693ec6fe 100644 --- a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherDuration.cs +++ b/Neo4j.Driver/Neo4j.Driver/V1/Types/Duration.cs @@ -16,6 +16,7 @@ // limitations under the License. using System; +using System.Collections.Generic; using Neo4j.Driver.Internal; using Neo4j.Driver.Internal.Types; @@ -25,54 +26,58 @@ namespace Neo4j.Driver.V1 /// Represents temporal amount containing months, days, seconds and nanoseconds. /// A duration can hold a negative value. /// - public struct CypherDuration : IValue, IEquatable, IComparable, IComparable, IConvertible + public sealed class Duration : TemporalValue, IEquatable, IComparable, IComparable { + /// + /// Default comparer for values. + /// + public static readonly IComparer Comparer = new TemporalValueComparer(); /// - /// Initializes a new instance of in terms of + /// Initializes a new instance of in terms of /// /// - public CypherDuration(long seconds) + public Duration(long seconds) : this(seconds, 0) { } /// - /// Initializes a new instance of in terms of + /// Initializes a new instance of in terms of /// and /// /// /// - public CypherDuration(long seconds, int nanos) + public Duration(long seconds, int nanos) : this(0, seconds, nanos) { } /// - /// Initializes a new instance of in terms of , + /// Initializes a new instance of in terms of , /// and /// /// /// /// - public CypherDuration(long days, long seconds, int nanos) + public Duration(long days, long seconds, int nanos) : this(0, days, seconds, nanos) { } /// - /// Initializes a new instance of with all supported temporal fields + /// Initializes a new instance of with all supported temporal fields /// /// /// /// /// - public CypherDuration(long months, long days, long seconds, int nanos) + public Duration(long months, long days, long seconds, int nanos) { - Throw.ArgumentOutOfRangeException.IfValueNotBetween(nanos, TemporalHelpers.MinNanosecond, + Throw.ArgumentOutOfRangeException.IfValueNotBetween(nanos, -TemporalHelpers.MaxNanosecond, TemporalHelpers.MaxNanosecond, nameof(nanos)); Months = months; @@ -103,13 +108,15 @@ public CypherDuration(long months, long days, long seconds, int nanos) /// /// Returns a value indicating whether the value of this instance is equal to the - /// value of the specified instance. + /// value of the specified instance. /// /// The object to compare to this instance. /// true if the value parameter equals the value of /// this instance; otherwise, false - public bool Equals(CypherDuration other) + public bool Equals(Duration other) { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; return Months == other.Months && Days == other.Days && Seconds == other.Seconds && Nanos == other.Nanos; } @@ -117,12 +124,13 @@ public bool Equals(CypherDuration other) /// Returns a value indicating whether this instance is equal to a specified object. /// /// The object to compare to this instance. - /// true if value is an instance of and + /// true if value is an instance of and /// equals the value of this instance; otherwise, false public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; - return obj is CypherDuration && Equals((CypherDuration) obj); + if (ReferenceEquals(this, obj)) return true; + return obj is Duration && Equals((Duration) obj); } /// @@ -142,7 +150,7 @@ public override int GetHashCode() } /// - /// Converts the value of the current object to its equivalent string representation. + /// Converts the value of the current object to its equivalent string representation. /// /// String representation of this Point. public override string ToString() @@ -151,173 +159,82 @@ public override string ToString() } /// - /// Compares the value of this instance to a specified value and returns an integer + /// Compares the value of this instance to a specified value and returns an integer /// that indicates whether this instance is earlier than, the same as, or later than the specified /// DateTime value. /// /// The object to compare to the current instance. /// A signed number indicating the relative values of this instance and the value parameter. - public int CompareTo(CypherDuration other) + public int CompareTo(Duration other) { + if (ReferenceEquals(this, other)) return 0; + if (ReferenceEquals(null, other)) return 1; var thisNanos = this.ToNanos(); var otherNanos = other.ToNanos(); return thisNanos.CompareTo(otherNanos); } /// - /// Compares the value of this instance to a specified object which is expected to be a + /// Compares the value of this instance to a specified object which is expected to be a /// value, and returns an integer that indicates whether this instance is earlier than, the same as, - /// or later than the specified value. + /// or later than the specified value. /// /// The object to compare to the current instance. /// A signed number indicating the relative values of this instance and the value parameter. public int CompareTo(object obj) { if (ReferenceEquals(null, obj)) return 1; - if (!(obj is CypherDuration)) throw new ArgumentException($"Object must be of type {nameof(CypherDuration)}"); - return CompareTo((CypherDuration) obj); + if (ReferenceEquals(this, obj)) return 0; + if (!(obj is Duration)) throw new ArgumentException($"Object must be of type {nameof(Duration)}"); + return CompareTo((Duration) obj); } /// - /// Determines whether one specified is less than another specified - /// . + /// Determines whether one specified is less than another specified + /// . /// /// The first object to compare. /// The second object to compare. /// - public static bool operator <(CypherDuration left, CypherDuration right) + public static bool operator <(Duration left, Duration right) { return left.CompareTo(right) < 0; } /// - /// Determines whether one specified is more than another specified - /// . + /// Determines whether one specified is more than another specified + /// . /// /// The first object to compare. /// The second object to compare. /// - public static bool operator >(CypherDuration left, CypherDuration right) + public static bool operator >(Duration left, Duration right) { return left.CompareTo(right) > 0; } /// - /// Determines whether one specified represents a duration that is the - /// same as or more than the other specified + /// Determines whether one specified represents a duration that is the + /// same as or more than the other specified /// /// The first object to compare. /// The second object to compare. /// - public static bool operator <=(CypherDuration left, CypherDuration right) + public static bool operator <=(Duration left, Duration right) { return left.CompareTo(right) <= 0; } /// - /// Determines whether one specified represents a duration that is the - /// same as or less than the other specified + /// Determines whether one specified represents a duration that is the + /// same as or less than the other specified /// /// The first object to compare. /// The second object to compare. /// - public static bool operator >=(CypherDuration left, CypherDuration right) + public static bool operator >=(Duration left, Duration right) { return left.CompareTo(right) >= 0; } - - #region IConvertible Implementation - - TypeCode IConvertible.GetTypeCode() - { - return TypeCode.Object; - } - - bool IConvertible.ToBoolean(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to boolean is not supported."); - } - - char IConvertible.ToChar(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to char is not supported."); - } - - sbyte IConvertible.ToSByte(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to sbyte is not supported."); - } - - byte IConvertible.ToByte(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to byte is not supported."); - } - - short IConvertible.ToInt16(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to short is not supported."); - } - - ushort IConvertible.ToUInt16(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned short is not supported."); - } - - int IConvertible.ToInt32(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to int is not supported."); - } - - uint IConvertible.ToUInt32(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned int is not supported."); - } - - long IConvertible.ToInt64(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to long is not supported."); - } - - ulong IConvertible.ToUInt64(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned long is not supported."); - } - - float IConvertible.ToSingle(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to single is not supported."); - } - - double IConvertible.ToDouble(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to double is not supported."); - } - - decimal IConvertible.ToDecimal(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to decimal is not supported."); - } - - DateTime IConvertible.ToDateTime(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to DateTime is not supported."); - } - - string IConvertible.ToString(IFormatProvider provider) - { - return ToString(); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider provider) - { - if (conversionType == typeof(string)) - { - return ToString(); - } - - throw new InvalidCastException($"Conversion of {GetType().Name} to {conversionType.Name} is not supported."); - } - - #endregion } } \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherDate.cs b/Neo4j.Driver/Neo4j.Driver/V1/Types/LocalDate.cs similarity index 57% rename from Neo4j.Driver/Neo4j.Driver/V1/Types/CypherDate.cs rename to Neo4j.Driver/Neo4j.Driver/V1/Types/LocalDate.cs index de6903997..16854fb1e 100644 --- a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherDate.cs +++ b/Neo4j.Driver/Neo4j.Driver/V1/Types/LocalDate.cs @@ -16,6 +16,7 @@ // limitations under the License. using System; +using System.Collections.Generic; using Neo4j.Driver.Internal; using Neo4j.Driver.Internal.Types; @@ -24,25 +25,30 @@ namespace Neo4j.Driver.V1 /// /// Represents a date value, without a time zone and time related components /// - public struct CypherDate : IValue, IEquatable, IComparable, IComparable, IConvertible, IHasDateComponents + public sealed class LocalDate : TemporalValue, IEquatable, IComparable, IComparable, IHasDateComponents { /// - /// Initializes a new instance of from a date value + /// Default comparer for values. + /// + public static readonly IComparer Comparer = new TemporalValueComparer(); + + /// + /// Initializes a new instance of from a date value /// /// - public CypherDate(DateTime date) + public LocalDate(DateTime date) : this(date.Year, date.Month, date.Day) { } /// - /// Initializes a new instance of from individual date component values + /// Initializes a new instance of from individual date component values /// /// /// /// - public CypherDate(int year, int month, int day) + public LocalDate(int year, int month, int day) { Throw.ArgumentOutOfRangeException.IfValueNotBetween(year, TemporalHelpers.MinYear, TemporalHelpers.MaxYear, nameof(year)); Throw.ArgumentOutOfRangeException.IfValueNotBetween(month, TemporalHelpers.MinMonth, TemporalHelpers.MaxMonth, nameof(month)); @@ -85,13 +91,15 @@ public DateTime DateTime /// /// Returns a value indicating whether the value of this instance is equal to the - /// value of the specified instance. + /// value of the specified instance. /// /// The object to compare to this instance. /// true if the value parameter equals the value of /// this instance; otherwise, false - public bool Equals(CypherDate other) + public bool Equals(LocalDate other) { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; return Year == other.Year && Month == other.Month && Day == other.Day; } @@ -99,12 +107,13 @@ public bool Equals(CypherDate other) /// Returns a value indicating whether this instance is equal to a specified object. /// /// The object to compare to this instance. - /// true if value is an instance of and + /// true if value is an instance of and /// equals the value of this instance; otherwise, false public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; - return obj is CypherDate && Equals((CypherDate) obj); + if (ReferenceEquals(this, obj)) return true; + return obj is LocalDate && Equals((LocalDate) obj); } /// @@ -123,7 +132,7 @@ public override int GetHashCode() } /// - /// Converts the value of the current object to its equivalent string representation. + /// Converts the value of the current object to its equivalent string representation. /// /// String representation of this Point. public override string ToString() @@ -132,14 +141,16 @@ public override string ToString() } /// - /// Compares the value of this instance to a specified value and returns an integer + /// Compares the value of this instance to a specified value and returns an integer /// that indicates whether this instance is earlier than, the same as, or later than the specified /// DateTime value. /// /// The object to compare to the current instance. /// A signed number indicating the relative values of this instance and the value parameter. - public int CompareTo(CypherDate other) + public int CompareTo(LocalDate other) { + if (ReferenceEquals(this, other)) return 0; + if (ReferenceEquals(null, other)) return 1; var yearComparison = Year.CompareTo(other.Year); if (yearComparison != 0) return yearComparison; var monthComparison = Month.CompareTo(other.Month); @@ -148,164 +159,78 @@ public int CompareTo(CypherDate other) } /// - /// Compares the value of this instance to a specified object which is expected to be a + /// Compares the value of this instance to a specified object which is expected to be a /// value, and returns an integer that indicates whether this instance is earlier than, the same as, - /// or later than the specified value. + /// or later than the specified value. /// /// The object to compare to the current instance. /// A signed number indicating the relative values of this instance and the value parameter. public int CompareTo(object obj) { if (ReferenceEquals(null, obj)) return 1; - if (!(obj is CypherDate)) throw new ArgumentException($"Object must be of type {nameof(CypherDate)}"); - return CompareTo((CypherDate) obj); + if (ReferenceEquals(this, obj)) return 0; + if (!(obj is LocalDate)) throw new ArgumentException($"Object must be of type {nameof(LocalDate)}"); + return CompareTo((LocalDate) obj); } /// - /// Determines whether one specified is earlier than another specified - /// . + /// Determines whether one specified is earlier than another specified + /// . /// /// The first object to compare. /// The second object to compare. /// - public static bool operator <(CypherDate left, CypherDate right) + public static bool operator <(LocalDate left, LocalDate right) { return left.CompareTo(right) < 0; } /// - /// Determines whether one specified is later than another specified - /// . + /// Determines whether one specified is later than another specified + /// . /// /// The first object to compare. /// The second object to compare. /// - public static bool operator >(CypherDate left, CypherDate right) + public static bool operator >(LocalDate left, LocalDate right) { return left.CompareTo(right) > 0; } /// - /// Determines whether one specified represents a duration that is the - /// same as or later than the other specified + /// Determines whether one specified represents a duration that is the + /// same as or later than the other specified /// /// The first object to compare. /// The second object to compare. /// - public static bool operator <=(CypherDate left, CypherDate right) + public static bool operator <=(LocalDate left, LocalDate right) { return left.CompareTo(right) <= 0; } /// - /// Determines whether one specified represents a duration that is the - /// same as or earlier than the other specified + /// Determines whether one specified represents a duration that is the + /// same as or earlier than the other specified /// /// The first object to compare. /// The second object to compare. /// - public static bool operator >=(CypherDate left, CypherDate right) + public static bool operator >=(LocalDate left, LocalDate right) { return left.CompareTo(right) >= 0; } - - #region IConvertible Implementation - - TypeCode IConvertible.GetTypeCode() - { - return TypeCode.Object; - } - - bool IConvertible.ToBoolean(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to boolean is not supported."); - } - - char IConvertible.ToChar(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to char is not supported."); - } - - sbyte IConvertible.ToSByte(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to sbyte is not supported."); - } - - byte IConvertible.ToByte(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to byte is not supported."); - } - - short IConvertible.ToInt16(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to short is not supported."); - } - - ushort IConvertible.ToUInt16(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned short is not supported."); - } - - int IConvertible.ToInt32(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to int is not supported."); - } - - uint IConvertible.ToUInt32(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned int is not supported."); - } - - long IConvertible.ToInt64(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to long is not supported."); - } - - ulong IConvertible.ToUInt64(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned long is not supported."); - } - - float IConvertible.ToSingle(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to single is not supported."); - } - - double IConvertible.ToDouble(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to double is not supported."); - } - - decimal IConvertible.ToDecimal(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to decimal is not supported."); - } - - DateTime IConvertible.ToDateTime(IFormatProvider provider) + + /// + protected override DateTime ToDateTime() { return DateTime; } - string IConvertible.ToString(IFormatProvider provider) - { - return ToString(); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider provider) + /// + protected override DateTimeOffset ToDateTimeOffset() { - if (conversionType == typeof(DateTime)) - { - return DateTime; - } - - if (conversionType == typeof(string)) - { - return ToString(); - } - - throw new InvalidCastException($"Conversion of {GetType().Name} to {conversionType.Name} is not supported."); + return new DateTimeOffset(DateTime); } - - #endregion } } \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherDateTime.cs b/Neo4j.Driver/Neo4j.Driver/V1/Types/LocalDateTime.cs similarity index 64% rename from Neo4j.Driver/Neo4j.Driver/V1/Types/CypherDateTime.cs rename to Neo4j.Driver/Neo4j.Driver/V1/Types/LocalDateTime.cs index 12ab1ef2e..1abf94f55 100644 --- a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherDateTime.cs +++ b/Neo4j.Driver/Neo4j.Driver/V1/Types/LocalDateTime.cs @@ -16,6 +16,7 @@ // limitations under the License. using System; +using System.Collections.Generic; using Neo4j.Driver.Internal; using Neo4j.Driver.Internal.Types; @@ -24,27 +25,15 @@ namespace Neo4j.Driver.V1 /// /// Represents a local date time value, without a time zone /// - public struct CypherDateTime : IValue, IEquatable, IComparable, IComparable, IConvertible, IHasDateTimeComponents + public sealed class LocalDateTime : TemporalValue, IEquatable, IComparable, IComparable, IHasDateTimeComponents { - /// - /// Initializes a new instance of from individual date time - /// component values + /// Default comparer for values. /// - /// - /// - /// - /// - /// - /// - public CypherDateTime(int year, int month, int day, int hour, int minute, int second) - : this(year, month, day, hour, minute, second, 0) - { - - } + public static readonly IComparer Comparer = new TemporalValueComparer(); /// - /// Initializes a new instance of from given value. + /// Initializes a new instance of from given value. /// The given value will be normalized to local time /// before being used. /// @@ -55,7 +44,7 @@ public CypherDateTime(int year, int month, int day, int hour, int minute, int se /// /// /// - public CypherDateTime(DateTime dateTime) + public LocalDateTime(DateTime dateTime) : this(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, TemporalHelpers.ExtractNanosecondFromTicks(dateTime.Ticks)) { @@ -63,7 +52,23 @@ public CypherDateTime(DateTime dateTime) } /// - /// Initializes a new instance of from individual date time + /// Initializes a new instance of from individual date time + /// component values + /// + /// + /// + /// + /// + /// + /// + public LocalDateTime(int year, int month, int day, int hour, int minute, int second) + : this(year, month, day, hour, minute, second, 0) + { + + } + + /// + /// Initializes a new instance of from individual date time /// /// /// @@ -72,7 +77,7 @@ public CypherDateTime(DateTime dateTime) /// /// /// - public CypherDateTime(int year, int month, int day, int hour, int minute, int second, int nanosecond) + public LocalDateTime(int year, int month, int day, int hour, int minute, int second, int nanosecond) { Throw.ArgumentOutOfRangeException.IfValueNotBetween(year, TemporalHelpers.MinYear, TemporalHelpers.MaxYear, nameof(year)); Throw.ArgumentOutOfRangeException.IfValueNotBetween(month, TemporalHelpers.MinMonth, TemporalHelpers.MaxMonth, nameof(month)); @@ -146,27 +151,29 @@ public DateTime DateTime /// /// Returns a value indicating whether the value of this instance is equal to the - /// value of the specified instance. + /// value of the specified instance. /// /// The object to compare to this instance. /// true if the value parameter equals the value of /// this instance; otherwise, false - public bool Equals(CypherDateTime other) + public bool Equals(LocalDateTime other) { - return Year == other.Year && Month == other.Month && Day == other.Day && Hour == other.Hour && - Minute == other.Minute && Second == other.Second && Nanosecond == other.Nanosecond; + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return Year == other.Year && Month == other.Month && Day == other.Day && Hour == other.Hour && Minute == other.Minute && Second == other.Second && Nanosecond == other.Nanosecond; } /// /// Returns a value indicating whether this instance is equal to a specified object. /// /// The object to compare to this instance. - /// true if value is an instance of and + /// true if value is an instance of and /// equals the value of this instance; otherwise, false public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; - return obj is CypherDateTime && Equals((CypherDateTime) obj); + if (ReferenceEquals(this, obj)) return true; + return obj is LocalDateTime && Equals((LocalDateTime) obj); } /// @@ -189,7 +196,7 @@ public override int GetHashCode() } /// - /// Converts the value of the current object to its equivalent string representation. + /// Converts the value of the current object to its equivalent string representation. /// /// String representation of this Point. public override string ToString() @@ -199,14 +206,16 @@ public override string ToString() } /// - /// Compares the value of this instance to a specified value and returns an integer + /// Compares the value of this instance to a specified value and returns an integer /// that indicates whether this instance is earlier than, the same as, or later than the specified /// DateTime value. /// /// The object to compare to the current instance. /// A signed number indicating the relative values of this instance and the value parameter. - public int CompareTo(CypherDateTime other) + public int CompareTo(LocalDateTime other) { + if (ReferenceEquals(this, other)) return 0; + if (ReferenceEquals(null, other)) return 1; var yearComparison = Year.CompareTo(other.Year); if (yearComparison != 0) return yearComparison; var monthComparison = Month.CompareTo(other.Month); @@ -223,164 +232,78 @@ public int CompareTo(CypherDateTime other) } /// - /// Compares the value of this instance to a specified object which is expected to be a + /// Compares the value of this instance to a specified object which is expected to be a /// value, and returns an integer that indicates whether this instance is earlier than, the same as, - /// or later than the specified value. + /// or later than the specified value. /// /// The object to compare to the current instance. /// A signed number indicating the relative values of this instance and the value parameter. public int CompareTo(object obj) { if (ReferenceEquals(null, obj)) return 1; - if (!(obj is CypherDateTime)) throw new ArgumentException($"Object must be of type {nameof(CypherDateTime)}"); - return CompareTo((CypherDateTime) obj); + if (ReferenceEquals(this, obj)) return 0; + if (!(obj is LocalDateTime)) throw new ArgumentException($"Object must be of type {nameof(LocalDateTime)}"); + return CompareTo((LocalDateTime) obj); } /// - /// Determines whether one specified is earlier than another specified - /// . + /// Determines whether one specified is earlier than another specified + /// . /// /// The first object to compare. /// The second object to compare. /// - public static bool operator <(CypherDateTime left, CypherDateTime right) + public static bool operator <(LocalDateTime left, LocalDateTime right) { return left.CompareTo(right) < 0; } /// - /// Determines whether one specified is later than another specified - /// . + /// Determines whether one specified is later than another specified + /// . /// /// The first object to compare. /// The second object to compare. /// - public static bool operator >(CypherDateTime left, CypherDateTime right) + public static bool operator >(LocalDateTime left, LocalDateTime right) { return left.CompareTo(right) > 0; } /// - /// Determines whether one specified represents a duration that is the - /// same as or later than the other specified + /// Determines whether one specified represents a duration that is the + /// same as or later than the other specified /// /// The first object to compare. /// The second object to compare. /// - public static bool operator <=(CypherDateTime left, CypherDateTime right) + public static bool operator <=(LocalDateTime left, LocalDateTime right) { return left.CompareTo(right) <= 0; } /// - /// Determines whether one specified represents a duration that is the - /// same as or earlier than the other specified + /// Determines whether one specified represents a duration that is the + /// same as or earlier than the other specified /// /// The first object to compare. /// The second object to compare. /// - public static bool operator >=(CypherDateTime left, CypherDateTime right) + public static bool operator >=(LocalDateTime left, LocalDateTime right) { return left.CompareTo(right) >= 0; } - #region IConvertible Implementation - - TypeCode IConvertible.GetTypeCode() - { - return TypeCode.Object; - } - - bool IConvertible.ToBoolean(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to boolean is not supported."); - } - - char IConvertible.ToChar(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to char is not supported."); - } - - sbyte IConvertible.ToSByte(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to sbyte is not supported."); - } - - byte IConvertible.ToByte(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to byte is not supported."); - } - - short IConvertible.ToInt16(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to short is not supported."); - } - - ushort IConvertible.ToUInt16(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned short is not supported."); - } - - int IConvertible.ToInt32(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to int is not supported."); - } - - uint IConvertible.ToUInt32(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned int is not supported."); - } - - long IConvertible.ToInt64(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to long is not supported."); - } - - ulong IConvertible.ToUInt64(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned long is not supported."); - } - - float IConvertible.ToSingle(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to single is not supported."); - } - - double IConvertible.ToDouble(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to double is not supported."); - } - - decimal IConvertible.ToDecimal(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to decimal is not supported."); - } - - DateTime IConvertible.ToDateTime(IFormatProvider provider) + /// + protected override DateTime ToDateTime() { return DateTime; } - string IConvertible.ToString(IFormatProvider provider) + /// + protected override DateTimeOffset ToDateTimeOffset() { - return ToString(); + return new DateTimeOffset(DateTime); } - - object IConvertible.ToType(Type conversionType, IFormatProvider provider) - { - if (conversionType == typeof(DateTime)) - { - return DateTime; - } - - if (conversionType == typeof(string)) - { - return ToString(); - } - - throw new InvalidCastException($"Conversion of {GetType().Name} to {conversionType.Name} is not supported."); - } - - #endregion } } diff --git a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherTime.cs b/Neo4j.Driver/Neo4j.Driver/V1/Types/LocalTime.cs similarity index 58% rename from Neo4j.Driver/Neo4j.Driver/V1/Types/CypherTime.cs rename to Neo4j.Driver/Neo4j.Driver/V1/Types/LocalTime.cs index db577d28b..6378cc6bb 100644 --- a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherTime.cs +++ b/Neo4j.Driver/Neo4j.Driver/V1/Types/LocalTime.cs @@ -16,6 +16,7 @@ // limitations under the License. using System; +using System.Collections.Generic; using Neo4j.Driver.Internal; using Neo4j.Driver.Internal.Types; @@ -24,48 +25,53 @@ namespace Neo4j.Driver.V1 /// /// Represents a local time value /// - public struct CypherTime : IValue, IEquatable, IComparable, IComparable, IConvertible, IHasTimeComponents + public sealed class LocalTime : TemporalValue, IEquatable, IComparable, IComparable, IHasTimeComponents { /// - /// Initializes a new instance of from time components of given + /// Default comparer for values. + /// + public static readonly IComparer Comparer = new TemporalValueComparer(); + + /// + /// Initializes a new instance of from time components of given /// /// - public CypherTime(DateTime time) + public LocalTime(DateTime time) : this(time.TimeOfDay) { } /// - /// Initializes a new instance of from given value + /// Initializes a new instance of from given value /// /// - public CypherTime(TimeSpan time) + public LocalTime(TimeSpan time) : this(time.Hours, time.Minutes, time.Seconds, TemporalHelpers.ExtractNanosecondFromTicks(time.Ticks)) { } /// - /// Initializes a new instance of from individual time components + /// Initializes a new instance of from individual time components /// /// /// /// - public CypherTime(int hour, int minute, int second) + public LocalTime(int hour, int minute, int second) : this(hour, minute, second, 0) { } /// - /// Initializes a new instance of from individual time components + /// Initializes a new instance of from individual time components /// /// /// /// /// - public CypherTime(int hour, int minute, int second, int nanosecond) + public LocalTime(int hour, int minute, int second, int nanosecond) { Throw.ArgumentOutOfRangeException.IfValueNotBetween(hour, TemporalHelpers.MinHour, TemporalHelpers.MaxHour, nameof(hour)); Throw.ArgumentOutOfRangeException.IfValueNotBetween(minute, TemporalHelpers.MinMinute, TemporalHelpers.MaxMinute, nameof(minute)); @@ -116,13 +122,15 @@ public TimeSpan Time /// /// Returns a value indicating whether the value of this instance is equal to the - /// value of the specified instance. + /// value of the specified instance. /// /// The object to compare to this instance. /// true if the value parameter equals the value of /// this instance; otherwise, false - public bool Equals(CypherTime other) + public bool Equals(LocalTime other) { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; return Hour == other.Hour && Minute == other.Minute && Second == other.Second && Nanosecond == other.Nanosecond; } @@ -130,12 +138,13 @@ public bool Equals(CypherTime other) /// Returns a value indicating whether this instance is equal to a specified object. /// /// The object to compare to this instance. - /// true if value is an instance of and + /// true if value is an instance of and /// equals the value of this instance; otherwise, false public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; - return obj is CypherTime && Equals((CypherTime) obj); + if (ReferenceEquals(this, obj)) return true; + return obj is LocalTime && Equals((LocalTime) obj); } /// @@ -155,7 +164,7 @@ public override int GetHashCode() } /// - /// Converts the value of the current object to its equivalent string representation. + /// Converts the value of the current object to its equivalent string representation. /// /// String representation of this Point. public override string ToString() @@ -164,14 +173,16 @@ public override string ToString() } /// - /// Compares the value of this instance to a specified value and returns an integer + /// Compares the value of this instance to a specified value and returns an integer /// that indicates whether this instance is earlier than, the same as, or later than the specified /// DateTime value. /// /// The object to compare to the current instance. /// A signed number indicating the relative values of this instance and the value parameter. - public int CompareTo(CypherTime other) + public int CompareTo(LocalTime other) { + if (ReferenceEquals(this, other)) return 0; + if (ReferenceEquals(null, other)) return 1; var hourComparison = Hour.CompareTo(other.Hour); if (hourComparison != 0) return hourComparison; var minuteComparison = Minute.CompareTo(other.Minute); @@ -182,169 +193,78 @@ public int CompareTo(CypherTime other) } /// - /// Compares the value of this instance to a specified object which is expected to be a + /// Compares the value of this instance to a specified object which is expected to be a /// value, and returns an integer that indicates whether this instance is earlier than, the same as, - /// or later than the specified value. + /// or later than the specified value. /// /// The object to compare to the current instance. /// A signed number indicating the relative values of this instance and the value parameter. public int CompareTo(object obj) { if (ReferenceEquals(null, obj)) return 1; - if (!(obj is CypherTime)) throw new ArgumentException($"Object must be of type {nameof(CypherTime)}"); - return CompareTo((CypherTime) obj); + if (ReferenceEquals(this, obj)) return 0; + if (!(obj is LocalTime)) throw new ArgumentException($"Object must be of type {nameof(LocalTime)}"); + return CompareTo((LocalTime) obj); } /// - /// Determines whether one specified is earlier than another specified - /// . + /// Determines whether one specified is earlier than another specified + /// . /// /// The first object to compare. /// The second object to compare. /// - public static bool operator <(CypherTime left, CypherTime right) + public static bool operator <(LocalTime left, LocalTime right) { return left.CompareTo(right) < 0; } /// - /// Determines whether one specified is later than another specified - /// . + /// Determines whether one specified is later than another specified + /// . /// /// The first object to compare. /// The second object to compare. /// - public static bool operator >(CypherTime left, CypherTime right) + public static bool operator >(LocalTime left, LocalTime right) { return left.CompareTo(right) > 0; } /// - /// Determines whether one specified represents a duration that is the - /// same as or later than the other specified + /// Determines whether one specified represents a duration that is the + /// same as or later than the other specified /// /// The first object to compare. /// The second object to compare. /// - public static bool operator <=(CypherTime left, CypherTime right) + public static bool operator <=(LocalTime left, LocalTime right) { return left.CompareTo(right) <= 0; } /// - /// Determines whether one specified represents a duration that is the - /// same as or earlier than the other specified + /// Determines whether one specified represents a duration that is the + /// same as or earlier than the other specified /// /// The first object to compare. /// The second object to compare. /// - public static bool operator >=(CypherTime left, CypherTime right) + public static bool operator >=(LocalTime left, LocalTime right) { return left.CompareTo(right) >= 0; } - #region IConvertible Implementation - - TypeCode IConvertible.GetTypeCode() - { - return TypeCode.Object; - } - - bool IConvertible.ToBoolean(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to boolean is not supported."); - } - - char IConvertible.ToChar(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to char is not supported."); - } - - sbyte IConvertible.ToSByte(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to sbyte is not supported."); - } - - byte IConvertible.ToByte(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to byte is not supported."); - } - - short IConvertible.ToInt16(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to short is not supported."); - } - - ushort IConvertible.ToUInt16(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned short is not supported."); - } - - int IConvertible.ToInt32(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to int is not supported."); - } - - uint IConvertible.ToUInt32(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned int is not supported."); - } - - long IConvertible.ToInt64(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to long is not supported."); - } - - ulong IConvertible.ToUInt64(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned long is not supported."); - } - - float IConvertible.ToSingle(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to single is not supported."); - } - - double IConvertible.ToDouble(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to double is not supported."); - } - - decimal IConvertible.ToDecimal(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to decimal is not supported."); - } - - DateTime IConvertible.ToDateTime(IFormatProvider provider) + /// + protected override DateTime ToDateTime() { return DateTime.Today.Add(Time); } - string IConvertible.ToString(IFormatProvider provider) - { - return ToString(); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider provider) + /// + protected override TimeSpan ToTimeSpan() { - if (conversionType == typeof(TimeSpan)) - { - return Time; - } - - if (conversionType == typeof(DateTime)) - { - return DateTime.Today.Add(Time); - } - - if (conversionType == typeof(string)) - { - return ToString(); - } - - throw new InvalidCastException($"Conversion of {GetType().Name} to {conversionType.Name} is not supported."); + return Time; } - - #endregion } } \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherTimeWithOffset.cs b/Neo4j.Driver/Neo4j.Driver/V1/Types/OffsetTime.cs similarity index 59% rename from Neo4j.Driver/Neo4j.Driver/V1/Types/CypherTimeWithOffset.cs rename to Neo4j.Driver/Neo4j.Driver/V1/Types/OffsetTime.cs index 869b205dc..200cb6f7c 100644 --- a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherTimeWithOffset.cs +++ b/Neo4j.Driver/Neo4j.Driver/V1/Types/OffsetTime.cs @@ -16,6 +16,7 @@ // limitations under the License. using System; +using System.Collections.Generic; using Neo4j.Driver.Internal; using Neo4j.Driver.Internal.Types; @@ -24,37 +25,41 @@ namespace Neo4j.Driver.V1 /// /// Represents a time value with a UTC offset /// - public struct CypherTimeWithOffset : IValue, IEquatable, IComparable, - IComparable, IConvertible, IHasTimeComponents + public sealed class OffsetTime : TemporalValue, IEquatable, IComparable, IComparable, IHasTimeComponents { /// - /// Initializes a new instance of from time components of given value + /// Default comparer for values. + /// + public static readonly IComparer Comparer = new TemporalValueComparer(); + + /// + /// Initializes a new instance of from time components of given value /// /// /// - public CypherTimeWithOffset(DateTime time, TimeSpan offset) + public OffsetTime(DateTime time, TimeSpan offset) : this(time.TimeOfDay, (int) offset.TotalSeconds) { } /// - /// Initializes a new instance of from given value + /// Initializes a new instance of from given value /// /// /// - public CypherTimeWithOffset(TimeSpan time, TimeSpan offset) + public OffsetTime(TimeSpan time, TimeSpan offset) : this(time, (int) offset.TotalSeconds) { } /// - /// Initializes a new instance of from given value + /// Initializes a new instance of from given value /// /// /// - private CypherTimeWithOffset(TimeSpan time, int offsetSeconds) + private OffsetTime(TimeSpan time, int offsetSeconds) : this(time.Hours, time.Minutes, time.Seconds, TemporalHelpers.ExtractNanosecondFromTicks(time.Ticks), offsetSeconds) { @@ -62,27 +67,27 @@ private CypherTimeWithOffset(TimeSpan time, int offsetSeconds) } /// - /// Initializes a new instance of from individual time components + /// Initializes a new instance of from individual time components /// /// /// /// /// - public CypherTimeWithOffset(int hour, int minute, int second, int offsetSeconds) + public OffsetTime(int hour, int minute, int second, int offsetSeconds) : this(hour, minute, second, 0, offsetSeconds) { } /// - /// Initializes a new instance of from individual time components + /// Initializes a new instance of from individual time components /// /// /// /// /// /// - public CypherTimeWithOffset(int hour, int minute, int second, int nanosecond, int offsetSeconds) + public OffsetTime(int hour, int minute, int second, int nanosecond, int offsetSeconds) { Throw.ArgumentOutOfRangeException.IfValueNotBetween(hour, TemporalHelpers.MinHour, TemporalHelpers.MaxHour, nameof(hour)); @@ -102,7 +107,7 @@ public CypherTimeWithOffset(int hour, int minute, int second, int nanosecond, in OffsetSeconds = offsetSeconds; } - internal CypherTimeWithOffset(IHasTimeComponents time, int offsetSeconds) + internal OffsetTime(IHasTimeComponents time, int offsetSeconds) : this(time.Hour, time.Minute, time.Second, time.Nanosecond, offsetSeconds) { @@ -155,27 +160,29 @@ public TimeSpan Time /// /// Returns a value indicating whether the value of this instance is equal to the - /// value of the specified instance. + /// value of the specified instance. /// /// The object to compare to this instance. /// true if the value parameter equals the value of /// this instance; otherwise, false - public bool Equals(CypherTimeWithOffset other) + public bool Equals(OffsetTime other) { - return Hour == other.Hour && Minute == other.Minute && Second == other.Second && - Nanosecond == other.Nanosecond && OffsetSeconds == other.OffsetSeconds; + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return Hour == other.Hour && Minute == other.Minute && Second == other.Second && Nanosecond == other.Nanosecond && OffsetSeconds == other.OffsetSeconds; } /// /// Returns a value indicating whether this instance is equal to a specified object. /// /// The object to compare to this instance. - /// true if value is an instance of and + /// true if value is an instance of and /// equals the value of this instance; otherwise, false public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; - return obj is CypherTimeWithOffset && Equals((CypherTimeWithOffset) obj); + if (ReferenceEquals(this, obj)) return true; + return obj is OffsetTime && Equals((OffsetTime) obj); } /// @@ -196,7 +203,7 @@ public override int GetHashCode() } /// - /// Converts the value of the current object to its equivalent string representation. + /// Converts the value of the current object to its equivalent string representation. /// /// String representation of this Point. public override string ToString() @@ -206,14 +213,17 @@ public override string ToString() } /// - /// Compares the value of this instance to a specified value and returns an integer + /// Compares the value of this instance to a specified value and returns an integer /// that indicates whether this instance is earlier than, the same as, or later than the specified /// DateTime value. /// /// The object to compare to the current instance. /// A signed number indicating the relative values of this instance and the value parameter. - public int CompareTo(CypherTimeWithOffset other) + public int CompareTo(OffsetTime other) { + if (ReferenceEquals(this, other)) return 0; + if (ReferenceEquals(null, other)) return 1; + var thisNanoOfDay = this.ToNanoOfDay() - (OffsetSeconds * TemporalHelpers.NanosPerSecond); var otherNanoOfDay = other.ToNanoOfDay() - (other.OffsetSeconds * TemporalHelpers.NanosPerSecond); @@ -231,160 +241,67 @@ public int CompareTo(CypherTimeWithOffset other) } /// - /// Compares the value of this instance to a specified object which is expected to be a + /// Compares the value of this instance to a specified object which is expected to be a /// value, and returns an integer that indicates whether this instance is earlier than, the same as, - /// or later than the specified value. + /// or later than the specified value. /// /// The object to compare to the current instance. /// A signed number indicating the relative values of this instance and the value parameter. public int CompareTo(object obj) { if (ReferenceEquals(null, obj)) return 1; - if (!(obj is CypherTimeWithOffset)) - throw new ArgumentException($"Object must be of type {nameof(CypherTimeWithOffset)}"); - return CompareTo((CypherTimeWithOffset) obj); + if (ReferenceEquals(this, obj)) return 0; + if (!(obj is OffsetTime)) + throw new ArgumentException($"Object must be of type {nameof(OffsetTime)}"); + return CompareTo((OffsetTime) obj); } /// - /// Determines whether one specified is earlier than another specified - /// . + /// Determines whether one specified is earlier than another specified + /// . /// /// The first object to compare. /// The second object to compare. /// - public static bool operator <(CypherTimeWithOffset left, CypherTimeWithOffset right) + public static bool operator <(OffsetTime left, OffsetTime right) { return left.CompareTo(right) < 0; } /// - /// Determines whether one specified is later than another specified - /// . + /// Determines whether one specified is later than another specified + /// . /// /// The first object to compare. /// The second object to compare. /// - public static bool operator >(CypherTimeWithOffset left, CypherTimeWithOffset right) + public static bool operator >(OffsetTime left, OffsetTime right) { return left.CompareTo(right) > 0; } /// - /// Determines whether one specified represents a duration that is the - /// same as or later than the other specified + /// Determines whether one specified represents a duration that is the + /// same as or later than the other specified /// /// The first object to compare. /// The second object to compare. /// - public static bool operator <=(CypherTimeWithOffset left, CypherTimeWithOffset right) + public static bool operator <=(OffsetTime left, OffsetTime right) { return left.CompareTo(right) <= 0; } /// - /// Determines whether one specified represents a duration that is the - /// same as or earlier than the other specified + /// Determines whether one specified represents a duration that is the + /// same as or earlier than the other specified /// /// The first object to compare. /// The second object to compare. /// - public static bool operator >=(CypherTimeWithOffset left, CypherTimeWithOffset right) + public static bool operator >=(OffsetTime left, OffsetTime right) { return left.CompareTo(right) >= 0; } - - #region IConvertible Implementation - - TypeCode IConvertible.GetTypeCode() - { - return TypeCode.Object; - } - - bool IConvertible.ToBoolean(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to boolean is not supported."); - } - - char IConvertible.ToChar(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to char is not supported."); - } - - sbyte IConvertible.ToSByte(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to sbyte is not supported."); - } - - byte IConvertible.ToByte(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to byte is not supported."); - } - - short IConvertible.ToInt16(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to short is not supported."); - } - - ushort IConvertible.ToUInt16(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned short is not supported."); - } - - int IConvertible.ToInt32(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to int is not supported."); - } - - uint IConvertible.ToUInt32(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned int is not supported."); - } - - long IConvertible.ToInt64(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to long is not supported."); - } - - ulong IConvertible.ToUInt64(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned long is not supported."); - } - - float IConvertible.ToSingle(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to single is not supported."); - } - - double IConvertible.ToDouble(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to double is not supported."); - } - - decimal IConvertible.ToDecimal(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to decimal is not supported."); - } - - DateTime IConvertible.ToDateTime(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to DateTime is not supported."); - } - - string IConvertible.ToString(IFormatProvider provider) - { - return ToString(); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider provider) - { - if (conversionType == typeof(string)) - { - return ToString(); - } - - throw new InvalidCastException($"Conversion of {GetType().Name} to {conversionType.Name} is not supported."); - } - - #endregion } } \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherPoint.cs b/Neo4j.Driver/Neo4j.Driver/V1/Types/Point.cs similarity index 82% rename from Neo4j.Driver/Neo4j.Driver/V1/Types/CypherPoint.cs rename to Neo4j.Driver/Neo4j.Driver/V1/Types/Point.cs index eeebe5b6d..26ee78feb 100644 --- a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherPoint.cs +++ b/Neo4j.Driver/Neo4j.Driver/V1/Types/Point.cs @@ -23,37 +23,37 @@ namespace Neo4j.Driver.V1 /// /// Represents a single three-dimensional point in a particular coordinate reference system. /// - public struct CypherPoint: IValue, IEquatable + public sealed class Point : IValue, IEquatable { internal const int TwoD = 2; internal const int ThreeD = 3; /// - /// Initializes a new instance of structure with two dimensions + /// Initializes a new instance of structure with two dimensions /// /// /// /// - public CypherPoint(int srId, double x, double y) + public Point(int srId, double x, double y) : this(TwoD, srId, x, y, double.NaN) { } /// - /// Initializes a new instance of structure with three dimensions + /// Initializes a new instance of structure with three dimensions /// /// /// /// /// - public CypherPoint(int srId, double x, double y, double z) + public Point(int srId, double x, double y, double z) : this(ThreeD, srId, x, y, z) { } - private CypherPoint(int dimension, int srId, double x, double y, double z) + private Point(int dimension, int srId, double x, double y, double z) { Dimension = dimension; SrId = srId; @@ -78,7 +78,7 @@ private CypherPoint(int dimension, int srId, double x, double y, double z) /// - /// Converts the value of the current object to its equivalent string representation. + /// Converts the value of the current object to its equivalent string representation. /// /// String representation of this Point. public override string ToString() @@ -113,13 +113,15 @@ public override int GetHashCode() /// /// Returns a value indicating whether the value of this instance is equal to the - /// value of the specified instance. + /// value of the specified instance. /// /// The object to compare to this instance. /// true if the value parameter equals the value of /// this instance; otherwise, false - public bool Equals(CypherPoint other) + public bool Equals(Point other) { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; return Dimension == other.Dimension && SrId == other.SrId && X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z); } @@ -127,13 +129,13 @@ public bool Equals(CypherPoint other) /// Returns a value indicating whether this instance is equal to a specified object. /// /// The object to compare to this instance. - /// true if value is an instance of and + /// true if value is an instance of and /// equals the value of this instance; otherwise, false public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; - if (obj.GetType() != GetType()) return false; - return Equals((CypherPoint) obj); + if (ReferenceEquals(this, obj)) return true; + return obj is Point && Equals((Point) obj); } } } \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver/V1/Types/TemporalValue.cs b/Neo4j.Driver/Neo4j.Driver/V1/Types/TemporalValue.cs new file mode 100644 index 000000000..40c1f89e1 --- /dev/null +++ b/Neo4j.Driver/Neo4j.Driver/V1/Types/TemporalValue.cs @@ -0,0 +1,183 @@ +// Copyright (c) 2002-2018 "Neo Technology," +// Network Engine for Objects in Lund AB [http://neotechnology.com] +// +// This file is part of Neo4j. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using System.Collections.Generic; +using Neo4j.Driver.Internal.Types; + +namespace Neo4j.Driver.V1 +{ + /// + /// Base class for temporal values + /// + public abstract class TemporalValue: IValue, IConvertible + { + /// + /// Converts this instance to a instance. + /// + /// A value + /// If conversion is not possible + /// If conversion results in a truncation under ms precision + /// If the value falls beyond valid range of target type + protected virtual DateTime ToDateTime() + { + throw new InvalidCastException($"Conversion of {GetType().Name} to {nameof(DateTime)} is not supported."); + } + + /// + /// Converts this instance to a instance. + /// + /// A value + /// If conversion is not possible + /// If conversion results in a truncation under ms precision + /// If the value falls beyond valid range of target type + protected virtual DateTimeOffset ToDateTimeOffset() + { + throw new InvalidCastException($"Conversion of {GetType().Name} to {nameof(DateTimeOffset)} is not supported."); + } + + /// + /// Converts this instance to a instance. + /// + /// A value + /// If conversion is not possible + /// If conversion results in a truncation under ms precision + /// If the value falls beyond valid range of target type + protected virtual TimeSpan ToTimeSpan() + { + throw new InvalidCastException($"Conversion of {GetType().Name} to {nameof(TimeSpan)} is not supported."); + } + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Object; + } + + bool IConvertible.ToBoolean(IFormatProvider provider) + { + throw new InvalidCastException($"Conversion of {GetType().Name} to boolean is not supported."); + } + + char IConvertible.ToChar(IFormatProvider provider) + { + throw new InvalidCastException($"Conversion of {GetType().Name} to char is not supported."); + } + + sbyte IConvertible.ToSByte(IFormatProvider provider) + { + throw new InvalidCastException($"Conversion of {GetType().Name} to sbyte is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider provider) + { + throw new InvalidCastException($"Conversion of {GetType().Name} to byte is not supported."); + } + + short IConvertible.ToInt16(IFormatProvider provider) + { + throw new InvalidCastException($"Conversion of {GetType().Name} to short is not supported."); + } + + ushort IConvertible.ToUInt16(IFormatProvider provider) + { + throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned short is not supported."); + } + + int IConvertible.ToInt32(IFormatProvider provider) + { + throw new InvalidCastException($"Conversion of {GetType().Name} to int is not supported."); + } + + uint IConvertible.ToUInt32(IFormatProvider provider) + { + throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned int is not supported."); + } + + long IConvertible.ToInt64(IFormatProvider provider) + { + throw new InvalidCastException($"Conversion of {GetType().Name} to long is not supported."); + } + + ulong IConvertible.ToUInt64(IFormatProvider provider) + { + throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned long is not supported."); + } + + float IConvertible.ToSingle(IFormatProvider provider) + { + throw new InvalidCastException($"Conversion of {GetType().Name} to single is not supported."); + } + + double IConvertible.ToDouble(IFormatProvider provider) + { + throw new InvalidCastException($"Conversion of {GetType().Name} to double is not supported."); + } + + decimal IConvertible.ToDecimal(IFormatProvider provider) + { + throw new InvalidCastException($"Conversion of {GetType().Name} to decimal is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider provider) + { + return ToDateTime(); + } + + string IConvertible.ToString(IFormatProvider provider) + { + return ToString(); + } + + object IConvertible.ToType(Type conversionType, IFormatProvider provider) + { + if (conversionType == typeof(DateTime)) + { + return ToDateTime(); + } + + if (conversionType == typeof(DateTimeOffset)) + { + return ToDateTimeOffset(); + } + + if (conversionType == typeof(TimeSpan)) + { + return ToTimeSpan(); + } + + if (conversionType == typeof(string)) + { + return ToString(); + } + + throw new InvalidCastException($"Conversion of {GetType().Name} to {conversionType.Name} is not supported."); + } + + internal class TemporalValueComparer : IComparer + where T: TemporalValue, IComparable + { + public int Compare(T x, T y) + { + if (ReferenceEquals(x, y)) return 0; + if (ReferenceEquals(null, y)) return 1; + if (ReferenceEquals(null, x)) return -1; + return x.CompareTo(y); + } + } + + } +} \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver/V1/Types/Zone.cs b/Neo4j.Driver/Neo4j.Driver/V1/Types/Zone.cs new file mode 100644 index 000000000..38078b39d --- /dev/null +++ b/Neo4j.Driver/Neo4j.Driver/V1/Types/Zone.cs @@ -0,0 +1,54 @@ +// Copyright (c) 2002-2018 "Neo Technology," +// Network Engine for Objects in Lund AB [http://neotechnology.com] +// +// This file is part of Neo4j. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; + +namespace Neo4j.Driver.V1 +{ + /// + /// This abstract class represents a time zone that's usable by type. A time zone + /// can be identified either by its offset (in seconds) from UTC or its IANA/Windows time zone identifiers. You can + /// get corresponding instances of by using its or + /// members. + /// + public abstract class Zone + { + + internal abstract int OffsetSecondsAt(DateTime dateTime); + + /// + /// Creates a instance by using its offset from UTC + /// + /// The offset (in seconds) from UTC. + /// A instance + public static Zone Of(int offsetSeconds) + { + return new ZoneOffset(offsetSeconds); + } + + /// + /// Creates a instance by using its time zone identifier. + /// + /// The time zone identifier. + /// A instance + public static Zone Of(string zoneId) + { + return new ZoneId(zoneId); + } + + } +} \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver/V1/Types/ZoneId.cs b/Neo4j.Driver/Neo4j.Driver/V1/Types/ZoneId.cs new file mode 100644 index 000000000..f7def1d44 --- /dev/null +++ b/Neo4j.Driver/Neo4j.Driver/V1/Types/ZoneId.cs @@ -0,0 +1,89 @@ +// Copyright (c) 2002-2018 "Neo Technology," +// Network Engine for Objects in Lund AB [http://neotechnology.com] +// +// This file is part of Neo4j. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using Neo4j.Driver.Internal; + +namespace Neo4j.Driver.V1 +{ + /// + /// Represents a time zone specified by its time zone identifier. + /// + public sealed class ZoneId: Zone, IEquatable + { + + internal ZoneId(string id) + { + Throw.ArgumentNullException.If(() => string.IsNullOrWhiteSpace(id), nameof(id)); + + Id = id; + } + + /// The time zone identifier. + public string Id { get; } + + internal override int OffsetSecondsAt(DateTime dateTime) + { + return (int) TemporalHelpers.GetTimeZoneInfo(Id).GetUtcOffset(dateTime).TotalSeconds; + } + + /// + /// Converts the value of the current object to its equivalent string representation. + /// + /// String representation of this Point. + public override string ToString() + { + return TemporalHelpers.ToIsoTimeZoneId(Id); + } + + /// + /// Returns a value indicating whether the value of this instance is equal to the + /// value of the specified instance. + /// + /// The object to compare to this instance. + /// true if the value parameter equals the value of + /// this instance; otherwise, false + public bool Equals(ZoneId other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return string.Equals(Id, other.Id); + } + + /// + /// Returns a value indicating whether this instance is equal to a specified object. + /// + /// The object to compare to this instance. + /// true if value is an instance of and + /// equals the value of this instance; otherwise, false + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj is ZoneId id && Equals(id); + } + + /// + /// Returns the hash code for this instance. + /// + /// A 32-bit signed integer hash code. + public override int GetHashCode() + { + return (Id != null ? Id.GetHashCode() : 0); + } + } +} \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver/V1/Types/ZoneOffset.cs b/Neo4j.Driver/Neo4j.Driver/V1/Types/ZoneOffset.cs new file mode 100644 index 000000000..7884b8549 --- /dev/null +++ b/Neo4j.Driver/Neo4j.Driver/V1/Types/ZoneOffset.cs @@ -0,0 +1,93 @@ +// Copyright (c) 2002-2018 "Neo Technology," +// Network Engine for Objects in Lund AB [http://neotechnology.com] +// +// This file is part of Neo4j. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using Neo4j.Driver.Internal; + +namespace Neo4j.Driver.V1 +{ + /// + /// Represents a time zone specified by its offset from UTC. + /// + public sealed class ZoneOffset: Zone, IEquatable + { + + internal ZoneOffset(int offsetSeconds) + { + Throw.ArgumentOutOfRangeException.IfValueNotBetween(offsetSeconds, TemporalHelpers.MinOffset, + TemporalHelpers.MaxOffset, nameof(offsetSeconds)); + + OffsetSeconds = offsetSeconds; + } + + /// The offset (in seconds) from UTC. + public int OffsetSeconds { get; } + + /// The offset from UTC as a instance. + public TimeSpan Offset => TimeSpan.FromSeconds(OffsetSeconds); + + internal override int OffsetSecondsAt(DateTime dateTime) + { + return OffsetSeconds; + } + + /// + /// Converts the value of the current object to its equivalent string representation. + /// + /// String representation of this Point. + public override string ToString() + { + return TemporalHelpers.ToIsoTimeZoneOffset(OffsetSeconds); + } + + /// + /// Returns a value indicating whether the value of this instance is equal to the + /// value of the specified instance. + /// + /// The object to compare to this instance. + /// true if the value parameter equals the value of + /// this instance; otherwise, false + public bool Equals(ZoneOffset other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return OffsetSeconds == other.OffsetSeconds; + } + + /// + /// Returns a value indicating whether this instance is equal to a specified object. + /// + /// The object to compare to this instance. + /// true if value is an instance of and + /// equals the value of this instance; otherwise, false + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj is ZoneOffset offset && Equals(offset); + } + + /// + /// Returns the hash code for this instance. + /// + /// A 32-bit signed integer hash code. + public override int GetHashCode() + { + return OffsetSeconds; + } + } +} \ No newline at end of file diff --git a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherDateTimeWithOffset.cs b/Neo4j.Driver/Neo4j.Driver/V1/Types/ZonedDateTime.cs similarity index 58% rename from Neo4j.Driver/Neo4j.Driver/V1/Types/CypherDateTimeWithOffset.cs rename to Neo4j.Driver/Neo4j.Driver/V1/Types/ZonedDateTime.cs index 5ee673aeb..685076876 100644 --- a/Neo4j.Driver/Neo4j.Driver/V1/Types/CypherDateTimeWithOffset.cs +++ b/Neo4j.Driver/Neo4j.Driver/V1/Types/ZonedDateTime.cs @@ -16,6 +16,7 @@ // limitations under the License. using System; +using System.Collections.Generic; using Neo4j.Driver.Internal; using Neo4j.Driver.Internal.Types; @@ -24,44 +25,60 @@ namespace Neo4j.Driver.V1 /// /// Represents a date time value with a time zone, specified as a UTC offset /// - public struct CypherDateTimeWithOffset : IValue, IEquatable, IComparable, - IComparable, IConvertible, IHasDateTimeComponents + public class ZonedDateTime : TemporalValue, IEquatable, IComparable, IComparable, IHasDateTimeComponents { /// - /// Initializes a new instance of from given value. + /// Default comparer for values. + /// + public static readonly IComparer Comparer = new TemporalValueComparer(); + + /// + /// Initializes a new instance of from given value. /// /// - public CypherDateTimeWithOffset(DateTimeOffset dateTimeOffset) + public ZonedDateTime(DateTimeOffset dateTimeOffset) : this(dateTimeOffset.DateTime, dateTimeOffset.Offset) { } /// - /// Initializes a new instance of from given value. + /// Initializes a new instance of from given value. /// /// /// - public CypherDateTimeWithOffset(DateTime dateTime, TimeSpan offset) + public ZonedDateTime(DateTime dateTime, TimeSpan offset) : this(dateTime, (int) offset.TotalSeconds) { } /// - /// Initializes a new instance of from given value. + /// Initializes a new instance of from given value. /// /// /// - public CypherDateTimeWithOffset(DateTime dateTime, int offsetSeconds) + public ZonedDateTime(DateTime dateTime, int offsetSeconds) + : this(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, + TemporalHelpers.ExtractNanosecondFromTicks(dateTime.Ticks), Zone.Of(offsetSeconds)) + { + + } + + /// + /// Initializes a new instance of from given value. + /// + /// + /// + public ZonedDateTime(DateTime dateTime, string zoneId) : this(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, - TemporalHelpers.ExtractNanosecondFromTicks(dateTime.Ticks), offsetSeconds) + TemporalHelpers.ExtractNanosecondFromTicks(dateTime.Ticks), Zone.Of(zoneId)) { } /// - /// Initializes a new instance of from individual date time component values + /// Initializes a new instance of from individual date time component values /// /// /// @@ -69,16 +86,15 @@ public CypherDateTimeWithOffset(DateTime dateTime, int offsetSeconds) /// /// /// - /// - public CypherDateTimeWithOffset(int year, int month, int day, int hour, int minute, int second, - int offsetSeconds) - : this(year, month, day, hour, minute, second, 0, offsetSeconds) + /// + public ZonedDateTime(int year, int month, int day, int hour, int minute, int second, Zone zone) + : this(year, month, day, hour, minute, second, 0, zone) { } /// - /// Initializes a new instance of from individual date time component values + /// Initializes a new instance of from individual date time component values /// /// /// @@ -87,9 +103,9 @@ public CypherDateTimeWithOffset(int year, int month, int day, int hour, int minu /// /// /// - /// - public CypherDateTimeWithOffset(int year, int month, int day, int hour, int minute, int second, int nanosecond, - int offsetSeconds) + /// + public ZonedDateTime(int year, int month, int day, int hour, int minute, int second, int nanosecond, + Zone zone) { Throw.ArgumentOutOfRangeException.IfValueNotBetween(year, TemporalHelpers.MinYear, TemporalHelpers.MaxYear, nameof(year)); @@ -105,8 +121,7 @@ public CypherDateTimeWithOffset(int year, int month, int day, int hour, int minu TemporalHelpers.MaxSecond, nameof(second)); Throw.ArgumentOutOfRangeException.IfValueNotBetween(nanosecond, TemporalHelpers.MinNanosecond, TemporalHelpers.MaxNanosecond, nameof(nanosecond)); - Throw.ArgumentOutOfRangeException.IfValueNotBetween(offsetSeconds, TemporalHelpers.MinOffset, - TemporalHelpers.MaxOffset, nameof(offsetSeconds)); + Throw.ArgumentNullException.IfNull(zone, nameof(zone)); Year = year; Month = month; @@ -115,12 +130,12 @@ public CypherDateTimeWithOffset(int year, int month, int day, int hour, int minu Minute = minute; Second = second; Nanosecond = nanosecond; - OffsetSeconds = offsetSeconds; + Zone = zone; } - internal CypherDateTimeWithOffset(IHasDateTimeComponents dateTime, int offsetSeconds) + internal ZonedDateTime(IHasDateTimeComponents dateTime, Zone zone) : this(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, - dateTime.Nanosecond, offsetSeconds) + dateTime.Nanosecond, zone) { } @@ -161,9 +176,9 @@ internal CypherDateTimeWithOffset(IHasDateTimeComponents dateTime, int offsetSec public int Nanosecond { get; } /// - /// Offset in seconds precision + /// The time zone that this instance represents. /// - public int OffsetSeconds { get; } + public Zone Zone { get; } /// /// Gets a value that represents the date and time of this instance. @@ -182,6 +197,11 @@ public DateTime DateTime } } + /// + /// Returns the offset from UTC of this instance at the time it represents. + /// + public int OffsetSeconds => Zone.OffsetSecondsAt(new DateTime(Year, Month, Day, Hour, Minute, Second)); + /// /// Gets a value that represents the offset of this instance. /// @@ -196,28 +216,30 @@ public DateTime DateTime /// /// Returns a value indicating whether the value of this instance is equal to the - /// value of the specified instance. + /// value of the specified instance. /// /// The object to compare to this instance. /// true if the value parameter equals the value of /// this instance; otherwise, false - public bool Equals(CypherDateTimeWithOffset other) + public bool Equals(ZonedDateTime other) { - return Year == other.Year && Month == other.Month && Day == other.Day && Hour == other.Hour && - Minute == other.Minute && Second == other.Second && Nanosecond == other.Nanosecond && - OffsetSeconds == other.OffsetSeconds; + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return Year == other.Year && Month == other.Month && Day == other.Day && Hour == other.Hour && Second == other.Second && Nanosecond == other.Nanosecond && Equals(Zone, other.Zone); } /// /// Returns a value indicating whether this instance is equal to a specified object. /// /// The object to compare to this instance. - /// true if value is an instance of and + /// true if value is an instance of and /// equals the value of this instance; otherwise, false public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; - return obj is CypherDateTimeWithOffset && Equals((CypherDateTimeWithOffset) obj); + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != this.GetType()) return false; + return Equals((ZonedDateTime) obj); } /// @@ -232,33 +254,34 @@ public override int GetHashCode() hashCode = (hashCode * 397) ^ Month; hashCode = (hashCode * 397) ^ Day; hashCode = (hashCode * 397) ^ Hour; - hashCode = (hashCode * 397) ^ Minute; hashCode = (hashCode * 397) ^ Second; hashCode = (hashCode * 397) ^ Nanosecond; - hashCode = (hashCode * 397) ^ OffsetSeconds; + hashCode = (hashCode * 397) ^ (Zone != null ? Zone.GetHashCode() : 0); return hashCode; } } /// - /// Converts the value of the current object to its equivalent string representation. + /// Converts the value of the current object to its equivalent string representation. /// /// String representation of this Point. public override string ToString() { return - $"{TemporalHelpers.ToIsoDateString(Year, Month, Day)}T{TemporalHelpers.ToIsoTimeString(Hour, Minute, Second, Nanosecond)}{TemporalHelpers.ToIsoTimeZoneOffset(OffsetSeconds)}"; + $"{TemporalHelpers.ToIsoDateString(Year, Month, Day)}T{TemporalHelpers.ToIsoTimeString(Hour, Minute, Second, Nanosecond)}{Zone}"; } /// - /// Compares the value of this instance to a specified value and returns an integer + /// Compares the value of this instance to a specified value and returns an integer /// that indicates whether this instance is earlier than, the same as, or later than the specified /// DateTime value. /// /// The object to compare to the current instance. /// A signed number indicating the relative values of this instance and the value parameter. - public int CompareTo(CypherDateTimeWithOffset other) + public int CompareTo(ZonedDateTime other) { + if (ReferenceEquals(this, other)) return 0; + if (ReferenceEquals(null, other)) return 1; var thisEpochSeconds = this.ToEpochSeconds() - OffsetSeconds; var otherEpochSeconds = other.ToEpochSeconds() - other.OffsetSeconds; var epochComparison = thisEpochSeconds.CompareTo(otherEpochSeconds); @@ -267,170 +290,79 @@ public int CompareTo(CypherDateTimeWithOffset other) } /// - /// Compares the value of this instance to a specified object which is expected to be a + /// Compares the value of this instance to a specified object which is expected to be a /// value, and returns an integer that indicates whether this instance is earlier than, the same as, - /// or later than the specified value. + /// or later than the specified value. /// /// The object to compare to the current instance. /// A signed number indicating the relative values of this instance and the value parameter. public int CompareTo(object obj) { if (ReferenceEquals(null, obj)) return 1; - if (!(obj is CypherDateTimeWithOffset)) - throw new ArgumentException($"Object must be of type {nameof(CypherDateTimeWithOffset)}"); - return CompareTo((CypherDateTimeWithOffset) obj); + if (ReferenceEquals(this, obj)) return 0; + if (!(obj is ZonedDateTime)) + throw new ArgumentException($"Object must be of type {nameof(ZonedDateTime)}"); + return CompareTo((ZonedDateTime) obj); } /// - /// Determines whether one specified is earlier than another specified - /// . + /// Determines whether one specified is earlier than another specified + /// . /// /// The first object to compare. /// The second object to compare. /// - public static bool operator <(CypherDateTimeWithOffset left, CypherDateTimeWithOffset right) + public static bool operator <(ZonedDateTime left, ZonedDateTime right) { return left.CompareTo(right) < 0; } /// - /// Determines whether one specified is later than another specified - /// . + /// Determines whether one specified is later than another specified + /// . /// /// The first object to compare. /// The second object to compare. /// - public static bool operator >(CypherDateTimeWithOffset left, CypherDateTimeWithOffset right) + public static bool operator >(ZonedDateTime left, ZonedDateTime right) { return left.CompareTo(right) > 0; } /// - /// Determines whether one specified represents a duration that is the - /// same as or later than the other specified + /// Determines whether one specified represents a duration that is the + /// same as or later than the other specified /// /// The first object to compare. /// The second object to compare. /// - public static bool operator <=(CypherDateTimeWithOffset left, CypherDateTimeWithOffset right) + public static bool operator <=(ZonedDateTime left, ZonedDateTime right) { return left.CompareTo(right) <= 0; } /// - /// Determines whether one specified represents a duration that is the - /// same as or earlier than the other specified + /// Determines whether one specified represents a duration that is the + /// same as or earlier than the other specified /// /// The first object to compare. /// The second object to compare. /// - public static bool operator >=(CypherDateTimeWithOffset left, CypherDateTimeWithOffset right) + public static bool operator >=(ZonedDateTime left, ZonedDateTime right) { return left.CompareTo(right) >= 0; } - #region IConvertible Implementation - - TypeCode IConvertible.GetTypeCode() - { - return TypeCode.Object; - } - - bool IConvertible.ToBoolean(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to boolean is not supported."); - } - - char IConvertible.ToChar(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to char is not supported."); - } - - sbyte IConvertible.ToSByte(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to sbyte is not supported."); - } - - byte IConvertible.ToByte(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to byte is not supported."); - } - - short IConvertible.ToInt16(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to short is not supported."); - } - - ushort IConvertible.ToUInt16(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned short is not supported."); - } - - int IConvertible.ToInt32(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to int is not supported."); - } - - uint IConvertible.ToUInt32(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned int is not supported."); - } - - long IConvertible.ToInt64(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to long is not supported."); - } - - ulong IConvertible.ToUInt64(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to unsigned long is not supported."); - } - - float IConvertible.ToSingle(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to single is not supported."); - } - - double IConvertible.ToDouble(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to double is not supported."); - } - - decimal IConvertible.ToDecimal(IFormatProvider provider) - { - throw new InvalidCastException($"Conversion of {GetType().Name} to decimal is not supported."); - } - - DateTime IConvertible.ToDateTime(IFormatProvider provider) + /// + protected override DateTime ToDateTime() { return DateTimeOffset.DateTime; } - string IConvertible.ToString(IFormatProvider provider) + /// + protected override DateTimeOffset ToDateTimeOffset() { - return ToString(); - } - - object IConvertible.ToType(Type conversionType, IFormatProvider provider) - { - if (conversionType == typeof(DateTime)) - { - return DateTimeOffset.DateTime; - } - - if (conversionType == typeof(string)) - { - return ToString(); - } - - if (conversionType == typeof(DateTimeOffset)) - { - return DateTimeOffset; - } - - throw new InvalidCastException($"Conversion of {GetType().Name} to {conversionType.Name} is not supported."); + return DateTimeOffset; } - - #endregion } } \ No newline at end of file