org.threeten.bp.temporal.ChronoUnit Java Examples

The following examples show how to use org.threeten.bp.temporal.ChronoUnit. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestMinguoChronology.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SuppressWarnings("unused")
@Test(dataProvider="samples")
public void test_MinguoDate(ChronoLocalDate minguoDate, LocalDate iso) {
    ChronoLocalDate hd = minguoDate;
    ChronoLocalDateTime<?> hdt = hd.atTime(LocalTime.NOON);
    ZoneOffset zo = ZoneOffset.ofHours(1);
    ChronoZonedDateTime<?> hzdt = hdt.atZone(zo);
    hdt = hdt.plus(1, ChronoUnit.YEARS);
    hdt = hdt.plus(1, ChronoUnit.MONTHS);
    hdt = hdt.plus(1, ChronoUnit.DAYS);
    hdt = hdt.plus(1, ChronoUnit.HOURS);
    hdt = hdt.plus(1, ChronoUnit.MINUTES);
    hdt = hdt.plus(1, ChronoUnit.SECONDS);
    hdt = hdt.plus(1, ChronoUnit.NANOS);
    ChronoLocalDateTime<?> a2 = hzdt.toLocalDateTime();
    ChronoLocalDate a3 = a2.toLocalDate();
    ChronoLocalDate a5 = hzdt.toLocalDate();
    //System.out.printf(" d: %s, dt: %s; odt: %s; zodt: %s; a4: %s%n", date, hdt, hodt, hzdt, a5);
}
 
Example #2
Source File: LocalTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns a copy of this time with the specified period added.
 * <p>
 * This method returns a new time based on this time with the specified period added.
 * This can be used to add any period that is defined by a unit, for example to add hours, minutes or seconds.
 * The unit is responsible for the details of the calculation, including the resolution
 * of any edge cases in the calculation.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param amountToAdd  the amount of the unit to add to the result, may be negative
 * @param unit  the unit of the period to add, not null
 * @return a {@code LocalTime} based on this time with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public LocalTime plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        ChronoUnit f = (ChronoUnit) unit;
        switch (f) {
            case NANOS: return plusNanos(amountToAdd);
            case MICROS: return plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);
            case MILLIS: return plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000000);
            case SECONDS: return plusSeconds(amountToAdd);
            case MINUTES: return plusMinutes(amountToAdd);
            case HOURS: return plusHours(amountToAdd);
            case HALF_DAYS: return plusHours((amountToAdd % 2) * 12);
        }
        throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
    }
    return unit.addTo(this, amountToAdd);
}
 
Example #3
Source File: LocalDateTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns a copy of this date-time with the specified period added.
 * <p>
 * This method returns a new date-time based on this date-time with the specified period added.
 * This can be used to add any period that is defined by a unit, for example to add years, months or days.
 * The unit is responsible for the details of the calculation, including the resolution
 * of any edge cases in the calculation.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param amountToAdd  the amount of the unit to add to the result, may be negative
 * @param unit  the unit of the period to add, not null
 * @return a {@code LocalDateTime} based on this date-time with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public LocalDateTime plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        ChronoUnit f = (ChronoUnit) unit;
        switch (f) {
            case NANOS: return plusNanos(amountToAdd);
            case MICROS: return plusDays(amountToAdd / MICROS_PER_DAY).plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);
            case MILLIS: return plusDays(amountToAdd / MILLIS_PER_DAY).plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000000);
            case SECONDS: return plusSeconds(amountToAdd);
            case MINUTES: return plusMinutes(amountToAdd);
            case HOURS: return plusHours(amountToAdd);
            case HALF_DAYS: return plusDays(amountToAdd / 256).plusHours((amountToAdd % 256) * 12);  // no overflow (256 is multiple of 2)
        }
        return with(date.plus(amountToAdd, unit), time);
    }
    return unit.addTo(this, amountToAdd);
}
 
Example #4
Source File: Instant.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * {@inheritDoc}
 * @throws DateTimeException {@inheritDoc}
 * @throws ArithmeticException {@inheritDoc}
 */
@Override
public Instant plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        switch ((ChronoUnit) unit) {
            case NANOS: return plusNanos(amountToAdd);
            case MICROS: return plus(amountToAdd / 1000000, (amountToAdd % 1000000) * 1000);
            case MILLIS: return plusMillis(amountToAdd);
            case SECONDS: return plusSeconds(amountToAdd);
            case MINUTES: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_MINUTE));
            case HOURS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_HOUR));
            case HALF_DAYS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY / 2));
            case DAYS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY));
        }
        throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
    }
    return unit.addTo(this, amountToAdd);
}
 
