Question 1
Topic: Handling date, time, text, numeric and boolean values
Skill tested: Use ZonedDateTime and Duration to calculate elapsed time across a daylight-saving transition.
A scheduling service stores a departure as a ZonedDateTime in Europe/Paris and must calculate the instant exactly 24 elapsed hours later. A developer currently adds one calendar day, but a production run crossing the spring daylight-saving transition ends at a different elapsed time than required. The stored value is 2024-03-30T12:00+01:00[Europe/Paris]. The service must preserve the original time zone and represent precisely 24 hours of elapsed time, rather than the same local clock time on the next calendar date. Which implementation meets the requirement?
Duration represents an amount of elapsed time, and adding Duration.ofDays(1) advances the underlying timeline by exactly 24 hours. Across this transition the result is 2024-03-31T13:00+02:00[Europe/Paris], because the local offset changes. Period.ofDays(1) is calendar-based and preserves local calendar progression, so it does not guarantee 24 elapsed hours. LocalDateTime arithmetic likewise advances by a calendar day, and manually changing the day-of-month while retaining an offset ignores the zone rules.