@Override public Value decodeForTemporal( long[] valueBlocks, int offset ) { long nanoOfSecond = valueBlocks[offset] >>> 32; checkValidNanoOfSecond( nanoOfSecond ); long epochSecond = valueBlocks[1 + offset]; return LocalDateTimeValue.localDateTime( epochSecond, nanoOfSecond ); }
@Override public LocalDateTime mapLocalDateTime( LocalDateTimeValue value ) { return value.asObjectCopy(); }
@Override protected LocalDateTimeValue parse( TextValue value, Supplier<ZoneId> defaultZone ) { return LocalDateTimeValue.parse( value ); }
public static LocalDateTimeValue localDateTime( long epochSecond, long nano ) { return new LocalDateTimeValue( localDateTimeRaw( epochSecond, nano ) ); }
@Override public void writeLocalDateTime( LocalDateTime localDateTime ) throws RuntimeException { builder.append( LocalDateTimeValue.localDateTime( localDateTime ).prettyPrint() ); builder.append( '|' ); }
private static LocalDateTimeValue parse( Matcher matcher ) { return localDateTime( LocalDateTime.of( parseDate( matcher ), optTime( matcher ) ) ); }
@Test public void testLocalDateTimeType() { LocalDateTime dateTime = LocalDateTimeValue.localDateTime( 1991, 1, 1, 0, 0, 13, 37 ).asObjectCopy(); String key = "dt"; node1.setProperty( key, dateTime ); newTransaction(); Object property = node1.getProperty( key ); assertEquals( dateTime, property ); }
@Test public void shouldHandleLocalDateTime() { // Given LocalDateTimeValue dvalue = LocalDateTimeValue.localDateTime( 1, 2, 3, 4, 5, 6, 7 ); // When dvalue.writeTo( converter ); // Then Object value = converter.value(); assertThat( value, instanceOf( LocalDateTime.class ) ); assertThat( value, equalTo( dvalue.asObjectCopy() ) ); }
public static LocalDateTimeValue truncate( TemporalUnit unit, TemporalValue input, MapValue fields, Supplier<ZoneId> defaultZone ) { Pair<LocalDate,LocalTime> pair = getTruncatedDateAndTime( unit, input, "local date time" ); LocalDate truncatedDate = pair.first(); LocalTime truncatedTime = pair.other(); LocalDateTime truncatedLDT = LocalDateTime.of( truncatedDate, truncatedTime ); if ( fields.size() == 0 ) { return localDateTime( truncatedLDT ); } else { return updateFieldMapWithConflictingSubseconds( fields, unit, truncatedLDT, ( mapValue, localDateTime ) -> { if ( mapValue.size() == 0 ) { return localDateTime( localDateTime ); } else { return build( mapValue.updatedWith( "datetime", localDateTime( localDateTime ) ), defaultZone ); } } ); } }
@Test void shouldParseDate() { assertEquals( localDateTime( date( 2017, 12, 17 ), localTime( 17, 14, 35, 123456789 ) ), parse( "2017-12-17T17:14:35.123456789" ) ); }
@Test void shouldHandleLocalDateTime() { LocalDateTimeValue localDateTime = localDateTime( 2015, 8, 8, 8, 40, 29, 999888111 ); PrettyPrinter printer = new PrettyPrinter(); localDateTime.writeTo( printer ); assertEquals( "{localDateTime: \"2015-08-08T08:40:29.999888111\"}", printer.value() ); }
static LocalDateTime asValueRaw( long long0, long long1 ) { return LocalDateTimeValue.localDateTimeRaw( long1, long0 ); }
@Override protected LocalDateTimeValue build( MapValue map, Supplier<ZoneId> defaultZone ) { return LocalDateTimeValue.build( map, defaultZone ); }
@Test public void testLocalDateTimeArray() { LocalDateTime[] array = new LocalDateTime[]{LocalDateTimeValue.localDateTime( 1991, 1, 1, 0, 0, 13, 37 ).asObjectCopy(), LocalDateTimeValue.localDateTime( 1992, 2, 28, 1, 15, 0, 4000 ).asObjectCopy()}; String key = "testarray"; node1.setProperty( key, array ); newTransaction(); LocalDateTime[] propertyValue = (LocalDateTime[]) node1.getProperty( key ); assertEquals( array.length, propertyValue.length ); for ( int i = 0; i < array.length; i++ ) { assertEquals( array[i], propertyValue[i] ); } node1.removeProperty( key ); newTransaction(); assertTrue( !node1.hasProperty( key ) ); }
public static LocalDateTimeValue truncate( TemporalUnit unit, TemporalValue input, MapValue fields, Supplier<ZoneId> defaultZone ) { Pair<LocalDate,LocalTime> pair = getTruncatedDateAndTime( unit, input, "local date time" ); LocalDate truncatedDate = pair.first(); LocalTime truncatedTime = pair.other(); LocalDateTime truncatedLDT = LocalDateTime.of( truncatedDate, truncatedTime ); if ( fields.size() == 0 ) { return localDateTime( truncatedLDT ); } else { return updateFieldMapWithConflictingSubseconds( fields, unit, truncatedLDT, ( mapValue, localDateTime ) -> { if ( mapValue.size() == 0 ) { return localDateTime( localDateTime ); } else { return build( mapValue.updatedWith( "datetime", localDateTime( localDateTime ) ), defaultZone ); } } ); } }
@Test void shouldWriteDateTime() { // given for ( LocalDateTimeValue value : new LocalDateTimeValue[] { localDateTime( date( 2017, 3, 26 ), localTime( 1, 0, 0, 0 ) ), localDateTime( date( 2017, 3, 26 ), localTime( 2, 0, 0, 0 ) ), localDateTime( date( 2017, 3, 26 ), localTime( 3, 0, 0, 0 ) ), localDateTime( date( 2017, 10, 29 ), localTime( 2, 0, 0, 0 ) ), localDateTime( date( 2017, 10, 29 ), localTime( 3, 0, 0, 0 ) ), localDateTime( date( 2017, 10, 29 ), localTime( 4, 0, 0, 0 ) ), } ) { List<LocalDateTimeValue> values = new ArrayList<>( 1 ); ValueWriter<RuntimeException> writer = new ThrowingValueWriter.AssertOnly() { @Override public void writeLocalDateTime( LocalDateTime localDateTime ) { values.add( localDateTime( localDateTime ) ); } }; // when value.writeTo( writer ); // then assertEquals( singletonList( value ), values ); } }
@Override public void writeLocalDateTime( LocalDateTime localDateTime ) throws RuntimeException { builder.append( LocalDateTimeValue.localDateTime( localDateTime ).prettyPrint() ); builder.append( '|' ); }
private static LocalDateTimeValue parse( Matcher matcher ) { return localDateTime( LocalDateTime.of( parseDate( matcher ), optTime( matcher ) ) ); }
public static LocalDateTimeValue now( Clock clock, Supplier<ZoneId> defaultZone ) { return now( clock.withZone( defaultZone.get() ) ); }