Example #5
Source File: UsabilityChrono.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Print a month calendar with complete week rows.
 * @param date A date in some calendar
 * @param out a PrintStream
 */
private static void printMonthCal(ChronoLocalDate date, PrintStream out) {

    int lengthOfMonth = (int) date.lengthOfMonth();
    ChronoLocalDate end = date.with(ChronoField.DAY_OF_MONTH, lengthOfMonth);
    end = end.plus(7 - end.get(ChronoField.DAY_OF_WEEK), ChronoUnit.DAYS);
    // Back up to the beginning of the week including the 1st of the month
    ChronoLocalDate start = date.with(ChronoField.DAY_OF_MONTH, 1);
    start = start.minus(start.get(ChronoField.DAY_OF_WEEK), ChronoUnit.DAYS);

    out.printf("%9s Month %2d, %4d%n", date.getChronology().getId(),
            date.get(ChronoField.MONTH_OF_YEAR),
            date.get(ChronoField.YEAR));
    String[] colText = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
    printMonthRow(colText, " ", out);

    String[] cell = new String[7];
    for ( ; start.compareTo(end) <= 0; start = start.plus(1, ChronoUnit.DAYS)) {
        int ndx = start.get(ChronoField.DAY_OF_WEEK) - 1;
        cell[ndx] = Integer.toString((int) start.get(ChronoField.DAY_OF_MONTH));
        if (ndx == 6) {
            printMonthRow(cell, "|", out);
        }
    }
}
 
Example #6
Source File: ChronoLocalDateTimeImpl.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public ChronoLocalDateTimeImpl<D> plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        ChronoUnit f = (ChronoUnit) unit;
        switch (f) {
            case NANOS: return plusNanos(amountToAdd);
            case MICROS: return plusDays(amountToAdd / MICROS_PER_DAY).plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);
            case MILLIS: return plusDays(amountToAdd / MILLIS_PER_DAY).plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000000);
            case SECONDS: return plusSeconds(amountToAdd);
            case MINUTES: return plusMinutes(amountToAdd);
            case HOURS: return plusHours(amountToAdd);
            case HALF_DAYS: return plusDays(amountToAdd / 256).plusHours((amountToAdd % 256) * 12);  // no overflow (256 is multiple of 2)
        }
        return with(date.plus(amountToAdd, unit), time);
    }
    return date.getChronology().ensureChronoLocalDateTime(unit.addTo(this, amountToAdd));
}
 
Example #7
Source File: ZonedDateTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean isSupported(TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return unit.isDateBased() || unit.isTimeBased();
    }
    return unit != null && unit.isSupportedBy(this);
}
 
Example #8
Source File: OffsetDateTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean isSupported(TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return unit.isDateBased() || unit.isTimeBased();
    }
    return unit != null && unit.isSupportedBy(this);
}
 
Example #9
Source File: UsabilityChrono.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Example code.
 */
static void example1() {
    System.out.printf("Available Calendars%n");

    // Print the Minguo date
    ChronoLocalDate now1 = MinguoChronology.INSTANCE.dateNow();
    int day = now1.get(ChronoField.DAY_OF_MONTH);
    int dow = now1.get(ChronoField.DAY_OF_WEEK);
    int month = now1.get(ChronoField.MONTH_OF_YEAR);
    int year = now1.get(ChronoField.YEAR);
    System.out.printf("  Today is %s %s %d-%s-%d%n", now1.getChronology().getId(),
            DayOfWeek.of(dow), year, month, day);

    // Print today's date and the last day of the year for the Minguo Calendar.
    ChronoLocalDate first = now1
            .with(ChronoField.DAY_OF_MONTH, 1)
            .with(ChronoField.MONTH_OF_YEAR, 1);
    ChronoLocalDate last = first
            .plus(1, ChronoUnit.YEARS)
            .minus(1, ChronoUnit.DAYS);
    System.out.printf("  1st of year: %s; end of year: %s%n", first, last);

    // Enumerate the list of available calendars and print today for each
    LocalDate  before = LocalDate.of(-500, 1, 1);
    Set<Chronology> chronos = Chronology.getAvailableChronologies();
    for (Chronology chrono : chronos) {
        ChronoLocalDate date = chrono.dateNow();
        ChronoLocalDate date2 = chrono.date(before);
        System.out.printf("   %20s: %22s, %22s%n", chrono.getId(), date, date2);
    }
}
 
Example #10
Source File: TestMonth.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_query() {
    assertEquals(Month.JUNE.query(TemporalQueries.chronology()), IsoChronology.INSTANCE);
    assertEquals(Month.JUNE.query(TemporalQueries.localDate()), null);
    assertEquals(Month.JUNE.query(TemporalQueries.localTime()), null);
    assertEquals(Month.JUNE.query(TemporalQueries.offset()), null);
    assertEquals(Month.JUNE.query(TemporalQueries.precision()), ChronoUnit.MONTHS);
    assertEquals(Month.JUNE.query(TemporalQueries.zone()), null);
    assertEquals(Month.JUNE.query(TemporalQueries.zoneId()), null);
}
 
