java.time.chrono.IsoChronology Java Examples

The following examples show how to use java.time.chrono.IsoChronology. 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: TCKIsoChronology.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "resolve_ymaa")
public void test_resolve_ymaa_strict(int y, int m, int w, int d, LocalDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
    fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
    if (strict) {
        LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
 
Example #2
Source File: TestIsoChronoImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "RangeVersusCalendar")
public void test_IsoChrono_vsCalendar(LocalDate isoStartDate, LocalDate isoEndDate) {
    GregorianCalendar cal = new GregorianCalendar();
    assertEquals(cal.getCalendarType(), "gregory", "Unexpected calendar type");
    LocalDate isoDate = IsoChronology.INSTANCE.date(isoStartDate);

    cal.setTimeZone(TimeZone.getTimeZone("GMT+00"));
    cal.set(Calendar.YEAR, isoDate.get(YEAR));
    cal.set(Calendar.MONTH, isoDate.get(MONTH_OF_YEAR) - 1);
    cal.set(Calendar.DAY_OF_MONTH, isoDate.get(DAY_OF_MONTH));

    while (isoDate.isBefore(isoEndDate)) {
        assertEquals(isoDate.get(DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH), "Day mismatch in " + isoDate + ";  cal: " + cal);
        assertEquals(isoDate.get(MONTH_OF_YEAR), cal.get(Calendar.MONTH) + 1, "Month mismatch in " + isoDate);
        assertEquals(isoDate.get(YEAR_OF_ERA), cal.get(Calendar.YEAR), "Year mismatch in " + isoDate);

        isoDate = isoDate.plus(1, ChronoUnit.DAYS);
        cal.add(Calendar.DAY_OF_MONTH, 1);
    }
}
 
Example #3
Source File: TestIsoChronology.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="samples")
Object[][] data_samples() {
    return new Object[][] {
        {IsoChronology.INSTANCE.date(1, 7, 8), LocalDate.of(1, 7, 8)},
        {IsoChronology.INSTANCE.date(1, 7, 20), LocalDate.of(1, 7, 20)},
        {IsoChronology.INSTANCE.date(1, 7, 21), LocalDate.of(1, 7, 21)},

        {IsoChronology.INSTANCE.date(2, 7, 8), LocalDate.of(2, 7, 8)},
        {IsoChronology.INSTANCE.date(3, 6, 27), LocalDate.of(3, 6, 27)},
        {IsoChronology.INSTANCE.date(3, 5, 23), LocalDate.of(3, 5, 23)},
        {IsoChronology.INSTANCE.date(4, 6, 16), LocalDate.of(4, 6, 16)},
        {IsoChronology.INSTANCE.date(4, 7, 3), LocalDate.of(4, 7, 3)},
        {IsoChronology.INSTANCE.date(4, 7, 4), LocalDate.of(4, 7, 4)},
        {IsoChronology.INSTANCE.date(5, 1, 1), LocalDate.of(5, 1, 1)},
        {IsoChronology.INSTANCE.date(1727, 3, 3), LocalDate.of(1727, 3, 3)},
        {IsoChronology.INSTANCE.date(1728, 10, 28), LocalDate.of(1728, 10, 28)},
        {IsoChronology.INSTANCE.date(2012, 10, 29), LocalDate.of(2012, 10, 29)},
    };
}
 
Example #4
Source File: IsoFields.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ValueRange rangeRefinedBy(TemporalAccessor temporal) {
    if (isSupportedBy(temporal) == false) {
        throw new UnsupportedTemporalTypeException("Unsupported field: DayOfQuarter");
    }
    long qoy = temporal.getLong(QUARTER_OF_YEAR);
    if (qoy == 1) {
        long year = temporal.getLong(YEAR);
        return (IsoChronology.INSTANCE.isLeapYear(year) ? ValueRange.of(1, 91) : ValueRange.of(1, 90));
    } else if (qoy == 2) {
        return ValueRange.of(1, 91);
    } else if (qoy == 3 || qoy == 4) {
        return ValueRange.of(1, 92);
    } // else value not from 1 to 4, so drop through
    return range();
}
 
