private static DateTimeValue readDateTime( ByteBuffer bb, int offset ) { final long epocSeconds = bb.getLong( offset ); offset += Long.BYTES; final int nanos = bb.getInt( offset ); offset += Integer.BYTES; final int z = bb.getInt( offset ); return DateTimeValue.datetime( epocSeconds, nanos, toZoneId( z ) ); }
@Test public void shouldHandleDateTimeWithZoneOffset() { // Given DateTimeValue dvalue = DateTimeValue.datetime( 1, 2, 3, 4, 5, 6, 7, "+00:00" ); // When dvalue.writeTo( converter ); // Then Object value = converter.value(); assertThat( value, instanceOf( ZonedDateTime.class ) ); assertThat( value, equalTo( dvalue.asObjectCopy() ) ); }
public static DateTimeValue datetime( int year, int month, int day, int hour, int minute, int second, int nanoOfSecond, String zone ) { return datetime( year, month, day, hour, minute, second, nanoOfSecond, parseZoneName( zone ) ); }
public static DateTimeValue datetime( long epochSecond, long nano, ZoneOffset zoneOffset ) { return new DateTimeValue( datetimeRaw( epochSecond, nano, zoneOffset ) ); }
@Override public void writeDateTime( ZonedDateTime zonedDateTime ) throws RuntimeException { builder.append( DateTimeValue.datetime( zonedDateTime ).prettyPrint() ); builder.append( '|' ); }
@Test public void testDateTimeTypeWithZoneId() { DateTimeValue dateTime = DateTimeValue.datetime( 1991, 1, 1, 0, 0, 13, 37, ZoneId.of( "Europe/Stockholm" ) ); String key = "dt"; node1.setProperty( key, dateTime ); newTransaction(); Object property = node1.getProperty( key ); assertEquals( dateTime.asObjectCopy(), property ); }
Supplier<ZoneId> defaultZone ) Pair<LocalDate,LocalTime> pair = getTruncatedDateAndTime( unit, input, "date time" ); return datetime( truncatedZDT ); if ( timezone != NO_VALUE ) truncatedZDT = truncatedZDT.withZoneSameLocal( timezoneOf( timezone ) ); return updateFieldMapWithConflictingSubseconds( fields, unit, truncatedZDT, ( mapValue, zonedDateTime ) -> { return datetime( zonedDateTime ); return build( mapValue.updatedWith( "datetime", datetime( zonedDateTime ) ), defaultZone );
@Test void shouldHandleDateTimeWithTimeZoneId() { DateTimeValue datetime = datetime( 2045, 2, 7, 12, 00, 40, 999888999, "Europe/London" ); PrettyPrinter printer = new PrettyPrinter(); datetime.writeTo( printer ); assertEquals( "{datetime: \"2045-02-07T12:00:40.999888999Z[Europe/London]\"}", printer.value() ); }
@Test public void shouldAddDurationToDateTimes() { assertEquals( datetime( date( 2018, 2, 1 ), time( 1, 17, 3, 0, UTC ) ), datetime( date( 2018, 1, 1 ), time( 1, 2, 3, 0, UTC ) ).add( DurationValue.duration( 1, 0, 900, 0 ) ) ); assertEquals( datetime( date( 2018, 2, 28 ), time( 0, 0, 0, 0, UTC ) ), datetime( date( 2018, 1, 31 ), time( 0, 0, 0, 0, UTC ) ).add( DurationValue.duration( 1, 0, 0, 0 ) ) ); assertEquals( datetime( date( 2018, 1, 28 ), time( 0, 0, 0, 0, UTC ) ), datetime( date( 2018, 2, 28 ), time( 0, 0, 0, 0, UTC ) ).add( DurationValue.duration( -1, 0, 0, 0 ) ) ); }
@Test @FrozenClockRule.TimeZone( "Europe/Stockholm" ) public void shouldAcquireCurrentDateTime() { assertEqualTemporal( datetime( ZonedDateTime.now( clock ) ), DateTimeValue.now( clock ) ); assertEqualTemporal( // Using the named UTC timezone datetime( ZonedDateTime.now( clock.withZone( "UTC" ) ) ), DateTimeValue.now( clock, "UTC" ) ); assertEqualTemporal( // Using the timezone defined as 0 hours offset from UTC datetime( ZonedDateTime.now( clock.withZone( UTC ) ) ), DateTimeValue.now( clock, "Z" ) ); }
@Test @FrozenClockRule.TimeZone( {"Europe/Stockholm", "America/Los_Angeles"} ) public void shouldCopyDateTime() { assertEqualTemporal( datetime( ZonedDateTime.now( clock ) ), builder( clock ).add( "datetime", datetime( ZonedDateTime.now( clock ) ) ).build() ); assertEqualTemporal( datetime( ZonedDateTime.now( clock ) ), builder( clock ) .add( "datetime", localDateTime( LocalDateTime.now( clock ) ) ) .build() ); assertEqualTemporal( datetime( ZonedDateTime.now( clock ).withZoneSameLocal( ZoneId.of( "America/New_York" ) ) ), builder( clock ) .add( "datetime", localDateTime( LocalDateTime.now( clock ) ) ) .add( "timezone", stringValue( "America/New_York" ) ) .build() ); }
@Override protected DateTimeValue parse( TextValue value, Supplier<ZoneId> defaultZone ) { return DateTimeValue.parse( value, defaultZone ); }
@Test public void shouldSubtractDurationFromDateTimes() { assertEquals( datetime( date( 2018, 1, 1 ), time( 1, 2, 3, 0, UTC ) ), datetime( date( 2018, 2, 1 ), time( 1, 17, 3, 0, UTC ) ).sub( DurationValue.duration( 1, 0, 900, 0 ) ) ); assertEquals( datetime( date( 2018, 1, 28 ), time( 0, 0, 0, 0, UTC ) ), datetime( date( 2018, 2, 28 ), time( 0, 0, 0, 0, UTC ) ).sub( DurationValue.duration( 1, 0, 0, 0 ) ) ); assertEquals( datetime( date( 2018, 2, 28 ), time( 0, 0, 0, 0, UTC ) ), datetime( date( 2018, 1, 31 ), time( 0, 0, 0, 0, UTC ) ).sub( DurationValue.duration( -1, 0, 0, 0 ) ) ); }
public static ZonedDateTime datetimeRaw( long epochSecond, long nano, ZoneOffset zoneOffset ) { return datetimeRaw( epochSecond, nano, (ZoneId) zoneOffset ); }
public static DateTimeValue now( Clock clock, String timezone ) { return now( clock.withZone( parseZoneName( timezone ) ) ); }
parse( "2018-01-10T10:35:57", clock::getZone ), fromValues( builder( clock ) ) .add( "year", 2018 ) .add( "month", 1 ) .build() ); assertEqualTemporal( parse( "2018-01-10T10:35:57.999999999", clock::getZone ), fromValues( builder( clock ) ) .add( "year", 2018 ) .add( "month", 1 ) .build() ); assertEqualTemporal( parse( "2018-01-10T10:35:57.999999", clock::getZone ), fromValues( builder( clock ) ) .add( "year", 2018 ) .add( "month", 1 ) .build() ); assertEqualTemporal( parse( "2018-01-10T10:35:57.999", clock::getZone ), fromValues( builder( clock ) ) .add( "year", 2018 ) .add( "month", 1 ) .build() ); assertEqualTemporal( parse( "2018-01-10T10:35:57.001999999", clock::getZone ),
@Override public ZonedDateTime mapDateTime( DateTimeValue value ) { return value.asObjectCopy(); }
@Override protected DateTimeValue build( MapValue map, Supplier<ZoneId> defaultZone ) { return DateTimeValue.build( map, defaultZone ); }