當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalDateTime.minus方法代碼示例

本文整理匯總了Java中java.time.LocalDateTime.minus方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDateTime.minus方法的具體用法?Java LocalDateTime.minus怎麽用?Java LocalDateTime.minus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.LocalDateTime的用法示例。


在下文中一共展示了LocalDateTime.minus方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: changeEndDate

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
 * Changes the end date of the entry interval.
 *
 * @param date         the new end date
 * @param keepDuration if true then this method will also change the start date and time in such a way that the total duration
 *                     of the entry will not change. If false then this method will ensure that the entry's interval
 *                     stays valid, which means that the start time will be before the end time and that the
 *                     duration of the entry will be at least the duration defined by the {@link #minimumDurationProperty()}.
 */
public final void changeEndDate(LocalDate date, boolean keepDuration) {
    requireNonNull(date);

    Interval interval = getInterval();

    LocalDateTime newEndDateTime = getEndAsLocalDateTime().with(date);
    LocalDateTime startDateTime = getStartAsLocalDateTime();

    if (keepDuration) {
        startDateTime = newEndDateTime.minus(getDuration());
        setInterval(startDateTime, newEndDateTime, getZoneId());
    } else {
        /*
         * We might have a problem if the new end time is BEFORE the current start time.
         */
        if (newEndDateTime.isBefore(startDateTime)) {
            interval = interval.withStartDateTime(newEndDateTime.minus(interval.getDuration()));
        }

        setInterval(interval.withEndDate(date));
    }
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:32,代碼來源:Entry.java

示例2: changeEndTime

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
 * Changes the end time of the entry interval.
 *
 * @param time         the new end time
 * @param keepDuration if true then this method will also change the start time in such a way that the total duration
 *                     of the entry will not change. If false then this method will ensure that the entry's interval
 *                     stays valid, which means that the start time will be before the end time and that the
 *                     duration of the entry will be at least the duration defined by the {@link #minimumDurationProperty()}.
 */
public final void changeEndTime(LocalTime time, boolean keepDuration) {
    requireNonNull(time);

    Interval interval = getInterval();

    LocalDateTime newEndDateTime = getEndAsLocalDateTime().with(time);
    LocalDateTime startDateTime = getStartAsLocalDateTime();

    if (keepDuration) {
        startDateTime = newEndDateTime.minus(getDuration());
        setInterval(startDateTime, newEndDateTime, getZoneId());
    } else {
        /*
         * We might have a problem if the new end time is BEFORE the current start time.
         */
        if (newEndDateTime.isBefore(startDateTime.plus(getMinimumDuration()))) {
            interval = interval.withStartDateTime(newEndDateTime.minus(getMinimumDuration()));
        }

        setInterval(interval.withEndTime(time));
    }
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:32,代碼來源:Entry.java

示例3: testRangeOfLocalDateTimes

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test(dataProvider = "localDateTimeRanges")
public void testRangeOfLocalDateTimes(LocalDateTime start, LocalDateTime end, Duration step, boolean parallel) {
    final Range<LocalDateTime> range = Range.of(start, end, step);
    final Array<LocalDateTime> array = range.toArray(parallel);
    final boolean ascend = start.isBefore(end);
    final int expectedLength = (int)Math.ceil(Math.abs((double)ChronoUnit.SECONDS.between(start, end)) / (double)step.getSeconds());
    Assert.assertEquals(array.length(), expectedLength);
    Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATETIME);
    Assert.assertTrue(!array.style().isSparse());
    Assert.assertEquals(range.start(), start, "The range start");
    Assert.assertEquals(range.end(), end, "The range end");
    LocalDateTime expected = null;
    for (int i=0; i<array.length(); ++i) {
        final LocalDateTime actual = array.getValue(i);
        expected = expected == null ? start : ascend ? expected.plus(step) : expected.minus(step);
        Assert.assertEquals(actual, expected, "Value matches at " + i);
        Assert.assertTrue(ascend ? actual.compareTo(start) >=0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + i);
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:20,代碼來源:RangeBasicTests.java

示例4: testRangeOfLocalDateTimes

import java.time.LocalDateTime; //導入方法依賴的package包/類
@Test(dataProvider = "LocalDateTimeRanges")
public void testRangeOfLocalDateTimes(LocalDateTime start, LocalDateTime end, Duration step, boolean parallel) {
    final boolean ascend = start.isBefore(end);
    final Range<LocalDateTime> range = Range.of(start, end, step, v -> v.getHour() == 6);
    final Array<LocalDateTime> array = range.toArray(parallel);
    final LocalDateTime first = array.first(v -> true).map(ArrayValue::getValue).get();
    final LocalDateTime last = array.last(v -> true).map(ArrayValue::getValue).get();
    Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATETIME);
    Assert.assertTrue(!array.style().isSparse());
    Assert.assertEquals(range.start(), start, "The range start");
    Assert.assertEquals(range.end(), end, "The range end");
    int index = 0;
    LocalDateTime value = first;
    while (ascend ? value.isBefore(last) : value.isAfter(last)) {
        final LocalDateTime actual = array.getValue(index);
        Assert.assertEquals(actual, value, "Value matches at " + index);
        Assert.assertTrue(ascend ? actual.compareTo(start) >= 0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + index);
        value = ascend ? value.plus(step) : value.minus(step);
        while (value.getHour() == 6) value = ascend ? value.plus(step) : value.minus(step);
        index++;
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:23,代碼來源:RangeFilterTests.java

示例5: setPatientAge

import java.time.LocalDateTime; //導入方法依賴的package包/類
private void setPatientAge(int age) {
  LocalDateTime now = LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.of("UTC"));

  LocalDateTime bday = now.minus(age, ChronoUnit.YEARS);
  long birthdate = bday.toInstant(ZoneOffset.UTC).toEpochMilli();
  person.attributes.put(Person.BIRTHDATE, birthdate);
}
 
開發者ID:synthetichealth,項目名稱:synthea_java,代碼行數:8,代碼來源:LogicTest.java

示例6: changeStartAndEndTime

import java.time.LocalDateTime; //導入方法依賴的package包/類
private void changeStartAndEndTime(MouseEvent evt) {
    DraggedEntry draggedEntry = dayView.getDraggedEntry();
    LocalDateTime locationTime = dayView.getZonedDateTimeAt(evt.getX(), evt.getY()).toLocalDateTime();

    LOGGER.fine("changing start/end time, time = " + locationTime //$NON-NLS-1$
            + " offset duration = " + offsetDuration); //$NON-NLS-1$

    if (locationTime != null && offsetDuration != null) {

        LocalDateTime newStartTime = locationTime.minus(offsetDuration);
        newStartTime = grid(newStartTime);
        LocalDateTime newEndTime = newStartTime.plus(entryDuration);

        LOGGER.fine("new start time = " + newStartTime); //$NON-NLS-1$
        LOGGER.fine("new start time (grid) = " + newStartTime); //$NON-NLS-1$
        LOGGER.fine("new end time = " + newEndTime); //$NON-NLS-1$

        LocalDate startDate = newStartTime.toLocalDate();
        LocalTime startTime = newStartTime.toLocalTime();

        LocalDate endDate = LocalDateTime.of(startDate, startTime).plus(entryDuration).toLocalDate();
        LocalTime endTime = newEndTime.toLocalTime();

        LOGGER.finer("new interval: sd = " + startDate + ", st = " + startTime + ", ed = " + endDate + ", et = " + endTime);

        draggedEntry.setInterval(startDate, startTime, endDate, endTime);

        requestLayout();
    }
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:31,代碼來源:DayViewEditController.java


注:本文中的java.time.LocalDateTime.minus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。