当前位置: 首页>>代码示例>>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;未经允许,请勿转载。