Example #5
Source File: TCKIsoChronology.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "resolve_yearOfEra")
public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    if (e != null) {
        fieldValues.put(ChronoField.ERA, (long) e);
    }
    if (yoe != null) {
        fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
    }
    if (y != null) {
        fieldValues.put(ChronoField.YEAR, (long) y);
    }
    if (field != null) {
        LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, style);
        assertEquals(date, null);
        assertEquals(fieldValues.get(field), (Long) expected.longValue());
        assertEquals(fieldValues.size(), 1);
    } else {
        try {
            IsoChronology.INSTANCE.resolveDate(fieldValues, style);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
 
Example #6
Source File: IsoFields.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
@Override
public ValueRange rangeRefinedBy(TemporalAccessor temporal) {
    if (isSupportedBy(temporal) == false) {
        throw new UnsupportedTemporalTypeException("Unsupported field: DayOfQuarter");
    }
    long qoy = temporal.getLong(QUARTER_OF_YEAR);
    if (qoy == 1) {
        long year = temporal.getLong(YEAR);
        return (IsoChronology.INSTANCE.isLeapYear(year) ? ValueRange.of(1, 91) : ValueRange.of(1, 90));
    } else if (qoy == 2) {
        return ValueRange.of(1, 91);
    } else if (qoy == 3 || qoy == 4) {
        return ValueRange.of(1, 92);
    } // else value not from 1 to 4, so drop through
    return range();
}
 
Example #7
Source File: TCKYear.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_with() {
    Year base = Year.of(5);
    Year result = base.with(ChronoField.ERA, 0);
    assertEquals(result, base.with(IsoEra.of(0)));

    int prolepticYear = IsoChronology.INSTANCE.prolepticYear(IsoEra.of(0), 5);
    assertEquals(result.get(ChronoField.ERA), 0);
    assertEquals(result.get(ChronoField.YEAR), prolepticYear);
    assertEquals(result.get(ChronoField.YEAR_OF_ERA), 5);

    result = base.with(ChronoField.YEAR, 10);
    assertEquals(result.get(ChronoField.ERA), base.get(ChronoField.ERA));
    assertEquals(result.get(ChronoField.YEAR), 10);
    assertEquals(result.get(ChronoField.YEAR_OF_ERA), 10);

    result = base.with(ChronoField.YEAR_OF_ERA, 20);
    assertEquals(result.get(ChronoField.ERA), base.get(ChronoField.ERA));
    assertEquals(result.get(ChronoField.YEAR), 20);
    assertEquals(result.get(ChronoField.YEAR_OF_ERA), 20);
}
 
Example #8
Source File: LocalDate.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a local date from the year, month and day fields.
 *
 * @param year  the year to represent, validated from MIN_YEAR to MAX_YEAR
 * @param month  the month-of-year to represent, from 1 to 12, validated
 * @param dayOfMonth  the day-of-month to represent, validated from 1 to 31
 * @return the local date, not null
 * @throws DateTimeException if the day-of-month is invalid for the month-year
 */
private static LocalDate create(int year, int month, int dayOfMonth) {
    if (dayOfMonth > 28) {
        int dom = 31;
        switch (month) {
            case 2:
                dom = (IsoChronology.INSTANCE.isLeapYear(year) ? 29 : 28);
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                dom = 30;
                break;
        }
        if (dayOfMonth > dom) {
            if (dayOfMonth == 29) {
                throw new DateTimeException("Invalid date 'February 29' as '" + year + "' is not a leap year");
            } else {
                throw new DateTimeException("Invalid date '" + Month.of(month).name() + " " + dayOfMonth + "'");
            }
        }
    }
    return new LocalDate(year, month, dayOfMonth);
}
 
Example #9
Source File: ZoneOffsetTransitionRule.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a transition instance for the specified year.
 * <p>
 * Calculations are performed using the ISO-8601 chronology.
 *
 * @param year  the year to create a transition for, not null
 * @return the transition instance, not null
 */
public ZoneOffsetTransition createTransition(int year) {
    LocalDate date;
    if (dom < 0) {
        date = LocalDate.of(year, month, month.length(IsoChronology.INSTANCE.isLeapYear(year)) + 1 + dom);
        if (dow != null) {
            date = date.with(previousOrSame(dow));
        }
    } else {
        date = LocalDate.of(year, month, dom);
        if (dow != null) {
            date = date.with(nextOrSame(dow));
        }
    }
    if (timeEndOfDay) {
        date = date.plusDays(1);
    }
    LocalDateTime localDT = LocalDateTime.of(date, time);
    LocalDateTime transition = timeDefinition.createDateTime(localDT, standardOffset, offsetBefore);
    return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
}
 
Example #10
Source File: TCKIsoChronology.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_smart(int y, int d, LocalDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
    if (smart) {
        LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
 
Example #11
Source File: TCKIsoChronology.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "resolve_ymaa")
public void test_resolve_ymaa_smart(int y, int m, int w, int d, LocalDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
    fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
    if (smart) {
        LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
 
Example #12
Source File: LocalDate.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a local date from the year, month and day fields.
 *
 * @param year  the year to represent, validated from MIN_YEAR to MAX_YEAR
 * @param month  the month-of-year to represent, from 1 to 12, validated
 * @param dayOfMonth  the day-of-month to represent, validated from 1 to 31
 * @return the local date, not null
 * @throws DateTimeException if the day-of-month is invalid for the month-year
 */
private static LocalDate create(int year, int month, int dayOfMonth) {
    if (dayOfMonth > 28) {
        int dom = 31;
        switch (month) {
            case 2:
                dom = (IsoChronology.INSTANCE.isLeapYear(year) ? 29 : 28);
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                dom = 30;
                break;
        }
        if (dayOfMonth > dom) {
            if (dayOfMonth == 29) {
                throw new DateTimeException("Invalid date 'February 29' as '" + year + "' is not a leap year");
            } else {
                throw new DateTimeException("Invalid date '" + Month.of(month).name() + " " + dayOfMonth + "'");
            }
        }
    }
    return new LocalDate(year, month, dayOfMonth);
}
 
Example #13
Source File: LocalDate.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an instance of {@code LocalDate} from a year and day-of-year.
 * <p>
 * This returns a {@code LocalDate} with the specified year and day-of-year.
 * The day-of-year must be valid for the year, otherwise an exception will be thrown.
 *
 * @param year  the year to represent, from MIN_YEAR to MAX_YEAR
 * @param dayOfYear  the day-of-year to represent, from 1 to 366
 * @return the local date, not null
 * @throws DateTimeException if the value of any field is out of range,
 *  or if the day-of-year is invalid for the year
 */
public static LocalDate ofYearDay(int year, int dayOfYear) {
    YEAR.checkValidValue(year);
    DAY_OF_YEAR.checkValidValue(dayOfYear);
    boolean leap = IsoChronology.INSTANCE.isLeapYear(year);
    if (dayOfYear == 366 && leap == false) {
        throw new DateTimeException("Invalid date 'DayOfYear 366' as '" + year + "' is not a leap year");
    }
    Month moy = Month.of((dayOfYear - 1) / 31 + 1);
    int monthEnd = moy.firstDayOfYear(leap) + moy.length(leap) - 1;
    if (dayOfYear > monthEnd) {
        moy = moy.plus(1);
    }
    int dom = dayOfYear - moy.firstDayOfYear(leap) + 1;
    return new LocalDate(year, moy.getValue(), dom);
}
 
Example #14
Source File: LocalDate.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains an instance of {@code LocalDate} from a year and day-of-year.
 * <p>
 * This returns a {@code LocalDate} with the specified year and day-of-year.
 * The day-of-year must be valid for the year, otherwise an exception will be thrown.
 *
 * @param year  the year to represent, from MIN_YEAR to MAX_YEAR
 * @param dayOfYear  the day-of-year to represent, from 1 to 366
 * @return the local date, not null
 * @throws DateTimeException if the value of any field is out of range,
 *  or if the day-of-year is invalid for the year
 */
public static LocalDate ofYearDay(int year, int dayOfYear) {
    YEAR.checkValidValue(year);
    DAY_OF_YEAR.checkValidValue(dayOfYear);
    boolean leap = IsoChronology.INSTANCE.isLeapYear(year);
    if (dayOfYear == 366 && leap == false) {
        throw new DateTimeException("Invalid date 'DayOfYear 366' as '" + year + "' is not a leap year");
    }
    Month moy = Month.of((dayOfYear - 1) / 31 + 1);
    int monthEnd = moy.firstDayOfYear(leap) + moy.length(leap) - 1;
    if (dayOfYear > monthEnd) {
        moy = moy.plus(1);
    }
    int dom = dayOfYear - moy.firstDayOfYear(leap) + 1;
    return new LocalDate(year, moy.getValue(), dom);
}
 
Example #15
Source File: TestIsoChronology.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_chrono_byName() {
    Chronology c = IsoChronology.INSTANCE;
    Chronology test = Chronology.of("ISO");
    Assert.assertNotNull(test, "The ISO calendar could not be found byName");
    Assert.assertEquals(test.getId(), "ISO", "ID mismatch");
    Assert.assertEquals(test.getCalendarType(), "iso8601", "Type mismatch");
    Assert.assertEquals(test, c);
}
 
Example #16
Source File: TCKChronoPrinterParser.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="parseValid")
Object[][] data_parseValid() {
    return new Object[][] {
            {"ISO", IsoChronology.INSTANCE},
            {"ThaiBuddhist", ThaiBuddhistChronology.INSTANCE},
            {"Japanese", JapaneseChronology.INSTANCE},

            {"ISO2012", IsoChronology.INSTANCE},
            {"ThaiBuddhistXXX", ThaiBuddhistChronology.INSTANCE},
            {"JapaneseXXX", JapaneseChronology.INSTANCE},
    };
}
 
Example #17
Source File: TCKLocalDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="query")
Object[][] data_query() {
    return new Object[][] {
            {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.chronology(), IsoChronology.INSTANCE},
            {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.zoneId(), null},
            {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.precision(), ChronoUnit.NANOS},
            {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.zone(), null},
            {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.offset(), null},
            {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.localDate(), LocalDate.of(2007, 7, 15)},
            {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.localTime(), LocalTime.of(12, 30, 40, 987654321)},
    };
}
 
Example #18
Source File: DateTimeTextProvider.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the text for the specified chrono, field, locale and style
 * for the purpose of formatting.
 * <p>
 * The text associated with the value is returned.
 * The null return value should be used if there is no applicable text, or
 * if the text would be a numeric representation of the value.
 *
 * @param chrono  the Chronology to get text for, not null
 * @param field  the field to get text for, not null
 * @param value  the field value to get text for, not null
 * @param style  the style to get text for, not null
 * @param locale  the locale to get text for, not null
 * @return the text for the field value, null if no text found
 */
public String getText(Chronology chrono, TemporalField field, long value,
                                TextStyle style, Locale locale) {
    if (chrono == IsoChronology.INSTANCE
            || !(field instanceof ChronoField)) {
        return getText(field, value, style, locale);
    }

    int fieldIndex;
    int fieldValue;
    if (field == ERA) {
        fieldIndex = Calendar.ERA;
        if (chrono == JapaneseChronology.INSTANCE) {
            if (value == -999) {
                fieldValue = 0;
            } else {
                fieldValue = (int) value + 2;
            }
        } else {
            fieldValue = (int) value;
        }
    } else if (field == MONTH_OF_YEAR) {
        fieldIndex = Calendar.MONTH;
        fieldValue = (int) value - 1;
    } else if (field == DAY_OF_WEEK) {
        fieldIndex = Calendar.DAY_OF_WEEK;
        fieldValue = (int) value + 1;
        if (fieldValue > 7) {
            fieldValue = Calendar.SUNDAY;
        }
    } else if (field == AMPM_OF_DAY) {
        fieldIndex = Calendar.AM_PM;
        fieldValue = (int) value;
    } else {
        return null;
    }
    return CalendarDataUtility.retrieveJavaTimeFieldValueName(
            chrono.getCalendarType(), fieldIndex, fieldValue, style.toCalendarStyle(), locale);
}
 
Example #19
Source File: TCKDateTimeParseResolver.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_fieldResolvesToChronoZonedDateTime_noOverrideChrono_matches() {
    ZonedDateTime zdt = ZonedDateTime.of(2010, 6, 30, 12, 30, 0, 0, EUROPE_PARIS);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(zdt)).toFormatter();
    TemporalAccessor accessor = f.parse("1234567890");
    assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(2010, 6, 30));
    assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.of(12, 30));
    assertEquals(accessor.query(TemporalQueries.chronology()), IsoChronology.INSTANCE);
    assertEquals(accessor.query(TemporalQueries.zoneId()), EUROPE_PARIS);
}
 
