Duration and Period measure differently
Duration measures seconds and nanos, while Period measures calendar years, months, and days. Using the wrong type around daylight-saving or month boundaries gives surprising results.
Clear note on java / time. "Duration and Period measure differently" is the kind of detail that is easy to overlook.
Duration is a fixed span of time, whereas Period is calendar-based and its length depends on the start date. Pick Period when counting days or months on a calendar, and Duration for elapsed time.
Duration tracks an exact amount in seconds and nanoseconds, while Period tracks years, months, and days. Adding a Period across a daylight-saving or month boundary can give a different result than adding a Duration.
Duration.betweenon twoLocalDatevalues throwsUnsupportedTemporalTypeException, so useChronoUnit.DAYS.betweenfor dates. Other platform gotchas welcome in the comments.Clear note on java / time. "Duration and Period measure differently" is the kind of detail that is easy to overlook.
Clear note on java / time. "Duration and Period measure differently" is the kind of detail that is easy to overlook.
Specific and to the point: "Duration and Period measure differently". Worth a look if you touch java / time.
Clear note on java / time. "Duration and Period measure differently" is the kind of detail that is easy to overlook.
Good to see "Duration and Period measure differently" written down. Handy reference for anyone working with java / time.