What changed, and why it matters
This commit changes how dates are displayed on the wallet's balance chart. It switches the multi-year axis label from a two-digit year (like 'Aug 24') to a four-digit year (like 'Aug 2024') and adds unit tests. There is no security relevance in the code change itself.
No security action needed. This is a UI formatting improvement with accompanying tests. Review and merge through normal quality-assurance process.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies DateAxisFormatter.java to use SimpleDateFormat pattern ‘MMM yyyy’ instead of ‘MMM yy’ for the MONTH_FORMAT used when the chart duration exceeds one year. It also introduces DateAxisFormatterTest.java with JUnit tests verifying the formatter picks the expected pattern for sub-day, sub-year, and multi-year durations, and that only every third label is rendered. No cryptographic, networking, input-validation, or privilege-related code is touched.
Changed components
src/main/java/com/sparrowwallet/sparrow/control/DateAxisFormatter.javasrc/test/java/com/sparrowwallet/sparrow/control/DateAxisFormatterTest.javaInspect captured patch +63 / −1
diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DateAxisFormatter.java b/src/main/java/com/sparrowwallet/sparrow/control/DateAxisFormatter.java
index 438c6ab..ae35d25 100644
--- a/src/main/java/com/sparrowwallet/sparrow/control/DateAxisFormatter.java
+++ b/src/main/java/com/sparrowwallet/sparrow/control/DateAxisFormatter.java
@@ -11,7 +11,7 @@ import java.util.Date;
public class DateAxisFormatter extends StringConverter<Number> {
private static final DateFormat HOUR_FORMAT = new SimpleDateFormat("HH:mm");
private static final DateFormat DAY_FORMAT = new SimpleDateFormat("d MMM");
- private static final DateFormat MONTH_FORMAT = new SimpleDateFormat("MMM yy");
+ private static final DateFormat MONTH_FORMAT = new SimpleDateFormat("MMM yyyy");
private final DateFormat dateFormat;
private int oddCounter;
diff --git a/src/test/java/com/sparrowwallet/sparrow/control/DateAxisFormatterTest.java b/src/test/java/com/sparrowwallet/sparrow/control/DateAxisFormatterTest.java
new file mode 100644
index 0000000..812c8d7
--- /dev/null
+++ b/src/test/java/com/sparrowwallet/sparrow/control/DateAxisFormatterTest.java
@@ -0,0 +1,62 @@
+package com.sparrowwallet.sparrow.control;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.TimeZone;
+
+public class DateAxisFormatterTest {
+ private static final long HOUR = 60 * 60 * 1000L;
+ private static final long DAY = 24 * HOUR;
+ private static final long YEAR = 365 * DAY;
+
+ private static String thirdLabel(DateAxisFormatter formatter, long timestamp) {
+ formatter.toString(timestamp);
+ formatter.toString(timestamp);
+ return formatter.toString(timestamp);
+ }
+
+ private static long timestamp(int year, int month, int day) {
+ Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
+ cal.clear();
+ cal.set(year, month, day);
+ return cal.getTimeInMillis();
+ }
+
+ @Test
+ public void multiYearDurationIncludesFourDigitYear() {
+ DateAxisFormatter formatter = new DateAxisFormatter(2 * YEAR);
+ String label = thirdLabel(formatter, timestamp(2024, Calendar.AUGUST, 15));
+ Assertions.assertTrue(label.matches("\\p{L}+ \\d{4}"),
+ "Expected month + 4-digit year, got: " + label);
+ Assertions.assertTrue(label.endsWith("2024"),
+ "Expected year 2024 in label, got: " + label);
+ }
+
+ @Test
+ public void subYearDurationUsesDayMonth() {
+ DateAxisFormatter formatter = new DateAxisFormatter(30 * DAY);
+ String label = thirdLabel(formatter, timestamp(2024, Calendar.AUGUST, 15));
+ Assertions.assertTrue(label.matches("\\d{1,2} \\p{L}+"),
+ "Expected day + month, got: " + label);
+ }
+
+ @Test
+ public void subDayDurationUsesHourMinute() {
+ DateAxisFormatter formatter = new DateAxisFormatter(2 * HOUR);
+ String label = thirdLabel(formatter, timestamp(2024, Calendar.AUGUST, 15));
+ Assertions.assertTrue(label.matches("\\d{2}:\\d{2}"),
+ "Expected HH:mm, got: " + label);
+ }
+
+ @Test
+ public void everyThirdLabelIsRendered() {
+ DateAxisFormatter formatter = new DateAxisFormatter(2 * YEAR);
+ long ts = timestamp(2024, Calendar.AUGUST, 15);
+ Assertions.assertEquals("", formatter.toString(ts));
+ Assertions.assertEquals("", formatter.toString(ts));
+ Assertions.assertNotEquals("", formatter.toString(ts));
+ }
+}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.