@SuppressWarnings( "unchecked" ) @Override public <R extends Temporal> R adjustInto( R temporal, long newValue ) { int newVal = range.checkValidIntValue( newValue, this ); int oldYear = temporal.get( ChronoField.YEAR ); return (R) temporal.with( ChronoField.YEAR, (oldYear / years) * years + newVal ) .with( TemporalAdjusters.firstDayOfYear() ); }
@Override ZoneId getZoneId() { throw new UnsupportedTemporalTypeException( "Cannot get the timezone of" + this ); }
Neo4JTemporalField( String name, TemporalUnit baseUnit, TemporalUnit rangeUnit, int years ) { this.name = name; this.baseUnit = baseUnit; this.rangeUnit = rangeUnit; this.years = years; this.range = ValueRange.of( Year.MIN_VALUE / years, Year.MAX_VALUE / years ); }
/** * Convenience method to measure elapsed time between start of query execution and completion or exception as appropriate. Do not call with a null argument or before a query has executed/exploded. * @param unit the time unit to convert to * @return the elapsed time in the given unit */ public long getElapsedTime(ChronoUnit unit) { return unit.between(executionMoment, completionMoment == null ? exceptionMoment : completionMoment); }
@Override @SuppressWarnings( "unchecked" ) public final V plus( long amountToAdd, TemporalUnit unit ) { return replacement( (T) temporal().plus( amountToAdd, unit ) ); }
@Override @SuppressWarnings( "unchecked" ) public final V with( TemporalAdjuster adjuster ) { return replacement( (T) temporal().with( adjuster ) ); }
@Override public final int get( TemporalField field ) { int accessor; try { accessor = temporal().get( field ); } catch ( UnsupportedTemporalTypeException e ) { throw new UnsupportedTemporalUnitException( e.getMessage(), e ); } return accessor; }
@Override @SuppressWarnings( "unchecked" ) public final V minus( long amountToSubtract, TemporalUnit unit ) { return replacement( (T) temporal().minus( amountToSubtract, unit ) ); }
@Override public final boolean isSupported( TemporalField field ) { return temporal().isSupported( field ); }
@Override public <R> R query( TemporalQuery<R> query ) { return temporal().query( query ); }
/** * Returns absolute value of the difference according to time unit. * * @param temporal1 the first {@link Temporal} * @param temporal2 the second {@link Temporal} * @return absolute value of the difference according to time unit. */ protected long getDifference(Temporal temporal1, Temporal temporal2) { return abs(unit.between(temporal1, temporal2)); }
@Override public final ValueRange range( TemporalField field ) { return temporal().range( field ); }
@Override public final long getLong( TemporalField field ) { return temporal().getLong( field ); }
private boolean validateIfModifiedSince(Instant lastModified) { if (lastModified.isBefore(Instant.EPOCH)) { return false; } long ifModifiedSince = getRequestHeaders().getIfModifiedSince(); if (ifModifiedSince == -1) { return false; } // We will perform this validation... this.notModified = ChronoUnit.SECONDS.between(lastModified, Instant.ofEpochMilli(ifModifiedSince)) >= 0; return true; }
@Override @SuppressWarnings( "unchecked" ) public final V plus( TemporalAmount amount ) { return replacement( (T) temporal().plus( amount ) ); }
@Override @SuppressWarnings( "unchecked" ) public final V with( TemporalField field, long newValue ) { return replacement( (T) temporal().with( field, newValue ) ); }
@Override @SuppressWarnings( "unchecked" ) public final V minus( TemporalAmount amount ) { return replacement( (T) temporal().minus( amount ) ); }
@Override public final boolean isSupported( TemporalUnit unit ) { return temporal().isSupported( unit ); }
private static long toDays(int year, int month, int day) { return DAYS.between(LocalDate.of(1970, 1, 1), LocalDate.of(year, month, day)); }