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


Java LocalDate.isBefore方法代碼示例

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


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

示例1: main

import java.time.LocalDate; //導入方法依賴的package包/類
public static void main(String[] args) {
    /* Read and save input as LocalDates */
    Scanner scan = new Scanner(System.in);
    LocalDate returnDate = readDate(scan);
    LocalDate expectDate = readDate(scan);
    scan.close();
    
    /* Calculate fine */
    int fine;
    if (returnDate.isEqual(expectDate) || returnDate.isBefore(expectDate)) {
        fine = 0;
    } else if (returnDate.getMonth() == expectDate.getMonth() && returnDate.getYear() == expectDate.getYear()) {
        fine = 15 * (returnDate.getDayOfMonth() - expectDate.getDayOfMonth());
    } else if (returnDate.getYear() == expectDate.getYear()) {
        fine = 500 * (returnDate.getMonthValue() - expectDate.getMonthValue());
    } else {
        fine = 10000;
    }
    System.out.println(fine);
}
 
開發者ID:rshaghoulian,項目名稱:HackerRank_solutions,代碼行數:21,代碼來源:Solution.java

示例2: split

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Splits the given period into multiple slices of one month long.
 *
 * @param start the start of the period.
 * @param end   the end of the period.
 * @return The list of slices result of the splitting.
 */
