/** * @see RandomValues */ public TimeValue nextTimeValue() { return time( nextTimeRaw() ); }
@Test public void testTimeArray() { String key = "testarray"; // array sizes 1 through 4 for ( OffsetTime[] array : new OffsetTime[][]{new OffsetTime[]{TimeValue.time( 23, 11, 8, 0, "+17:59" ).asObjectCopy()}, new OffsetTime[]{TimeValue.time( 23, 11, 8, 0, "+17:59" ).asObjectCopy(), TimeValue.time( 14, 34, 55, 3478, "+02:00" ).asObjectCopy()}, new OffsetTime[]{TimeValue.time( 23, 11, 8, 0, "+17:59" ).asObjectCopy(), TimeValue.time( 14, 34, 55, 3478, "+02:00" ).asObjectCopy(), TimeValue.time( 0, 17, 20, 783478, "-03:00" ).asObjectCopy()}, new OffsetTime[]{TimeValue.time( 23, 11, 8, 0, "+17:59" ).asObjectCopy(), TimeValue.time( 14, 34, 55, 3478, "+02:00" ).asObjectCopy(), TimeValue.time( 0, 17, 20, 783478, "-03:00" ).asObjectCopy(), TimeValue.time( 1, 1, 1, 1, "-01:00" ).asObjectCopy()}} ) { node1.setProperty( key, array ); newTransaction(); OffsetTime[] propertyValue = (OffsetTime[]) 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 ) ); }
@Test void shouldParseTimeWithHourMinuteSecondAndFractions() { assertEquals( time( 14, 5, 17, 123000000, UTC ), parse( "140517.123", inUTC ) ); assertEquals( time( 14, 5, 17, 1, UTC ), parse( "14:5:17.000000001", inUTC ) ); assertEquals( time( 4, 15, 4, 0, UTC ), parse( "4:15:4.000", inUTC ) ); assertEquals( time( 9, 7, 19, 999999999, UTC ), parse( "9:7:19.999999999", inUTC ) ); assertEquals( time( 3, 4, 1, 123456789, UTC ), parse( "03:04:01.123456789", inUTC ) ); }
public static TimeValue time( int hour, int minute, int second, int nanosOfSecond, String offset ) { return time( hour, minute, second, nanosOfSecond, parseOffset( offset ) ); }
@Override public void writeTime( OffsetTime offsetTime ) throws RuntimeException { builder.append( TimeValue.time( offsetTime ).prettyPrint() ); builder.append( '|' ); }
@Test public void shouldHandleTimeWithOffset() { // Given TimeValue time = TimeValue.time( 1, 2, 3, 4, "+01:00" ); // When time.writeTo( converter ); // Then Object value = converter.value(); assertThat( value, instanceOf( OffsetTime.class ) ); assertThat( value, equalTo( time.asObjectCopy() ) ); }
OffsetTime truncatedOT = assertValidUnit( () -> time.truncatedTo( unit ) ); if ( fields.size() == 0 ) return time( truncatedOT ); assertValidArgument( () -> ZonedDateTime.ofInstant( Instant.now(), timezoneOf( timezone ) ) ); ZoneOffset currentOffset = currentDT.getOffset(); truncatedOT = truncatedOT.withOffsetSameLocal( currentOffset ); return updateFieldMapWithConflictingSubseconds( fields, unit, truncatedOT, ( mapValue, offsetTime ) -> { if ( mapValue.size() == 0 ) return time( offsetTime ); return build( mapValue.updatedWith( "time", time( offsetTime ) ), defaultZone );
@Test void shouldCompareDerivedValue() { TimeValue value1 = time( 4242, ZoneOffset.of( "-12:00" ) ); TimeValue value2 = time( value1.temporal() ); assertEquals( 0, value1.unsafeCompareTo( value2 ) ); }
@Test void shouldWriteTime() { // given for ( TimeValue time : new TimeValue[] { time( 11, 30, 4, 112233440, ofHours( 3 ) ), time( 23, 59, 59, 999999999, ofHours( 18 ) ), time( 23, 59, 59, 999999999, ofHours( -18 ) ), time( 0, 0, 0, 0, ofHours( -18 ) ), time( 0, 0, 0, 0, ofHours( 18 ) ), } ) { List<TimeValue> values = new ArrayList<>( 1 ); ValueWriter<RuntimeException> writer = new ThrowingValueWriter.AssertOnly() { @Override public void writeTime( OffsetTime offsetTime ) { values.add( time( offsetTime ) ); } }; // when time.writeTo( writer ); // then assertEquals( singletonList( time ), values ); } }
result = defaultTime( timezone ); selectingTimeZone = false; return time( result );
public static TimeValue parse( CharSequence text, Supplier<ZoneId> defaultZone ) { return parse( TimeValue.class, PATTERN, TimeValue::parse, text, defaultZone ); }
@Test void shouldReuseInstanceInArithmetics() { final TimeValue noon = time( 12, 0, 0, 0, UTC ); assertSame( noon, noon.add( DurationValue.duration( 0, 0, 0, 0 ) ) ); assertSame( noon, noon.add( DurationValue.duration( 1, 1, 0, 0 ) ) ); assertSame( noon, noon.add( DurationValue.duration( -1, 1, 0, -0 ) ) ); }
static OffsetTime asValueRaw( long long0, long long1 ) { if ( TimeZones.validZoneOffset( (int) long1 ) ) { return TimeValue.timeRaw( long0, ZoneOffset.ofTotalSeconds( (int) long1 ) ); } // TODO Getting here means that after a proper read this value is plain wrong... shouldn't something be thrown instead? Yes and same for TimeZones return null; }
@Test void shouldBeAbleToParseTimeThatOverridesHeaderInformation() { String headerInformation = "{timezone:-01:00}"; String data = "14:05:17Z"; TimeValue expected = TimeValue.parse( data, orFail ); TimeValue actual = TimeValue.parse( data, orFail, TemporalValue.parseHeaderInformation( headerInformation ) ); assertEqual( expected, actual ); assertEquals( UTC, actual.getZoneOffset() ); }
@Override public OffsetTime mapTime( TimeValue value ) { return value.asObjectCopy(); }
public static DateTimeValue datetime( DateValue date, TimeValue time ) { OffsetTime t = time.temporal(); return new DateTimeValue( ZonedDateTime.of( date.temporal(), t.toLocalTime(), t.getOffset() ) ); }
@Override protected TimeValue build( MapValue map, Supplier<ZoneId> defaultZone ) { return TimeValue.build( map, defaultZone ); }