use of java.time.temporal.UnsupportedTemporalTypeException in project symja_android_library by axkr.
the class PackedLocalTime method truncatedTo.
public static int truncatedTo(TemporalUnit unit, int packedTime) {
if (unit == ChronoUnit.NANOS || unit == ChronoUnit.MILLIS) {
return packedTime;
}
Duration unitDur = unit.getDuration();
if (unitDur.getSeconds() > SECONDS_PER_DAY) {
throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation");
}
int hour = PackedLocalTime.getHour(packedTime);
int minute = PackedLocalTime.getMinute(packedTime);
int second = PackedLocalTime.getSecond(packedTime);
int milli = 0;
if (unit == ChronoUnit.DAYS) {
hour = 0;
minute = 0;
second = 0;
} else if (unit == ChronoUnit.HALF_DAYS) {
if (hour >= 12) {
hour = 12;
} else {
hour = 0;
}
minute = 0;
second = 0;
} else if (unit == ChronoUnit.HOURS) {
minute = 0;
second = 0;
} else if (unit == ChronoUnit.MINUTES) {
second = 0;
}
return PackedLocalTime.create(hour, minute, second, milli);
}
use of java.time.temporal.UnsupportedTemporalTypeException in project neo4j by neo4j.
the class TemporalValue method until.
@Override
public final long until(Temporal endExclusive, TemporalUnit unit) {
if (!(endExclusive instanceof TemporalValue)) {
throw new InvalidArgumentException("Can only compute durations between TemporalValues.");
}
TemporalValue from = this;
TemporalValue to = (TemporalValue) endExclusive;
if (unit.isTimeBased()) {
from = attachTime(from);
to = attachTime(to);
} else if (from.isSupported(ChronoField.SECOND_OF_DAY) && !to.isSupported(ChronoField.SECOND_OF_DAY)) {
to = attachTime(to);
} else if (to.isSupported(ChronoField.SECOND_OF_DAY) && !from.isSupported(ChronoField.SECOND_OF_DAY)) {
from = attachTime(from);
}
if (from.isSupported(ChronoField.MONTH_OF_YEAR) && !to.isSupported(ChronoField.MONTH_OF_YEAR)) {
to = attachDate(to, from.getDatePart());
} else if (to.isSupported(ChronoField.MONTH_OF_YEAR) && !from.isSupported(ChronoField.MONTH_OF_YEAR)) {
from = attachDate(from, to.getDatePart());
}
if (from.supportsTimeZone() && !to.supportsTimeZone()) {
to = attachTimeZone(to, from.getZoneId(from::getZoneOffset));
} else if (to.supportsTimeZone() && !from.supportsTimeZone()) {
from = attachTimeZone(from, to.getZoneId(to::getZoneOffset));
}
long until;
try {
until = from.temporal().until(to, unit);
} catch (UnsupportedTemporalTypeException e) {
throw new UnsupportedTemporalUnitException(e.getMessage(), e);
}
return until;
}
Aggregations