public long add(long instant, int value) { if (iTimeField) { int offset = getOffsetToAdd(instant); long localInstant = iField.add(instant + offset, value); return localInstant - offset; } else { long localInstant = iZone.convertUTCToLocal(instant); localInstant = iField.add(localInstant, value); return iZone.convertLocalToUTC(localInstant, false, instant); } }
/** * Adds to this field in a copy of this LocalDate. * <p> * The LocalDate attached to this property is unchanged by this call. * * @param value the value to add to the field in the copy * @return a copy of the LocalDate with the field value changed * @throws IllegalArgumentException if the value isn't valid */ public LocalDate addToCopy(int value) { return iInstant.withLocalMillis(iField.add(iInstant.getLocalMillis(), value)); }
/** * Adds to this field in a copy of this LocalDateTime. * <p> * The LocalDateTime attached to this property is unchanged by this call. * * @param value the value to add to the field in the copy * @return a copy of the LocalDateTime with the field value changed * @throws IllegalArgumentException if the value isn't valid */ public LocalDateTime addToCopy(int value) { return iInstant.withLocalMillis(iField.add(iInstant.getLocalMillis(), value)); }
/** * Adds to this field in a copy of this LocalTime. * <p> * The LocalTime attached to this property is unchanged by this call. * * @param value the value to add to the field in the copy * @return a copy of the LocalTime with the field value changed */ public LocalTime addCopy(int value) { return iInstant.withLocalMillis(iField.add(iInstant.getLocalMillis(), value)); }
@ScalarOperator(ADD) @SqlType(StandardTypes.DATE) public static long intervalYearToMonthPlusDate(@SqlType(StandardTypes.INTERVAL_YEAR_TO_MONTH) long left, @SqlType(StandardTypes.DATE) long right) { long millis = MONTH_OF_YEAR_UTC.add(TimeUnit.DAYS.toMillis(right), left); return TimeUnit.MILLISECONDS.toDays(millis); }
@ScalarOperator(ADD) @SqlType(StandardTypes.DATE) public static long datePlusIntervalYearToMonth(@SqlType(StandardTypes.DATE) long left, @SqlType(StandardTypes.INTERVAL_YEAR_TO_MONTH) long right) { long millis = MONTH_OF_YEAR_UTC.add(TimeUnit.DAYS.toMillis(left), right); return TimeUnit.MILLISECONDS.toDays(millis); }
@ScalarOperator(SUBTRACT) @SqlType(StandardTypes.DATE) public static long dateMinusIntervalYearToMonth(ConnectorSession session, @SqlType(StandardTypes.DATE) long left, @SqlType(StandardTypes.INTERVAL_YEAR_TO_MONTH) long right) { long millis = MONTH_OF_YEAR_UTC.add(TimeUnit.DAYS.toMillis(left), -right); return TimeUnit.MILLISECONDS.toDays(millis); }
private long setDayOfMonth(Chronology chrono, long instant) { if (iDayOfMonth >= 0) { instant = chrono.dayOfMonth().set(instant, iDayOfMonth); } else { instant = chrono.dayOfMonth().set(instant, 1); instant = chrono.monthOfYear().add(instant, 1); instant = chrono.dayOfMonth().add(instant, iDayOfMonth); } return instant; }
public long add(long instant, int amount) { checkLimits(instant, null); long result = getWrappedField().add(instant, amount); checkLimits(result, "resulting"); return result; }
public long add(long instant, long amount) { checkLimits(instant, null); long result = getWrappedField().add(instant, amount); checkLimits(result, "resulting"); return result; }
@Description("add the specified amount of date to the given date") @LiteralParameters("x") @ScalarFunction("date_add") @SqlType(StandardTypes.DATE) public static long addFieldValueDate(ConnectorSession session, @SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.DATE) long date) { long millis = getDateField(UTC_CHRONOLOGY, unit).add(DAYS.toMillis(date), toIntExact(value)); return MILLISECONDS.toDays(millis); }
@ScalarOperator(SUBTRACT) @SqlType(StandardTypes.TIMESTAMP) public static long timestampMinusIntervalYearToMonth(ConnectorSession session, @SqlType(StandardTypes.TIMESTAMP) long left, @SqlType(StandardTypes.INTERVAL_YEAR_TO_MONTH) long right) { if (session.isLegacyTimestamp()) { return getChronology(session.getTimeZoneKey()).monthOfYear().add(left, -right); } else { return MONTH_OF_YEAR_UTC.add(left, -right); } }
@ScalarOperator(ADD) @SqlType(StandardTypes.TIMESTAMP) public static long intervalYearToMonthPlusTimestamp(ConnectorSession session, @SqlType(StandardTypes.INTERVAL_YEAR_TO_MONTH) long left, @SqlType(StandardTypes.TIMESTAMP) long right) { if (session.isLegacyTimestamp()) { return getChronology(session.getTimeZoneKey()).monthOfYear().add(right, left); } else { return MONTH_OF_YEAR_UTC.add(right, left); } }
@ScalarOperator(ADD) @SqlType(StandardTypes.TIMESTAMP) public static long timestampPlusIntervalYearToMonth(ConnectorSession session, @SqlType(StandardTypes.TIMESTAMP) long left, @SqlType(StandardTypes.INTERVAL_YEAR_TO_MONTH) long right) { if (session.isLegacyTimestamp()) { return getChronology(session.getTimeZoneKey()).monthOfYear().add(left, right); } else { return MONTH_OF_YEAR_UTC.add(left, right); } }
@Description("add the specified amount of time to the given time") @LiteralParameters("x") @ScalarFunction("date_add") @SqlType(StandardTypes.TIME) public static long addFieldValueTime(ConnectorSession session, @SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.TIME) long time) { if (session.isLegacyTimestamp()) { ISOChronology chronology = getChronology(session.getTimeZoneKey()); return modulo24Hour(chronology, getTimeField(chronology, unit).add(time, toIntExact(value))); } return modulo24Hour(getTimeField(UTC_CHRONOLOGY, unit).add(time, toIntExact(value))); }
@Description("add the specified amount of time to the given timestamp") @LiteralParameters("x") @ScalarFunction("date_add") @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long addFieldValueTimestampWithTimeZone( @SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone) { long millis = getTimestampField(unpackChronology(timestampWithTimeZone), unit).add(unpackMillisUtc(timestampWithTimeZone), toIntExact(value)); return updateMillisUtc(millis, timestampWithTimeZone); }
@ScalarOperator(ADD) @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long intervalYearToMonthPlusTimestampWithTimeZone(@SqlType(StandardTypes.INTERVAL_YEAR_TO_MONTH) long left, @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long right) { return updateMillisUtc(unpackChronology(right).monthOfYear().add(unpackMillisUtc(right), left), right); }
@ScalarOperator(ADD) @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long timestampWithTimeZonePlusIntervalYearToMonth(@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long left, @SqlType(StandardTypes.INTERVAL_YEAR_TO_MONTH) long right) { return updateMillisUtc(unpackChronology(left).monthOfYear().add(unpackMillisUtc(left), right), left); }
@ScalarOperator(SUBTRACT) @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long timestampWithTimeZoneMinusIntervalYearToMonth(@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long left, @SqlType(StandardTypes.INTERVAL_YEAR_TO_MONTH) long right) { long dateTimeWithTimeZone = unpackChronology(left).monthOfYear().add(unpackMillisUtc(left), -right); return updateMillisUtc(dateTimeWithTimeZone, left); }
@Description("add the specified amount of time to the given time") @LiteralParameters("x") @ScalarFunction("date_add") @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) public static long addFieldValueTimeWithTimeZone( @SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long timeWithTimeZone) { ISOChronology chronology = unpackChronology(timeWithTimeZone); long millis = modulo24Hour(chronology, getTimeField(chronology, unit).add(unpackMillisUtc(timeWithTimeZone), toIntExact(value))); return updateMillisUtc(millis, timeWithTimeZone); }