A duration is measured between local date-times, which ignore daylight saving changes and come out an hour off around them
What it finds
LocalDateTime has no time zone, so Duration.between of two of them counts wall-clock time: across a daylight saving change, the result is an hour too long or too short. Instant or ZonedDateTime count real elapsed time.
Reported is Duration.between or between of a ChronoUnit whose arguments include LocalDateTime.now(...) or a variable declared as LocalDateTime.
From the rule's source, local_time_duration.rs.
import java.time.Duration;import java.time.Instant;import java.time.LocalDateTime; class Elapsed { void run(LocalDateTime start, Instant a, Instant b) { Duration d = Duration.between(start, LocalDateTime.now());tx0 reports: daylight saving Duration e = Duration.between(a, b); }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:local-time-duration" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:local-time-duration] reason="..."tx0 explain tx0/java:local-time-duration shows the same in the terminal. Found a false positive? Report it.