diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/ZonedTimeSchemaKey.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/ZonedTimeSchemaKey.java index 33e3bd11b0890..0c8465b648208 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/ZonedTimeSchemaKey.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/ZonedTimeSchemaKey.java @@ -24,9 +24,9 @@ import org.neo4j.kernel.impl.store.TimeZones; import org.neo4j.values.storable.TimeValue; import org.neo4j.values.storable.Value; -import org.neo4j.values.storable.Values; import static java.lang.String.format; +import static org.neo4j.values.storable.Values.NO_VALUE; /** * Includes value and entity id (to be able to handle non-unique values). A value can be any {@link TimeValue}. @@ -46,7 +46,12 @@ class ZonedTimeSchemaKey extends NativeSchemaKey @Override public Value asValue() { - return TimeValue.time( nanosOfDayUTC, ZoneOffset.ofTotalSeconds( zoneOffsetSeconds ) ); + // We need to check validity upfront without throwing exceptions, because the PageCursor might give garbage bytes + if ( TimeZones.validZoneOffset( zoneOffsetSeconds ) ) + { + return TimeValue.time( nanosOfDayUTC, ZoneOffset.ofTotalSeconds( zoneOffsetSeconds ) ); + } + return NO_VALUE; } @Override @@ -67,9 +72,9 @@ public void initValueAsHighest() public int compareValueTo( ZonedTimeSchemaKey other ) { int compare = Long.compare( nanosOfDayUTC, other.nanosOfDayUTC ); - if ( compare == 0 && differentValidZoneOffset( other ) ) + if ( compare == 0 ) { - compare = Values.COMPARATOR.compare( asValue(), other.asValue() ); + compare = Integer.compare( zoneOffsetSeconds, other.zoneOffsetSeconds ); } return compare; } @@ -98,11 +103,4 @@ protected Value assertCorrectType( Value value ) } return value; } - - // We need to check validity upfront without throwing exceptions, because the PageCursor might give garbage bytes - private boolean differentValidZoneOffset( ZonedTimeSchemaKey other ) - { - return zoneOffsetSeconds != other.zoneOffsetSeconds && - TimeZones.validZoneOffset( zoneOffsetSeconds ) && TimeZones.validZoneOffset( other.zoneOffsetSeconds ); - } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/api/index/IndexProviderCompatibilityTestSuite.java b/community/kernel/src/test/java/org/neo4j/kernel/api/index/IndexProviderCompatibilityTestSuite.java index 8b4944b9cd633..f6f9ba7676b75 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/api/index/IndexProviderCompatibilityTestSuite.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/api/index/IndexProviderCompatibilityTestSuite.java @@ -116,6 +116,8 @@ public Compatibility( IndexProviderCompatibilityTestSuite testSuite, SchemaIndex DateTimeValue.datetime( 2014, 3, 25, 12, 46, 13, 7474, "+05:00" ), DateTimeValue.datetime( 2014, 3, 25, 12, 45, 14, 7474, "+05:00" ), DateTimeValue.datetime( 2014, 3, 25, 12, 45, 14, 7475, "+05:00" ), + DateTimeValue.datetime( 10000, 100, ZoneOffset.ofTotalSeconds( 3 ) ), + DateTimeValue.datetime( 10000, 101, ZoneOffset.ofTotalSeconds( -3 ) ), DurationValue.duration( 10, 20, 30, 40 ), DurationValue.duration( 11, 20, 30, 40 ), DurationValue.duration( 10, 21, 30, 40 ), @@ -141,7 +143,7 @@ public Compatibility( IndexProviderCompatibilityTestSuite testSuite, SchemaIndex pageCacheAndDependenciesRule = new PageCacheAndDependenciesRule( DefaultFileSystemRule::new, testSuite.getClass() ); } - protected void withPopulator( IndexPopulator populator, ThrowingConsumer runWithPopulator ) throws Exception + void withPopulator( IndexPopulator populator, ThrowingConsumer runWithPopulator ) throws Exception { try { diff --git a/community/values/src/test/java/org/neo4j/values/storable/TimeValueTest.java b/community/values/src/test/java/org/neo4j/values/storable/TimeValueTest.java index 4ffb9647d1b5f..f3459503093b5 100644 --- a/community/values/src/test/java/org/neo4j/values/storable/TimeValueTest.java +++ b/community/values/src/test/java/org/neo4j/values/storable/TimeValueTest.java @@ -170,15 +170,15 @@ public void shouldEqualItself() } @Test - public void shouldNotEqualSameTimeButDifferentTimezone() + public void shouldNotEqualSameInstantButDifferentTimezone() { - assertNotEqual( time( 10, 52, 5, 6, UTC ), time( 10, 52, 5, 6, "+01:00" ) ); + assertNotEqual( time( 10000, UTC ), time( 10000, ZoneOffset.of( "+01:00" ) ) ); } @Test - public void shouldEqualSamePointInTimeInDifferentTimezone() + public void shouldNotEqualSameInstantInSameLocalTimeButDifferentTimezone() { - assertEqual( time( 10, 52, 5, 6, UTC ), time( 11, 52, 5, 6, "+01:00" ) ); + assertNotEqual( time( 10, 52, 5, 6, UTC ), time( 11, 52, 5, 6, "+01:00" ) ); } @SuppressWarnings( "UnusedReturnValue" )