java.util.Date or Calendar is used where java.time offers immutable types
What it finds
Date and Calendar are mutable, mix up dates with instants and count months from 0. java.time (Instant, LocalDate, ZonedDateTime) replaced them in Java 8 and on Android through desugaring.
From the rule's source, legacy_date_api.rs.
import java.util.Calendarimport java.util.Date fun now(): Long { val a = Date()tx0 reports: Date is a legacy date type val b = Calendar.getInstance()tx0 reports: Calendar.getInstance is a legacy date type return a.time + b.timeInMillis + java.time.Instant.now().toEpochMilli()} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:legacy-date-api" = "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/kotlin:legacy-date-api] reason="..."tx0 explain tx0/kotlin:legacy-date-api shows the same in the terminal. Found a false positive? Report it.