当前位置: 首页>>代码示例>>Java>>正文


Java ChronoLocalDate类代码示例

本文整理汇总了Java中java.time.chrono.ChronoLocalDate的典型用法代码示例。如果您正苦于以下问题:Java ChronoLocalDate类的具体用法?Java ChronoLocalDate怎么用?Java ChronoLocalDate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChronoLocalDate类属于java.time.chrono包,在下文中一共展示了ChronoLocalDate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_badWithAdjusterChrono

import java.time.chrono.ChronoLocalDate; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badWithAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalAdjuster adjuster = new FixedAdjuster(date2);
        if (chrono != chrono2) {
            try {
                date.with(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException");
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.with(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:TCKChronoLocalDate.java

示例2: ReducedPrinterParser

import java.time.chrono.ChronoLocalDate; //导入依赖的package包/类
/**
 * Constructor.
 *
 * @param field  the field to format, validated not null
 * @param minWidth  the minimum field width, from 1 to 10
 * @param maxWidth  the maximum field width, from 1 to 10
 * @param baseValue  the base value
 * @param baseDate  the base date
 */
ReducedPrinterParser(TemporalField field, int minWidth, int maxWidth,
        int baseValue, ChronoLocalDate baseDate) {
    this(field, minWidth, maxWidth, baseValue, baseDate, 0);
    if (minWidth < 1 || minWidth > 10) {
        throw new IllegalArgumentException("The minWidth must be from 1 to 10 inclusive but was " + minWidth);
    }
    if (maxWidth < 1 || maxWidth > 10) {
        throw new IllegalArgumentException("The maxWidth must be from 1 to 10 inclusive but was " + minWidth);
    }
    if (maxWidth < minWidth) {
        throw new IllegalArgumentException("Maximum width must exceed or equal the minimum width but " +
                maxWidth + " < " + minWidth);
    }
    if (baseDate == null) {
        if (field.range().isValidValue(baseValue) == false) {
            throw new IllegalArgumentException("The base value must be within the range of the field");
        }
        if ((((long) baseValue) + EXCEED_POINTS[maxWidth]) > Integer.MAX_VALUE) {
            throw new DateTimeException("Unable to add printer-parser as the range exceeds the capacity of an int");
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:DateTimeFormatterBuilder.java

示例3: test_badPlusAdjusterChrono

import java.time.chrono.ChronoLocalDate; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badPlusAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalAmount adjuster = new FixedAdjuster(date2);
        if (chrono != chrono2) {
            try {
                date.plus(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException");
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.plus(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:TCKChronoLocalDate.java

示例4: test_badMinusAdjusterChrono

import java.time.chrono.ChronoLocalDate; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badMinusAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalAmount adjuster = new FixedAdjuster(date2);
        if (chrono != chrono2) {
            try {
                date.minus(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException");
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.minus(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:TCKChronoLocalDate.java

示例5: localizedWeekOfWeekBasedYear

import java.time.chrono.ChronoLocalDate; //导入依赖的package包/类
/**
 * Returns the week of week-based-year for the temporal.
 * The week can be part of the previous year, the current year,
 * or the next year depending on the week start and minimum number
 * of days.
 * @param temporal  a date of any chronology
 * @return the week of the year
 * @see #localizedWeekBasedYear(java.time.temporal.TemporalAccessor)
 */
private int localizedWeekOfWeekBasedYear(TemporalAccessor temporal) {
    int dow = localizedDayOfWeek(temporal);
    int doy = temporal.get(DAY_OF_YEAR);
    int offset = startOfWeekOffset(doy, dow);
    int week = computeWeek(offset, doy);
    if (week == 0) {
        // Day is in end of week of previous year
        // Recompute from the last day of the previous year
        ChronoLocalDate date = Chronology.from(temporal).date(temporal);
        date = date.minus(doy, DAYS);   // Back down into previous year
        return localizedWeekOfWeekBasedYear(date);
    } else if (week > 50) {
        // If getting close to end of year, use higher precision logic
        // Check if date of year is in partial week associated with next year
        ValueRange dayRange = temporal.range(DAY_OF_YEAR);
        int yearLen = (int)dayRange.getMaximum();
        int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
        if (week >= newYearWeek) {
            // Overlaps with week of following year; reduce to week in following year
            week = week - newYearWeek + 1;
        }
    }
    return week;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:34,代码来源:WeekFields.java

示例6: initializeDatePickers

import java.time.chrono.ChronoLocalDate; //导入依赖的package包/类
/**
 * Ensures that the date pickers only allow selection of dates within the valid booking date
 * range, as defined in the specifications document.
 *
 * Chief among these rules is that bookings may not be placed more than one year in advance.
 */
private void initializeDatePickers() {
    Callback<DatePicker, DateCell> dayCellFactory =
        (final DatePicker datePicker) -> new DateCell() {
            @Override
            public void updateItem(LocalDate item, boolean empty) {
                super.updateItem(item, empty);

                if(item.isAfter(LocalDate.now().plusYears(1))) {
                    setDisable(true);
                }
                if(item.isBefore(ChronoLocalDate.from(LocalDate.now()))) {
                    setDisable(true);
                }
            }
        };
    // Disable selecting invalid check-in/check-out dates
    checkInDatePicker.setDayCellFactory(dayCellFactory);
    checkOutDatePicker.setDayCellFactory(dayCellFactory);
}
 
开发者ID:maillouxc,项目名称:git-rekt,代码行数:26,代码来源:BrowseRoomsScreenController.java

示例7: test_date_comparator_checkGenerics_LocalDate

import java.time.chrono.ChronoLocalDate; //导入依赖的package包/类
public void test_date_comparator_checkGenerics_LocalDate() {
    List<LocalDate> dates = new ArrayList<>();
    LocalDate date = LocalDate.of(2013, 1, 1);

    // Insert dates in order, no duplicates
    dates.add(date.minus(10, ChronoUnit.YEARS));
    dates.add(date.minus(1, ChronoUnit.YEARS));
    dates.add(date.minus(1, ChronoUnit.MONTHS));
    dates.add(date.minus(1, ChronoUnit.WEEKS));
    dates.add(date.minus(1, ChronoUnit.DAYS));
    dates.add(date);
    dates.add(date.plus(1, ChronoUnit.DAYS));
    dates.add(date.plus(1, ChronoUnit.WEEKS));
    dates.add(date.plus(1, ChronoUnit.MONTHS));
    dates.add(date.plus(1, ChronoUnit.YEARS));
    dates.add(date.plus(10, ChronoUnit.YEARS));

    List<LocalDate> copy = new ArrayList<>(dates);
    Collections.shuffle(copy);
    Collections.sort(copy, ChronoLocalDate.timeLineOrder());
    assertEquals(copy, dates);
    assertTrue(ChronoLocalDate.timeLineOrder().compare(copy.get(0), copy.get(1)) < 0);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:TestChronoLocalDate.java

示例8: test_badPlusTemporalUnitChrono

import java.time.chrono.ChronoLocalDate; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalUnit adjuster = new FixedTemporalUnit(date2);
        if (chrono != chrono2) {
            try {
                date.plus(1, adjuster);
                Assert.fail("TemporalUnit.doAdd plus should have thrown a ClassCastException" + date.getClass()
                        + ", can not be cast to " + date2.getClass());
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.plus(1, adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:TCKChronoLocalDate.java

示例9: test_reducedWithChronoYear

import java.time.chrono.ChronoLocalDate; //导入依赖的package包/类
@Test(dataProvider="ReducedWithChrono")
public void test_reducedWithChronoYear(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR, 2, 2, LocalDate.of(2000, 1, 1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input, pos);
    int actual = parsed.get(YEAR);
    assertEquals(actual, expected,
            String.format("Wrong date parsed, chrono: %s, input: %s",
            chrono, input));

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:TestReducedParser.java

示例10: test_date_comparator_checkGenerics_ISO

import java.time.chrono.ChronoLocalDate; //导入依赖的package包/类
public void test_date_comparator_checkGenerics_ISO() {
    List<ChronoLocalDate> dates = new ArrayList<>();
    ChronoLocalDate date = LocalDate.of(2013, 1, 1);

    // Insert dates in order, no duplicates
    dates.add(date.minus(10, ChronoUnit.YEARS));
    dates.add(date.minus(1, ChronoUnit.YEARS));
    dates.add(date.minus(1, ChronoUnit.MONTHS));
    dates.add(date.minus(1, ChronoUnit.WEEKS));
    dates.add(date.minus(1, ChronoUnit.DAYS));
    dates.add(date);
    dates.add(date.plus(1, ChronoUnit.DAYS));
    dates.add(date.plus(1, ChronoUnit.WEEKS));
    dates.add(date.plus(1, ChronoUnit.MONTHS));
    dates.add(date.plus(1, ChronoUnit.YEARS));
    dates.add(date.plus(10, ChronoUnit.YEARS));

    List<ChronoLocalDate> copy = new ArrayList<>(dates);
    Collections.shuffle(copy);
    Collections.sort(copy, ChronoLocalDate.timeLineOrder());
    assertEquals(copy, dates);
    assertTrue(ChronoLocalDate.timeLineOrder().compare(copy.get(0), copy.get(1)) < 0);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:TestChronoLocalDate.java

示例11: resolve

import java.time.chrono.ChronoLocalDate; //导入依赖的package包/类
@Override
public ChronoLocalDate resolve(
        Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle) {
    Long yearLong = fieldValues.get(YEAR);
    Long qoyLong = fieldValues.get(QUARTER_OF_YEAR);
    if (yearLong == null || qoyLong == null) {
        return null;
    }
    int y = YEAR.checkValidIntValue(yearLong);  // always validate
    long doq = fieldValues.get(DAY_OF_QUARTER);
    ensureIso(partialTemporal);
    LocalDate date;
    if (resolverStyle == ResolverStyle.LENIENT) {
        date = LocalDate.of(y, 1, 1).plusMonths(Math.multiplyExact(Math.subtractExact(qoyLong, 1), 3));
        doq = Math.subtractExact(doq, 1);
    } else {
        int qoy = QUARTER_OF_YEAR.range().checkValidIntValue(qoyLong, QUARTER_OF_YEAR);  // validated
        date = LocalDate.of(y, ((qoy - 1) * 3) + 1, 1);
        if (doq < 1 || doq > 90) {
            if (resolverStyle == ResolverStyle.STRICT) {
                rangeRefinedBy(date).checkValidValue(doq, this);  // only allow exact range
            } else {  // SMART
                range().checkValidValue(doq, this);  // allow 1-92 rolling into next quarter
            }
        }
        doq--;
    }
    fieldValues.remove(this);
    fieldValues.remove(YEAR);
    fieldValues.remove(QUARTER_OF_YEAR);
    return date.plusDays(doq);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:IsoFields.java

示例12: resolve

import java.time.chrono.ChronoLocalDate; //导入依赖的package包/类
@Override
public ChronoLocalDate resolve(
        Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle) {
    long value = fieldValues.remove(this);
    Chronology chrono = Chronology.from(partialTemporal);
    if (resolverStyle == ResolverStyle.LENIENT) {
        return chrono.dateEpochDay(Math.subtractExact(value, offset));
    }
    range().checkValidValue(value, this);
    return chrono.dateEpochDay(value - offset);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:JulianFields.java

示例13: ofWeekBasedYear

import java.time.chrono.ChronoLocalDate; //导入依赖的package包/类
/**
 * Return a new week-based-year date of the Chronology, year, week-of-year,
 * and dow of week.
 * @param chrono The chronology of the new date
 * @param yowby the year of the week-based-year
 * @param wowby the week of the week-based-year
 * @param dow the day of the week
 * @return a ChronoLocalDate for the requested year, week of year, and day of week
 */
private ChronoLocalDate ofWeekBasedYear(Chronology chrono,
        int yowby, int wowby, int dow) {
    ChronoLocalDate date = chrono.date(yowby, 1, 1);
    int ldow = localizedDayOfWeek(date);
    int offset = startOfWeekOffset(1, ldow);

    // Clamp the week of year to keep it in the same year
    int yearLen = date.lengthOfYear();
    int newYearWeek = computeWeek(offset, yearLen + weekDef.getMinimalDaysInFirstWeek());
    wowby = Math.min(wowby, newYearWeek - 1);

    int days = -offset + (dow - 1) + (wowby - 1) * 7;
    return date.plus(days, DAYS);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:WeekFields.java

示例14: test_epochSecond

import java.time.chrono.ChronoLocalDate; //导入依赖的package包/类
@Test(dataProvider = "epochSecond_dataProvider")
public void test_epochSecond(Chronology chrono, int y, int m, int d, int h, int min, int s, ZoneOffset offset) {
    ChronoLocalDate chronoLd = chrono.date(y, m, d);
    assertEquals(chrono.epochSecond(y, m, d, h, min, s, offset),
                 OffsetDateTime.of(LocalDate.from(chronoLd), LocalTime.of(h, min, s), offset)
                               .toEpochSecond());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:TCKChronology.java

示例15: test_MinguoChronology_dateYearDay

import java.time.chrono.ChronoLocalDate; //导入依赖的package包/类
@Test
public void test_MinguoChronology_dateYearDay() {
    Chronology chrono = Chronology.of("Minguo");
    ChronoLocalDate date1 = chrono.dateYearDay(MinguoEra.ROC, 5, 60);
    ChronoLocalDate date2 = chrono.date(MinguoEra.ROC, 5, 2, 29);
    assertEquals(date1, MinguoChronology.INSTANCE.dateYearDay(MinguoEra.ROC, 5, 60));
    assertEquals(date2, MinguoChronology.INSTANCE.dateYearDay(MinguoEra.ROC, 5, 60));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:TCKChronology.java


注:本文中的java.time.chrono.ChronoLocalDate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。