A date pattern with month and day uses Y, the week-based year, which is off by one around New Year
What it finds
new SimpleDateFormat("YYYY-MM-dd") prints the week-based year, not the calendar year: for the last days of December that fall in the first week of the next year, and the first days of January in the last week of the previous one, it is off by one. yyyy (or uuuu with DateTimeFormatter) is the calendar year.
Reported for literal patterns given to SimpleDateFormat or DateTimeFormatter.ofPattern that use Y together with a month (M) and a day of the month (d) but no week (w), outside quoted text.
From the rule's source, week_year_pattern.rs.
import java.text.SimpleDateFormat;import java.time.format.DateTimeFormatter; class Formats { SimpleDateFormat a = new SimpleDateFormat("YYYY-MM-dd");tx0 reports: Y in this pattern is the week-based year SimpleDateFormat b = new SimpleDateFormat("yyyy-MM-dd"); DateTimeFormatter c = DateTimeFormatter.ofPattern("dd.MM.YYYY HH:mm");tx0 reports: Y in this pattern DateTimeFormatter d = DateTimeFormatter.ofPattern("YYYY-'W'ww"); SimpleDateFormat e = new SimpleDateFormat("'Year' yyyy, MM/dd");} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/java:week-year-pattern" = "off"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:week-year-pattern] reason="..."tx0 explain tx0/java:week-year-pattern shows the same in the terminal. Found a false positive? Report it.