public static List<Slice> split(LocalDate start, LocalDate end) {
    Objects.requireNonNull(start);
    Objects.requireNonNull(end);
    Preconditions.checkArgument(!start.isAfter(end));

    List<Slice> slices = Lists.newArrayList();

    LocalDate startOfMonth = start.withDayOfMonth(1);
    LocalDate endOfMonth = YearMonth.from(end).atEndOfMonth();

    do {
        slices.add(new Slice(startOfMonth, YearMonth.from(startOfMonth).atEndOfMonth()));
        startOfMonth = startOfMonth.plus(1, ChronoUnit.MONTHS);
    }
    while (startOfMonth.isBefore(endOfMonth) || startOfMonth.isEqual(endOfMonth));

    return slices;
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:26,代碼來源:Slice.java

示例3: onCheckOutDateSelected

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Validates the checkout date to ensure that it is at least one day after the checkin date.
 *
 * If it isn't, disables the room search button until it is.
 */
@FXML
private void onCheckOutDateSelected() {
    LocalDate checkOutDate = checkOutDatePicker.getValue();
    LocalDate checkInDate = checkInDatePicker.getValue();
    if(checkOutDate.isBefore(checkInDate) || checkOutDate.isEqual(checkInDate)) {
        checkOutDatePicker.getStyleClass().add("invalidField");
        checkOutDatePicker.setTooltip(
            new Tooltip("Checkout date cannot be on or before checkin date!")
        );
        findAvailableRoomsButton.setDisable(true);
    } else {
        checkOutDatePicker.getStyleClass().remove("invalidField");
        checkOutDatePicker.setTooltip(null);
        findAvailableRoomsButton.setDisable(false);
    }
    roomSearchResults.clear();
}
 
開發者ID:maillouxc,項目名稱:git-rekt,代碼行數:23,代碼來源:BrowseRoomsScreenController.java

示例4: isShowingTimeMarker

import java.time.LocalDate; //導入方法依賴的package包/類
@Override
protected boolean isShowingTimeMarker() {
    WeekDayView dayView = getSkinnable();
    WeekView weekView = dayView.getWeekView();

    if (weekView != null) {
        LocalDate today = getSkinnable().getToday();

        LocalDate weekStart = weekView.getStartDate();
        LocalDate weekEnd = weekView.getEndDate();

        return !(weekStart.isAfter(today) || weekEnd.isBefore(today));

    }

    return false;
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:18,代碼來源:WeekDayViewSkin.java

示例5: testRangeOfLocalDates

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider = "localDateRanges")
public void testRangeOfLocalDates(LocalDate start, LocalDate end, Period step, boolean parallel) {
    final Range<LocalDate> range = Range.of(start, end, step);
    final Array<LocalDate> array = range.toArray(parallel);
    final boolean ascend = start.isBefore(end);
    final int expectedLength = (int)Math.ceil(Math.abs((double)ChronoUnit.DAYS.between(start, end)) / (double)step.getDays());
    Assert.assertEquals(array.length(), expectedLength);
    Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATE);
    Assert.assertTrue(!array.style().isSparse());
    Assert.assertEquals(range.start(), start, "The range start");
    Assert.assertEquals(range.end(), end, "The range end");
    LocalDate expected = null;
    for (int i=0; i<array.length(); ++i) {
        final LocalDate 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

示例6: addEntryToResult

import java.time.LocalDate; //導入方法依賴的package包/類
private void addEntryToResult(Map<LocalDate, List<Entry<?>>> result, Entry<?> entry, LocalDate startDate, LocalDate endDate) {
    LocalDate entryStartDate = entry.getStartDate();
    LocalDate entryEndDate = entry.getEndDate();

    // entry does not intersect with time interval
    if (entryEndDate.isBefore(startDate) || entryStartDate.isAfter(endDate)) {
        return;
    }

    if (entryStartDate.isAfter(startDate)) {
        startDate = entryStartDate;
    }

    if (entryEndDate.isBefore(endDate)) {
        endDate = entryEndDate;
    }

    LocalDate date = startDate;
    do {
        result.computeIfAbsent(date, it -> new ArrayList<>()).add(entry);
        date = date.plusDays(1);
    } while (!date.isAfter(endDate));
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:24,代碼來源:Calendar.java

示例7: updateSelectedDates

import java.time.LocalDate; //導入方法依賴的package包/類
private void updateSelectedDates() {
    List<LocalDate> dates = new ArrayList<>();

    LocalDate start = getSkinnable().getPageStartDate();

    do {
        dates.add(start);
        start = start.plusDays(1);
    }
    while (start.isBefore(getSkinnable().getPageEndDate()) || start.isEqual(getSkinnable().getPageEndDate()));

    calendarOne.getSelectedDates().clear();
    calendarOne.getSelectedDates().addAll(dates);

    calendarTwo.getSelectedDates().clear();
    calendarTwo.getSelectedDates().addAll(dates);
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:18,代碼來源:PrintablePageSkin.java

示例8: isValid

import java.time.LocalDate; //導入方法依賴的package包/類
@Override
public boolean isValid(LocalDate localDate, ConstraintValidatorContext cxt) {
    // Another validator should check for this if required
    if (localDate == null) {
        return true;
    }

    return !localDate.isBefore(LocalDate.now());
}
 
開發者ID:hmcts,項目名稱:cmc-claim-store,代碼行數:10,代碼來源:DateNotInThePastConstraintValidator.java

示例9: getDateDiff

import java.time.LocalDate; //導入方法依賴的package包/類
private DateCalculatorResult getDateDiff(final DateToken startDateToken, final Token thirdToken) {
    LocalDate one = startDateToken.getValue();
    LocalDate two = ((DateToken) thirdToken).getValue();
    return (one.isBefore(two))
            ? new DateCalculatorResult(Period.between(one, two))
            : new DateCalculatorResult(Period.between(two, one));
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Programming-Blueprints,代碼行數:8,代碼來源:DateCalculator.java

示例10: from

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Obtains an instance of {@code JapaneseEra} from a date.
 *
 * @param date  the date, not null
 * @return the Era singleton, never null
 */
static JapaneseEra from(LocalDate date) {
    if (date.isBefore(MEIJI_6_ISODATE)) {
        throw new DateTimeException("JapaneseDate before Meiji 6 are not supported");
    }
    for (int i = KNOWN_ERAS.length - 1; i > 0; i--) {
        JapaneseEra era = KNOWN_ERAS[i];
        if (date.compareTo(era.since) >= 0) {
            return era;
        }
    }
    return null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:JapaneseEra.java

示例11: JapaneseDate

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Creates an instance from an ISO date.
 *
 * @param isoDate  the standard local date, validated not null
 */
JapaneseDate(LocalDate isoDate) {
    if (isoDate.isBefore(MEIJI_6_ISODATE)) {
        throw new DateTimeException("JapaneseDate before Meiji 6 is not supported");
    }
    LocalGregorianCalendar.Date jdate = toPrivateJapaneseDate(isoDate);
    this.era = JapaneseEra.toJapaneseEra(jdate.getEra());
    this.yearOfEra = jdate.getYear();
    this.isoDate = isoDate;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:JapaneseDate.java

示例12: JapaneseDate

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Constructs a {@code JapaneseDate}. This constructor does NOT validate the given parameters,
 * and {@code era} and {@code year} must agree with {@code isoDate}.
 *
 * @param era  the era, validated not null
 * @param year  the year-of-era, validated
 * @param isoDate  the standard local date, validated not null
 */
JapaneseDate(JapaneseEra era, int year, LocalDate isoDate) {
    if (isoDate.isBefore(MEIJI_6_ISODATE)) {
        throw new DateTimeException("JapaneseDate before Meiji 6 is not supported");
    }
    this.era = era;
    this.yearOfEra = year;
    this.isoDate = isoDate;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:JapaneseDate.java

示例13: bepaalEersteSelectiedatum

import java.time.LocalDate; //導入方法依賴的package包/類
private static BerekendeEersteSelectieDatum bepaalEersteSelectiedatum(LocalDate eersteSelectieDatum, LocalDate beginDatum,
                                                                      Dienst dienst, ChronoUnit chronoUnit) {
    LocalDate nieuweEersteSelectiedatum = eersteSelectieDatum;
    int aantalPeriodes = 0;
    while (nieuweEersteSelectiedatum.isBefore(beginDatum) && chronoUnit != null && dienst.getEenheidSelectieInterval() != null) {
        nieuweEersteSelectiedatum = nieuweEersteSelectiedatum.plus(dienst.getSelectieInterval(), chronoUnit);
        aantalPeriodes++;
    }
    return new BerekendeEersteSelectieDatum(nieuweEersteSelectiedatum, aantalPeriodes);
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:11,代碼來源:SelectieTaakBerekenServiceImpl.java

示例14: select

import java.time.LocalDate; //導入方法依賴的package包/類
@Override
public void select(LocalDate date) {
    if (date != null) {
        if (rangeStart == null) {
            model.selectedDates.setAll(date);
            model.lastSelected = date;
            rangeStart = date;
            rangeEnd = date;
        } else {
            if (date.equals(rangeStart.plusDays(-1)) || date.equals(rangeEnd.plusDays(1))) {
                model.selectedDates.add(date);
                model.lastSelected = date;

                if (date.isAfter(rangeEnd)) {
                    rangeEnd = date;
                }

                if (date.isBefore(rangeStart)) {
                    rangeStart = date;
                }
            } else {
                rangeStart = null;
                rangeEnd = null;
                select(date);
            }
        }
    }
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:29,代碼來源:DateSelectionModel.java

示例15: isIntersecting

import java.time.LocalDate; //導入方法依賴的package包/類
private boolean isIntersecting(LocalDate start, LocalDate end) {
    if ((start.isBefore(rangeStart) || start.isEqual(rangeStart)) && (end.isAfter(rangeEnd) || end.isEqual(rangeEnd))) {
        return true;
    }

    if ((start.isEqual(rangeStart) || start.isAfter(rangeStart)) && (start.isBefore(rangeEnd) || start.isEqual(rangeEnd))) {
        return true;
    }

    return (end.isEqual(rangeStart) || end.isAfter(rangeStart)) && (end.isBefore(rangeEnd) || end.isEqual(rangeEnd));

}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:13,代碼來源:DateSelectionModel.java


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