/** * Rounds the specified instant to midnight. * * @param instant the milliseconds from 1970-01-01T00:00:00Z to round * @param chronology the chronology to use, not null * @return the updated instant, rounded to midnight */ protected long checkInstant(long instant, Chronology chronology) { return chronology.dayOfMonth().roundFloor(instant); }
/** * Rounds to the lowest whole unit of this field on a copy of this DateTime. * * @return a copy of the DateTime with the field value changed */ public DateTime roundFloorCopy() { return iInstant.withMillis(iField.roundFloor(iInstant.getMillis())); }
/** * Rounds to the lowest whole unit of this field on a copy of this DateTime. * * @return a copy of the DateTime with the field value changed */ public DateTime roundFloorCopy() { return iInstant.withMillis(iField.roundFloor(iInstant.getMillis())); }
public long roundFloor(long instant) { if (iTimeField) { int offset = getOffsetToAdd(instant); instant = iField.roundFloor(instant + offset); return instant - offset; } else { long localInstant = iZone.convertUTCToLocal(instant); localInstant = iField.roundFloor(localInstant); return iZone.convertLocalToUTC(localInstant, false, instant); } }
public long roundFloor(long instant) { // Note: This works fine, but it ideally shouldn't invoke other // fields from within a field. instant = iChronology.weekOfWeekyear().roundFloor(instant); int wow = iChronology.getWeekOfWeekyear(instant); if (wow > 1) { instant -= ((long) DateTimeConstants.MILLIS_PER_WEEK) * (wow - 1); } return instant; }
long set(long millis, boolean reset) { if (iText == null) { millis = iField.setExtended(millis, iValue); } else { millis = iField.set(millis, iText, iLocale); } if (reset) { millis = iField.roundFloor(millis); } return millis; }
/** * Rounds to the lowest whole unit of this field on a copy of this DateMidnight. * * @return a copy of the DateMidnight with the field value changed */ public DateMidnight roundFloorCopy() { return iInstant.withMillis(iField.roundFloor(iInstant.getMillis())); }
public long roundFloor(long instant) { // Note: This works fine, but it ideally shouldn't invoke other // fields from within a field. instant = iChronology.weekOfWeekyear().roundFloor(instant); int wow = iChronology.getWeekOfWeekyear(instant); if (wow > 1) { instant -= ((long) DateTimeConstants.MILLIS_PER_WEEK) * (wow - 1); } return instant; }
long set(long millis, boolean reset) { if (iText == null) { millis = iField.setExtended(millis, iValue); } else { millis = iField.set(millis, iText, iLocale); } if (reset) { millis = iField.roundFloor(millis); } return millis; }
/** * Rounds to the lowest whole unit of this field on a copy of this * LocalDateTime. * <p> * For example, rounding floor on the hourOfDay field of a LocalDateTime * where the time is 10:30 would result in new LocalDateTime with the * time of 10:00. * * @return a copy of the LocalDateTime with the field value changed */ public LocalDateTime roundFloorCopy() { return iInstant.withLocalMillis(iField.roundFloor(iInstant.getLocalMillis())); }
public long roundFloor(long instant) { checkLimits(instant, null); long result = getWrappedField().roundFloor(instant); checkLimits(result, "resulting"); return result; }
/** * Round to the lowest whole unit of this field. * * @return the mutable datetime being used, so calls can be chained * @see DateTimeField#roundFloor */ public MutableDateTime roundFloor() { iInstant.setMillis(getField().roundFloor(iInstant.getMillis())); return iInstant; }
public long roundFloor(long instant) { checkLimits(instant, null); long result = getWrappedField().roundFloor(instant); checkLimits(result, "resulting"); return result; }
public long roundFloor(long instant) { DateTimeField field = getWrappedField(); return field.roundFloor(field.set(instant, get(instant) * iDivisor)); }
@Description("truncate to the specified precision in the session timezone") @ScalarFunction("date_trunc") @LiteralParameters("x") @SqlType(StandardTypes.DATE) public static long truncateDate(ConnectorSession session, @SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.DATE) long date) { long millis = getDateField(UTC_CHRONOLOGY, unit).roundFloor(DAYS.toMillis(date)); return MILLISECONDS.toDays(millis); }
@Description("truncate to the specified precision in the session timezone") @ScalarFunction("date_trunc") @LiteralParameters("x") @SqlType(StandardTypes.TIME) public static long truncateTime(ConnectorSession session, @SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.TIME) long time) { if (session.isLegacyTimestamp()) { return getTimeField(getChronology(session.getTimeZoneKey()), unit).roundFloor(time); } else { return getTimeField(UTC_CHRONOLOGY, unit).roundFloor(time); } }
@Description("truncate to the specified precision in the session timezone") @ScalarFunction("date_trunc") @LiteralParameters("x") @SqlType(StandardTypes.TIMESTAMP) public static long truncateTimestamp(ConnectorSession session, @SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.TIMESTAMP) long timestamp) { if (session.isLegacyTimestamp()) { return getTimestampField(getChronology(session.getTimeZoneKey()), unit).roundFloor(timestamp); } else { return getTimestampField(UTC_CHRONOLOGY, unit).roundFloor(timestamp); } }
@ScalarFunction("date") @ScalarOperator(CAST) @SqlType(StandardTypes.DATE) public static long castToDate(@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long value) { // round down the current timestamp to days ISOChronology chronology = unpackChronology(value); long date = chronology.dayOfYear().roundFloor(unpackMillisUtc(value)); // date is currently midnight in timezone of the original value // convert to UTC long millis = date + chronology.getZone().getOffset(date); return TimeUnit.MILLISECONDS.toDays(millis); }
@Description("truncate to the specified precision") @ScalarFunction("date_trunc") @LiteralParameters("x") @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long truncateTimestampWithTimezone(@SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone) { long millis = getTimestampField(unpackChronology(timestampWithTimeZone), unit).roundFloor(unpackMillisUtc(timestampWithTimeZone)); return updateMillisUtc(millis, timestampWithTimeZone); }
@Description("truncate to the specified precision") @ScalarFunction("date_trunc") @LiteralParameters("x") @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) public static long truncateTimeWithTimeZone(@SqlType("varchar(x)") Slice unit, @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long timeWithTimeZone) { long millis = getTimeField(unpackChronology(timeWithTimeZone), unit).roundFloor(unpackMillisUtc(timeWithTimeZone)); return updateMillisUtc(millis, timeWithTimeZone); }