Example #11
Source File: Instant.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean isSupported(TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return unit.isTimeBased() || unit == DAYS;
    }
    return unit != null && unit.isSupportedBy(this);
}
 
Example #12
Source File: ScheduleDayEntry.java    From droidconat-2016 with Apache License 2.0 5 votes vote down vote up
private String formatSessionTime(Session session) {
    LocalDateTime fromTime = session.getFromTime();
    LocalDateTime toTime = session.getToTime();
    long minutes = ChronoUnit.MINUTES.between(fromTime, toTime);
    return itemView.getContext().getString(R.string.schedule_day_entry_session_time_format,
            formatTime(fromTime), formatTime(toTime), minutes);
}
 
Example #13
Source File: DeviceListAdapter.java    From openwebnet-android with MIT License 5 votes vote down vote up
private void handleDeviceDebug(DeviceViewHolder holder, DeviceModel device) {
    holder.linearLayoutCardDeviceDebug.setVisibility(View.GONE);
    if (preferenceService.isDeviceDebugEnabled()) {
        holder.textViewCardDeviceValueDelay.setText("-");
        holder.textViewCustomCardDeviceResponse.setText(mContext.getString(R.string.card_device_debug_none));
        holder.linearLayoutCardDeviceDebug.setVisibility(View.VISIBLE);
        if (!TextUtils.isEmpty(device.getResponseDebug())) {
            long duration = ChronoUnit.MILLIS.between(device.getInstantRequestDebug(), device.getInstantResponseDebug());
            holder.textViewCardDeviceValueDelay.setText(String.valueOf(duration));
            holder.textViewCustomCardDeviceResponse.setText(device.getResponseDebug());

            handleDeviceDebugClipboard(holder, device);
        }
    }
}
 
Example #14
Source File: OffsetTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean isSupported(TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return unit.isTimeBased();
    }
    return unit != null && unit.isSupportedBy(this);
}
 
Example #15
Source File: BigQuerySnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
/** Example of updating a table by changing its expiration. */
// [TARGET update(TableInfo, TableOption...)]
// [VARIABLE "my_dataset_name"]
// [VARIABLE "my_table_name"]
public Table updateTableExpiration(String datasetName, String tableName) {
  // [START bigquery_update_table_expiration]
  Table beforeTable = bigquery.getTable(datasetName, tableName);

  // Set table to expire 5 days from now.
  long expirationMillis = Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli();
  TableInfo tableInfo = beforeTable.toBuilder().setExpirationTime(expirationMillis).build();
  Table afterTable = bigquery.update(tableInfo);
  // [END bigquery_update_table_expiration]
  return afterTable;
}
 
Example #16
Source File: LocalTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean isSupported(TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return unit.isTimeBased();
    }
    return unit != null && unit.isSupportedBy(this);
}
 
Example #17
Source File: WeekDatePicker.java    From WeekDatePicker with MIT License 5 votes vote down vote up
@Override public void scrollTo(int x, int y) {
    if (fromDate != null && x < 0) {
        x = 0;
    }

    if (toDate != null) {
        float totalWidth = (weekWidth + dividerSize) * ChronoUnit.WEEKS.between(getFirstDay(), toDate);

        if (x > totalWidth) {
            x = (int) totalWidth;
        }
    }

    super.scrollTo(x, y);
}
 
Example #18
Source File: TestInstant.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_query() {
    assertEquals(TEST_12345_123456789.query(TemporalQueries.chronology()), null);
    assertEquals(TEST_12345_123456789.query(TemporalQueries.localDate()), null);
    assertEquals(TEST_12345_123456789.query(TemporalQueries.localTime()), null);
    assertEquals(TEST_12345_123456789.query(TemporalQueries.offset()), null);
    assertEquals(TEST_12345_123456789.query(TemporalQueries.precision()), ChronoUnit.NANOS);
    assertEquals(TEST_12345_123456789.query(TemporalQueries.zone()), null);
    assertEquals(TEST_12345_123456789.query(TemporalQueries.zoneId()), null);
}
 
Example #19
Source File: TestZonedDateTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_plus_adjuster() {
    MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
    ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
    ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2009, 1, 1, 12, 30, 59, 500), ZONE_0100);
    assertEquals(t.plus(period), expected);
}
 
Example #20
Source File: ChronoZonedDateTimeImpl.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean isSupported(TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return unit.isDateBased() || unit.isTimeBased();
    }
    return unit != null && unit.isSupportedBy(this);
}
 