Example #20
Source File: TestIsoChronology.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="toString")
Object[][] data_toString() {
    return new Object[][] {
        {IsoChronology.INSTANCE.date(1, 1, 1), "0001-01-01"},
        {IsoChronology.INSTANCE.date(1728, 10, 28), "1728-10-28"},
        {IsoChronology.INSTANCE.date(1728, 10, 29), "1728-10-29"},
        {IsoChronology.INSTANCE.date(1727, 12, 5), "1727-12-05"},
        {IsoChronology.INSTANCE.date(1727, 12, 6), "1727-12-06"},
    };
}
 
Example #21
Source File: DateTimeParseContext.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the effective chronology during parsing.
 *
 * @return the effective parsing chronology, not null
 */
Chronology getEffectiveChronology() {
    Chronology chrono = currentParsed().chrono;
    if (chrono == null) {
        chrono = formatter.getChronology();
        if (chrono == null) {
            chrono = IsoChronology.INSTANCE;
        }
    }
    return chrono;
}
 
Example #22
Source File: TCKChronology.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "calendarsystemtype")
Object[][] data_CalendarType() {
    return new Object[][] {
        {HijrahChronology.INSTANCE, "islamic-umalqura"},
        {IsoChronology.INSTANCE, "iso8601"},
        {JapaneseChronology.INSTANCE, "japanese"},
        {MinguoChronology.INSTANCE, "roc"},
        {ThaiBuddhistChronology.INSTANCE, "buddhist"},
    };
}
 
