use of java.time.LocalDate in project jdk8u_jdk by JetBrains.
the class TCKLocalDateTime method test_plusHours_one.
//-----------------------------------------------------------------------
// plusHours()
//-----------------------------------------------------------------------
@Test
public void test_plusHours_one() {
LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
LocalDate d = t.toLocalDate();
for (int i = 0; i < 50; i++) {
t = t.plusHours(1);
if ((i + 1) % 24 == 0) {
d = d.plusDays(1);
}
assertEquals(t.toLocalDate(), d);
assertEquals(t.getHour(), (i + 1) % 24);
}
}
use of java.time.LocalDate in project jdk8u_jdk by JetBrains.
the class TCKLocalDateTime method test_plusNanos_halfABillion.
//-----------------------------------------------------------------------
// plusNanos()
//-----------------------------------------------------------------------
@Test
public void test_plusNanos_halfABillion() {
LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
LocalDate d = t.toLocalDate();
int hour = 0;
int min = 0;
int sec = 0;
int nanos = 0;
for (long i = 0; i < 3700 * 1000000000L; i += 500000000) {
t = t.plusNanos(500000000);
nanos += 500000000;
if (nanos == 1000000000) {
sec++;
nanos = 0;
}
if (sec == 60) {
min++;
sec = 0;
}
if (min == 60) {
hour++;
min = 0;
}
assertEquals(t.toLocalDate(), d, String.valueOf(i));
assertEquals(t.getHour(), hour);
assertEquals(t.getMinute(), min);
assertEquals(t.getSecond(), sec);
assertEquals(t.getNano(), nanos);
}
}
use of java.time.LocalDate in project jdk8u_jdk by JetBrains.
the class TCKIsoChronology method test_resolve_ymaa_smart.
@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
}
}
}
use of java.time.LocalDate in project jdk8u_jdk by JetBrains.
the class TCKIsoChronology method test_resolve_ymaa_strict.
@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
}
}
}
use of java.time.LocalDate in project jdk8u_jdk by JetBrains.
the class TCKIsoFields method test_parse_weeks_STRICT.
//-----------------------------------------------------------------------
// parse weeks
//-----------------------------------------------------------------------
@Test(dataProvider = "week")
public void test_parse_weeks_STRICT(LocalDate date, DayOfWeek dow, int week, int wby) {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral('-').appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral('-').appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(ResolverStyle.STRICT);
LocalDate parsed = LocalDate.parse(wby + "-" + week + "-" + dow.getValue(), f);
assertEquals(parsed, date);
}
Aggregations