What is a possible result of the following?
LocalDate montyPythonDay = LocalDate.of(2017, Month.MAY, 10);
LocalDate aprilFools = LocalDate.of(2018, Month.APRIL, 1);
Duration duration = Duration.ofDays(1);
LocalDate result = montyPythonDay.minus(duration);
System.out.println(result + " " + aprilFools.isBefore(result));
D.
Duration is supposed to be used with objects that contain times.
While it has an ofDays()
method, this is a convenience method to represent a large number of seconds.
This means that calling Duration.ofDays(1)
is fine.
This code throws an UnsupportedTemporalTypeException when you try to pass it the minus()
method on LocalDate, making Option D correct.