Example #23
Source File: TCKDateTimeParseResolver.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_withChronology_noOverride() {
    DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(EPOCH_DAY, 2).toFormatter();
    TemporalAccessor accessor = f.parse("");
    assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(1970, 1, 3));
    assertEquals(accessor.query(TemporalQueries.localTime()), null);
    assertEquals(accessor.query(TemporalQueries.chronology()), IsoChronology.INSTANCE);
}
 
Example #24
Source File: TestIsoChronology.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_date_withEra() {
    int year = 5;
    int month = 5;
    int dayOfMonth = 5;
    LocalDate test = IsoChronology.INSTANCE.date(IsoEra.BCE, year, month, dayOfMonth);
    assertEquals(test.getEra(), IsoEra.BCE);
    assertEquals(test.get(ChronoField.YEAR_OF_ERA), year);
    assertEquals(test.get(ChronoField.MONTH_OF_YEAR), month);
    assertEquals(test.get(ChronoField.DAY_OF_MONTH), dayOfMonth);

    assertEquals(test.get(YEAR), 1 + (-1 * year));
    assertEquals(test.get(ERA), 0);
    assertEquals(test.get(YEAR_OF_ERA), year);
}
 
Example #25
Source File: Period.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates that the temporal has the correct chronology.
 */
