use of java.time.temporal.UnsupportedTemporalTypeException in project j2objc by google.
the class Year method with.
/**
* Returns a copy of this year with the specified field set to a new value.
* <p>
* This returns a {@code Year}, based on this one, with the value
* for the specified field changed.
* If it is not possible to set the value, because the field is not supported or for
* some other reason, an exception is thrown.
* <p>
* If the field is a {@link ChronoField} then the adjustment is implemented here.
* The supported fields behave as follows:
* <ul>
* <li>{@code YEAR_OF_ERA} -
* Returns a {@code Year} with the specified year-of-era
* The era will be unchanged.
* <li>{@code YEAR} -
* Returns a {@code Year} with the specified year.
* This completely replaces the date and is equivalent to {@link #of(int)}.
* <li>{@code ERA} -
* Returns a {@code Year} with the specified era.
* The year-of-era will be unchanged.
* </ul>
* <p>
* In all cases, if the new value is outside the valid range of values for the field
* then a {@code DateTimeException} will be thrown.
* <p>
* All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
* <p>
* If the field is not a {@code ChronoField}, then the result of this method
* is obtained by invoking {@code TemporalField.adjustInto(Temporal, long)}
* passing {@code this} as the argument. In this case, the field determines
* whether and how to adjust the instant.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param field the field to set in the result, not null
* @param newValue the new value of the field in the result
* @return a {@code Year} based on {@code this} with the specified field set, not null
* @throws DateTimeException if the field cannot be set
* @throws UnsupportedTemporalTypeException if the field is not supported
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
public Year with(TemporalField field, long newValue) {
if (field instanceof ChronoField) {
ChronoField f = (ChronoField) field;
f.checkValidValue(newValue);
switch(f) {
case YEAR_OF_ERA:
return Year.of((int) (year < 1 ? 1 - newValue : newValue));
case YEAR:
return Year.of((int) newValue);
case ERA:
return (getLong(ERA) == newValue ? this : Year.of(1 - year));
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.adjustInto(this, newValue);
}
use of java.time.temporal.UnsupportedTemporalTypeException in project symja_android_library by axkr.
the class DateMapFunctions method timeWindow.
/**
* Returns a column containing integers representing the nth group (0-based) that a date falls
* into.
*
* <p>Example: When Unit = ChronoUnit.DAY and n = 5, we form 5 day groups. a Date that is 2 days
* after the start is assigned to the first ("0") group. A day 7 days after the start is assigned
* to the second ("1") group.
*
* @param unit A ChronoUnit greater than or equal to a day
* @param n The number of units in each group.
* @param start The starting point of the first group; group boundaries are offsets from this
* point
*/
default IntColumn timeWindow(ChronoUnit unit, int n, LocalDate start) {
String newColumnName = "" + n + " " + unit.toString() + " window [" + name() + "]";
int packedStartDate = PackedLocalDate.pack(start);
IntColumn numberColumn = IntColumn.create(newColumnName, size());
for (int i = 0; i < size(); i++) {
int packedDate = getIntInternal(i);
int result;
switch(unit) {
case DAYS:
result = PackedLocalDate.daysUntil(packedDate, packedStartDate) / n;
numberColumn.set(i, result);
break;
case WEEKS:
result = PackedLocalDate.weeksUntil(packedDate, packedStartDate) / n;
numberColumn.set(i, result);
break;
case MONTHS:
result = PackedLocalDate.monthsUntil(packedDate, packedStartDate) / n;
numberColumn.set(i, result);
break;
case YEARS:
result = PackedLocalDate.yearsUntil(packedDate, packedStartDate) / n;
numberColumn.set(i, result);
break;
default:
throw new UnsupportedTemporalTypeException("The ChronoUnit " + unit + " is not supported for timeWindows on dates");
}
}
numberColumn.setPrintFormatter(NumberColumnFormatter.ints());
return numberColumn;
}
use of java.time.temporal.UnsupportedTemporalTypeException in project symja_android_library by axkr.
the class DateTimeMapFunctions method timeWindow.
/**
* Returns a column containing integers representing the nth group (0-based) that a date falls
* into.
*
* <p>Example: When Unit = ChronoUnit.DAY and n = 5, we form 5 day groups. a Date that is 2 days
* after the start is assigned to the first ("0") group. A day 7 days after the start is assigned
* to the second ("1") group.
*
* @param unit A ChronoUnit greater than or equal to a minute
* @param n The number of units in each group.
* @param start The starting point of the first group; group boundaries are offsets from this
* point
*/
default LongColumn timeWindow(ChronoUnit unit, int n, LocalDateTime start) {
String newColumnName = "" + n + " " + unit.toString() + " window [" + name() + "]";
long packedStartDate = pack(start);
LongColumn numberColumn = LongColumn.create(newColumnName, size());
for (int i = 0; i < size(); i++) {
long packedDate = getLongInternal(i);
long result;
switch(unit) {
case MINUTES:
result = minutesUntil(packedDate, packedStartDate) / n;
numberColumn.set(i, result);
break;
case HOURS:
result = hoursUntil(packedDate, packedStartDate) / n;
numberColumn.set(i, result);
break;
case DAYS:
result = daysUntil(packedDate, packedStartDate) / n;
numberColumn.set(i, result);
break;
case WEEKS:
result = weeksUntil(packedDate, packedStartDate) / n;
numberColumn.set(i, result);
break;
case MONTHS:
result = monthsUntil(packedDate, packedStartDate) / n;
numberColumn.set(i, result);
break;
case YEARS:
result = yearsUntil(packedDate, packedStartDate) / n;
numberColumn.set(i, result);
break;
default:
throw new UnsupportedTemporalTypeException("The ChronoUnit " + unit + " is not supported for timeWindows on dates");
}
}
numberColumn.setPrintFormatter(NumberColumnFormatter.ints());
return numberColumn;
}
use of java.time.temporal.UnsupportedTemporalTypeException in project symja_android_library by axkr.
the class TimeMapFunctions method plus.
default TimeColumn plus(int time, ChronoUnit unit) {
TimeColumn newColumn = TimeColumn.create("");
String timeUnitString = "";
for (int r = 0; r < size(); r++) {
int c1 = this.getIntInternal(r);
if (TimeColumn.valueIsMissing(c1)) {
newColumn.appendInternal(TimeColumnType.missingValueIndicator());
} else {
switch(unit) {
case HOURS:
newColumn.appendInternal(PackedLocalTime.plusHours(time, c1));
timeUnitString = "hours";
break;
case MINUTES:
newColumn.appendInternal(PackedLocalTime.plusMinutes(time, c1));
timeUnitString = "minutes";
break;
case SECONDS:
newColumn.appendInternal(PackedLocalTime.plusSeconds(time, c1));
timeUnitString = "seconds";
break;
case MILLIS:
newColumn.appendInternal(PackedLocalTime.plusMilliseconds(time, c1));
timeUnitString = "ms";
break;
default:
throw new UnsupportedTemporalTypeException("Type " + unit + " is not currently supported");
}
}
}
newColumn.setName(name() + " + " + time + " " + timeUnitString + "(s)");
return newColumn;
}
use of java.time.temporal.UnsupportedTemporalTypeException in project symja_android_library by axkr.
the class TimeMapFunctions method timeWindow.
/**
* Returns a column containing integers representing the nth group (0-based) that a date falls
* into.
*
* <p>Example: When Unit = ChronoUnit.DAY and n = 5, we form 5 day groups. a Date that is 2 days
* after the start is assigned to the first ("0") group. A day 7 days after the start is assigned
* to the second ("1") group.
*
* @param unit A ChronoUnit greater than or equal to a day
* @param n The number of units in each group.
* @param start The starting point of the first group; group boundaries are offsets from this
* point
*/
default DoubleColumn timeWindow(ChronoUnit unit, int n, LocalTime start) {
String newColumnName = "" + n + " " + unit.toString() + " window [" + name() + "]";
int packedStartTime = PackedLocalTime.pack(start);
DoubleColumn numberColumn = DoubleColumn.create(newColumnName, size());
for (int i = 0; i < size(); i++) {
int packedTime = getIntInternal(i);
int result;
switch(unit) {
case HOURS:
result = PackedLocalTime.hoursUntil(packedTime, packedStartTime) / n;
numberColumn.append(result);
break;
case MINUTES:
result = PackedLocalTime.minutesUntil(packedTime, packedStartTime) / n;
numberColumn.append(result);
break;
case SECONDS:
result = PackedLocalTime.secondsUntil(packedTime, packedStartTime) / n;
numberColumn.append(result);
break;
default:
throw new UnsupportedTemporalTypeException("The ChronoUnit " + unit + " is not supported for timeWindows on times");
}
}
numberColumn.setPrintFormatter(NumberColumnFormatter.ints());
return numberColumn;
}
Aggregations