Example #21
Source File: ChronoZonedDateTimeImpl.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public ChronoZonedDateTime<D> plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return with(dateTime.plus(amountToAdd, unit));
    }
    return toLocalDate().getChronology().ensureChronoZonedDateTime(unit.addTo(this, amountToAdd));   /// TODO: Generics replacement Risk!
}
 
Example #22
Source File: TestLocalTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_query() {
    assertEquals(TEST_12_30_40_987654321.query(TemporalQueries.chronology()), null);
    assertEquals(TEST_12_30_40_987654321.query(TemporalQueries.localDate()), null);
    assertEquals(TEST_12_30_40_987654321.query(TemporalQueries.localTime()), TEST_12_30_40_987654321);
    assertEquals(TEST_12_30_40_987654321.query(TemporalQueries.offset()), null);
    assertEquals(TEST_12_30_40_987654321.query(TemporalQueries.precision()), ChronoUnit.NANOS);
    assertEquals(TEST_12_30_40_987654321.query(TemporalQueries.zone()), null);
    assertEquals(TEST_12_30_40_987654321.query(TemporalQueries.zoneId()), null);
}
 
Example #23
Source File: ChronoLocalDate.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean isSupported(TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return unit.isDateBased();
    }
    return unit != null && unit.isSupportedBy(this);
}
 
Example #24
Source File: TestLocalDateTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_query() {
    assertEquals(TEST_2007_07_15_12_30_40_987654321.query(TemporalQueries.chronology()), IsoChronology.INSTANCE);
    assertEquals(TEST_2007_07_15_12_30_40_987654321.query(TemporalQueries.localDate()), TEST_2007_07_15_12_30_40_987654321.toLocalDate());
    assertEquals(TEST_2007_07_15_12_30_40_987654321.query(TemporalQueries.localTime()), TEST_2007_07_15_12_30_40_987654321.toLocalTime());
    assertEquals(TEST_2007_07_15_12_30_40_987654321.query(TemporalQueries.offset()), null);
    assertEquals(TEST_2007_07_15_12_30_40_987654321.query(TemporalQueries.precision()), ChronoUnit.NANOS);
    assertEquals(TEST_2007_07_15_12_30_40_987654321.query(TemporalQueries.zone()), null);
    assertEquals(TEST_2007_07_15_12_30_40_987654321.query(TemporalQueries.zoneId()), null);
}
 
Example #25
Source File: ChronoDateImpl.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public long until(Temporal endExclusive, TemporalUnit unit) {
    ChronoLocalDate end = getChronology().date(endExclusive);
    if (unit instanceof ChronoUnit) {
        return LocalDate.from(this).until(end, unit);  // TODO: this is wrong
    }
    return unit.between(this, end);
}
 
Example #26
Source File: ChronoLocalDateTimeImpl.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean isSupported(TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return unit.isDateBased() || unit.isTimeBased();
    }
    return unit != null && unit.isSupportedBy(this);
}
 
Example #27
Source File: TestZonedDateTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_minus_adjuster() {
    MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
    ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
    ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2007, 11, 1, 12, 30, 59, 500), ZONE_0100);
    assertEquals(t.minus(period), expected);
}
 
Example #28
Source File: TestDayOfWeek.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_query() {
    assertEquals(DayOfWeek.FRIDAY.query(TemporalQueries.chronology()), null);
    assertEquals(DayOfWeek.FRIDAY.query(TemporalQueries.localDate()), null);
    assertEquals(DayOfWeek.FRIDAY.query(TemporalQueries.localTime()), null);
    assertEquals(DayOfWeek.FRIDAY.query(TemporalQueries.offset()), null);
    assertEquals(DayOfWeek.FRIDAY.query(TemporalQueries.precision()), ChronoUnit.DAYS);
    assertEquals(DayOfWeek.FRIDAY.query(TemporalQueries.zone()), null);
    assertEquals(DayOfWeek.FRIDAY.query(TemporalQueries.zoneId()), null);
}
 
Example #29
Source File: Year.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean isSupported(TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return unit == YEARS || unit == DECADES || unit == CENTURIES || unit == MILLENNIA || unit == ERAS;
    }
    return unit != null && unit.isSupportedBy(this);
}
 
Example #30
Source File: Year.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * {@inheritDoc}
 * @throws DateTimeException {@inheritDoc}
 * @throws ArithmeticException {@inheritDoc}
 */
@Override
public Year plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        switch ((ChronoUnit) unit) {
            case YEARS: return plusYears(amountToAdd);
            case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
            case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
            case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
            case ERAS: return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd));
        }
        throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
    }
    return unit.addTo(this, amountToAdd);
}