private void validateChrono(TemporalAccessor temporal) {
    Objects.requireNonNull(temporal, "temporal");
    Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
    if (temporalChrono != null && IsoChronology.INSTANCE.equals(temporalChrono) == false) {
        throw new DateTimeException("Chronology mismatch, expected: ISO, actual: " + temporalChrono.getId());
    }
}
 
Example #26
Source File: TCKChronoZonedDateTimeSerialization.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "calendars")
Chronology[][] data_of_calendars() {
    return new Chronology[][]{
                {HijrahChronology.INSTANCE},
                {IsoChronology.INSTANCE},
                {JapaneseChronology.INSTANCE},
                {MinguoChronology.INSTANCE},
                {ThaiBuddhistChronology.INSTANCE},
    };
}
 
Example #27
Source File: TCKLocalDate.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="query")
Object[][] data_query() {
    return new Object[][] {
            {TEST_2007_07_15, TemporalQueries.chronology(), IsoChronology.INSTANCE},
            {TEST_2007_07_15, TemporalQueries.zoneId(), null},
            {TEST_2007_07_15, TemporalQueries.precision(), ChronoUnit.DAYS},
            {TEST_2007_07_15, TemporalQueries.zone(), null},
            {TEST_2007_07_15, TemporalQueries.offset(), null},
            {TEST_2007_07_15, TemporalQueries.localDate(), TEST_2007_07_15},
            {TEST_2007_07_15, TemporalQueries.localTime(), null},
    };
}
 
