use of java.time.Period in project j2objc by google.
the class TCKPeriod method test_plusYears_overflowTooBig.
@Test(expected = ArithmeticException.class)
public void test_plusYears_overflowTooBig() {
Period test = Period.ofYears(Integer.MAX_VALUE);
test.plusYears(1);
}
use of java.time.Period in project j2objc by google.
the class TCKPeriod method test_plusDays_overflowTooBig.
@Test(expected = ArithmeticException.class)
public void test_plusDays_overflowTooBig() {
Period test = Period.ofDays(Integer.MAX_VALUE);
test.plusDays(1);
}
use of java.time.Period in project j2objc by google.
the class TCKPeriod method test_minusMonths_overflowTooBig.
@Test(expected = ArithmeticException.class)
public void test_minusMonths_overflowTooBig() {
Period test = Period.ofMonths(Integer.MAX_VALUE);
test.minusMonths(-1);
}
use of java.time.Period in project quickstart by wildfly.
the class SampleEndPoint method birthday.
@GET()
@Path("/birthday")
@RolesAllowed({ "Subscriber" })
public String birthday() {
if (birthdate.isPresent()) {
LocalDate birthdate = LocalDate.parse(this.birthdate.get().toString());
LocalDate today = LocalDate.now();
LocalDate next = birthdate.withYear(today.getYear());
if (today.equals(next)) {
return "Happy Birthday";
}
if (next.isBefore(today)) {
next = next.withYear(next.getYear() + 1);
}
Period wait = today.until(next);
return String.format("%d months and %d days until your next birthday.", wait.getMonths(), wait.getDays());
}
return "Sorry, we don't know your birthdate.";
}
use of java.time.Period in project tutorials by eugenp.
the class JavaPeriodUnitTest method whenTestPeriod_thenOk.
@Test
public void whenTestPeriod_thenOk() {
LocalDate startDate = LocalDate.of(2015, 2, 15);
LocalDate endDate = LocalDate.of(2017, 1, 21);
Period period = Period.between(startDate, endDate);
LOG.info(String.format("Years:%d months:%d days:%d", period.getYears(), period.getMonths(), period.getDays()));
assertFalse(period.isNegative());
assertEquals(56, period.plusDays(50).getDays());
assertEquals(9, period.minusMonths(2).getMonths());
Period fromUnits = Period.of(3, 10, 10);
Period fromDays = Period.ofDays(50);
Period fromMonths = Period.ofMonths(5);
Period fromYears = Period.ofYears(10);
Period fromWeeks = Period.ofWeeks(40);
assertEquals(280, fromWeeks.getDays());
Period fromCharYears = Period.parse("P2Y");
assertEquals(2, fromCharYears.getYears());
Period fromCharUnits = Period.parse("P2Y3M5D");
assertEquals(5, fromCharUnits.getDays());
}
Aggregations