refactor(documents): YearMonth.from(d).toString() for density key (#385)

YearMonth.from(d).toString() emits the same canonical YYYY-MM string
as the previous String.format("%04d-%02d", …) call but reads as a
single intent-revealing expression. Existing assertions on
"1915-08", "1916-01", … pin the output format unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-08 10:51:21 +02:00
parent 360db1ae33
commit 47841b9110

View File

@@ -48,6 +48,7 @@ import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -171,8 +172,7 @@ public class DocumentService {
Map<String, Integer> counts = new java.util.TreeMap<>();
for (LocalDate d : dates) {
String month = String.format("%04d-%02d", d.getYear(), d.getMonthValue());
counts.merge(month, 1, Integer::sum);
counts.merge(YearMonth.from(d).toString(), 1, Integer::sum);
}
List<MonthBucket> buckets = counts.entrySet().stream()
.map(e -> new MonthBucket(e.getKey(), e.getValue()))