Example #28
Source File: TCKYearMonth.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="query")
Object[][] data_query() {
    return new Object[][] {
            {TEST_2008_06, TemporalQueries.chronology(), IsoChronology.INSTANCE},
            {TEST_2008_06, TemporalQueries.zoneId(), null},
            {TEST_2008_06, TemporalQueries.precision(), ChronoUnit.MONTHS},
            {TEST_2008_06, TemporalQueries.zone(), null},
            {TEST_2008_06, TemporalQueries.offset(), null},
            {TEST_2008_06, TemporalQueries.localDate(), null},
            {TEST_2008_06, TemporalQueries.localTime(), null},
    };
}
 
Example #29
Source File: TCKYear.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="query")
Object[][] data_query() {
    return new Object[][] {
            {TEST_2008, TemporalQueries.chronology(), IsoChronology.INSTANCE},
            {TEST_2008, TemporalQueries.zoneId(), null},
            {TEST_2008, TemporalQueries.precision(), ChronoUnit.YEARS},
            {TEST_2008, TemporalQueries.zone(), null},
            {TEST_2008, TemporalQueries.offset(), null},
            {TEST_2008, TemporalQueries.localDate(), null},
            {TEST_2008, TemporalQueries.localTime(), null},
    };
}
 
Example #30
Source File: TCKMonthDay.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="query")
Object[][] data_query() {
    return new Object[][] {
            {TEST_07_15, TemporalQueries.chronology(), IsoChronology.INSTANCE},
            {TEST_07_15, TemporalQueries.zoneId(), null},
            {TEST_07_15, TemporalQueries.precision(), null},
            {TEST_07_15, TemporalQueries.zone(), null},
            {TEST_07_15, TemporalQueries.offset(), null},
            {TEST_07_15, TemporalQueries.localDate(), null},
            {TEST_07_15, TemporalQueries.localTime(), null},
    };
}