Skip to content

Commit

Permalink
cleanups around TimeValue
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd authored and Lojjs committed Mar 16, 2018
1 parent 63420c1 commit a82142b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Expand Up @@ -24,9 +24,9 @@
import org.neo4j.kernel.impl.store.TimeZones; import org.neo4j.kernel.impl.store.TimeZones;
import org.neo4j.values.storable.TimeValue; import org.neo4j.values.storable.TimeValue;
import org.neo4j.values.storable.Value; import org.neo4j.values.storable.Value;
import org.neo4j.values.storable.Values;


import static java.lang.String.format; 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}. * Includes value and entity id (to be able to handle non-unique values). A value can be any {@link TimeValue}.
Expand All @@ -46,7 +46,12 @@ class ZonedTimeSchemaKey extends NativeSchemaKey<ZonedTimeSchemaKey>
@Override @Override
public Value asValue() 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 @Override
Expand All @@ -67,9 +72,9 @@ public void initValueAsHighest()
public int compareValueTo( ZonedTimeSchemaKey other ) public int compareValueTo( ZonedTimeSchemaKey other )
{ {
int compare = Long.compare( nanosOfDayUTC, other.nanosOfDayUTC ); 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; return compare;
} }
Expand Down Expand Up @@ -98,11 +103,4 @@ protected Value assertCorrectType( Value value )
} }
return 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 );
}
} }
Expand Up @@ -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, 46, 13, 7474, "+05:00" ),
DateTimeValue.datetime( 2014, 3, 25, 12, 45, 14, 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( 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( 10, 20, 30, 40 ),
DurationValue.duration( 11, 20, 30, 40 ), DurationValue.duration( 11, 20, 30, 40 ),
DurationValue.duration( 10, 21, 30, 40 ), DurationValue.duration( 10, 21, 30, 40 ),
Expand All @@ -141,7 +143,7 @@ public Compatibility( IndexProviderCompatibilityTestSuite testSuite, SchemaIndex
pageCacheAndDependenciesRule = new PageCacheAndDependenciesRule( DefaultFileSystemRule::new, testSuite.getClass() ); pageCacheAndDependenciesRule = new PageCacheAndDependenciesRule( DefaultFileSystemRule::new, testSuite.getClass() );
} }


protected void withPopulator( IndexPopulator populator, ThrowingConsumer<IndexPopulator,Exception> runWithPopulator ) throws Exception void withPopulator( IndexPopulator populator, ThrowingConsumer<IndexPopulator,Exception> runWithPopulator ) throws Exception
{ {
try try
{ {
Expand Down
Expand Up @@ -170,15 +170,15 @@ public void shouldEqualItself()
} }


@Test @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 @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" ) @SuppressWarnings( "UnusedReturnValue" )
Expand Down

0 comments on commit a82142b

Please sign in to comment.