use of java.time.chrono.ThaiBuddhistDate in project jdk8u_jdk by JetBrains.
the class TCKThaiBuddhistChronology method test_isLeapYear.
@Test(dataProvider = "prolepticYear")
public void test_isLeapYear(int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear - YDIFF).isLeap());
ThaiBuddhistDate jdate = ThaiBuddhistDate.now();
jdate = jdate.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
if (isLeapYear) {
assertEquals(jdate.lengthOfMonth(), 29);
} else {
assertEquals(jdate.lengthOfMonth(), 28);
}
}
use of java.time.chrono.ThaiBuddhistDate in project jdk8u_jdk by JetBrains.
the class TestReducedParser method test_reducedWithLateChronoChange.
@Test
public void test_reducedWithLateChronoChange() {
ThaiBuddhistDate date = ThaiBuddhistDate.of(2543, 1, 1);
DateTimeFormatter df = new DateTimeFormatterBuilder().appendValueReduced(YEAR, 2, 2, LocalDate.of(2000, 1, 1)).appendLiteral(" ").appendChronologyId().toFormatter();
int expected = date.get(YEAR);
String input = df.format(date);
ParsePosition pos = new ParsePosition(0);
TemporalAccessor parsed = df.parseUnresolved(input, pos);
assertEquals(pos.getIndex(), input.length(), "Input not parsed completely");
assertEquals(pos.getErrorIndex(), -1, "Error index should be -1 (no-error)");
int actual = parsed.get(YEAR);
assertEquals(actual, expected, String.format("Wrong date parsed, chrono: %s, input: %s", parsed.query(TemporalQueries.chronology()), input));
}
use of java.time.chrono.ThaiBuddhistDate in project jdk8u_jdk by JetBrains.
the class TCKThaiBuddhistChronology method test_adjust_toMonth.
@Test(expectedExceptions = DateTimeException.class)
public void test_adjust_toMonth() {
ThaiBuddhistDate jdate = ThaiBuddhistChronology.INSTANCE.date(1726, 1, 4);
jdate.with(Month.APRIL);
}
use of java.time.chrono.ThaiBuddhistDate in project jdk8u_jdk by JetBrains.
the class TCKThaiBuddhistChronology method test_resolve_ymd_smart.
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_smart(int y, int m, int d, ThaiBuddhistDate expected, Object 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.DAY_OF_MONTH, (long) d);
if (Boolean.TRUE.equals(smart)) {
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else if (smart instanceof ThaiBuddhistDate) {
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
assertEquals(date, smart);
} else {
try {
ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
}
}
}
use of java.time.chrono.ThaiBuddhistDate in project jdk8u_jdk by JetBrains.
the class TCKThaiBuddhistChronology method test_periodUntilUnit.
@Test
public void test_periodUntilUnit() {
ThaiBuddhistDate mdate1 = ThaiBuddhistDate.of(1, 1, 1);
ThaiBuddhistDate mdate2 = ThaiBuddhistDate.of(2, 2, 2);
long months = mdate1.until(mdate2, ChronoUnit.MONTHS);
assertEquals(months, 13);
}
Aggregations