diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/formatting/TimeAmountFormatter.java b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/formatting/TimeAmountFormatter.java index 51471b492..014309a7b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/formatting/TimeAmountFormatter.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/formatting/TimeAmountFormatter.java @@ -83,7 +83,7 @@ public class TimeAmountFormatter implements Formatter { } private void appendSeconds(StringBuilder builder, long seconds, long minutes, long hours, String fHours, String fMinutes, String fSeconds) { - if (seconds != 0) { + if (seconds != 0 || fSeconds.contains(ZERO_PH)) { String s = fSeconds.replace(SECONDS_PH, String.valueOf(seconds)); if (minutes == 0 && s.contains(MINUTES_PH)) { if (hours == 0 && fMinutes.contains(HOURS_PH)) { diff --git a/Plan/src/test/java/com/djrapitops/plan/data/store/mutators/formatting/TimeAmountFormatterDefaultTest.java b/Plan/src/test/java/com/djrapitops/plan/data/store/mutators/formatting/TimeAmountFormatterDefaultTest.java new file mode 100644 index 000000000..236388d4d --- /dev/null +++ b/Plan/src/test/java/com/djrapitops/plan/data/store/mutators/formatting/TimeAmountFormatterDefaultTest.java @@ -0,0 +1,130 @@ +package com.djrapitops.plan.data.store.mutators.formatting; + +import com.djrapitops.plan.system.settings.Settings; +import com.djrapitops.plugin.api.TimeAmount; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import utilities.Teardown; + +import static org.junit.Assert.assertEquals; + +/** + * Test class for {@link TimeAmountFormatter} that checks extra zeros config example. + * + * @author Rsl1122 + */ +public class TimeAmountFormatterDefaultTest { + + private TimeAmountFormatter timeAmountFormatter; + + @BeforeClass + public static void setUpClass() { + Settings.FORMAT_YEAR.setTemporaryValue("1 year, "); + Settings.FORMAT_YEARS.setTemporaryValue("%years% years, "); + Settings.FORMAT_MONTH.setTemporaryValue("1 month, "); + Settings.FORMAT_MONTHS.setTemporaryValue("%months% months, "); + Settings.FORMAT_DAY.setTemporaryValue("1d "); + Settings.FORMAT_DAYS.setTemporaryValue("%days%d "); + Settings.FORMAT_HOURS.setTemporaryValue("%hours%h "); + Settings.FORMAT_MINUTES.setTemporaryValue("%minutes%m "); + Settings.FORMAT_SECONDS.setTemporaryValue("%seconds%s"); + Settings.FORMAT_ZERO_SECONDS.setTemporaryValue("0s"); + } + + @AfterClass + public static void tearDownClass() { + Teardown.resetSettingsTempValues(); + } + + @Before + public void setUp() { + timeAmountFormatter = new TimeAmountFormatter(); + } + + @Test + public void exampleOne() { + String expected = "1 year, 1 month, 5d 12h 30m 20s"; + + long ms = TimeAmount.DAY.ms() * 400L + + TimeAmount.HOUR.ms() * 12L + + TimeAmount.MINUTE.ms() * 30L + + TimeAmount.SECOND.ms() * 20L; + String result = timeAmountFormatter.apply(ms); + + assertEquals(expected, result); + } + + @Test + public void exampleTwo() { + String expected = "1 year, 1 month, 5d "; + + long ms = TimeAmount.DAY.ms() * 400L; + String result = timeAmountFormatter.apply(ms); + + assertEquals(expected, result); + } + + @Test + public void exampleThree() { + String expected = "12h 20s"; + + long ms = TimeAmount.HOUR.ms() * 12L + + TimeAmount.SECOND.ms() * 20L; + String result = timeAmountFormatter.apply(ms); + + assertEquals(expected, result); + } + + @Test + public void exampleFour() { + String expected = "30m "; + + long ms = TimeAmount.MINUTE.ms() * 30L; + String result = timeAmountFormatter.apply(ms); + + assertEquals(expected, result); + } + + @Test + public void exampleFive() { + String expected = "20s"; + + long ms = TimeAmount.SECOND.ms() * 20L; + String result = timeAmountFormatter.apply(ms); + + assertEquals(expected, result); + } + + @Test + public void exampleZero() { + String expected = "-"; + + long ms = 0L; + String result = timeAmountFormatter.apply(ms); + + assertEquals(expected, result); + } + + @Test + public void exampleOneSecond() { + String expected = "1s"; + + long ms = TimeAmount.SECOND.ms(); + String result = timeAmountFormatter.apply(ms); + + assertEquals(expected, result); + } + + @Test + public void exampleOneMinute() { + String expected = "1m "; + + long ms = TimeAmount.MINUTE.ms(); + String result = timeAmountFormatter.apply(ms); + + assertEquals(expected, result); + } + +} \ No newline at end of file diff --git a/Plan/src/test/java/com/djrapitops/plan/data/store/mutators/formatting/TimeAmountFormatterExtraZerosTest.java b/Plan/src/test/java/com/djrapitops/plan/data/store/mutators/formatting/TimeAmountFormatterExtraZerosTest.java index 2b1e7809b..7971d5d9f 100644 --- a/Plan/src/test/java/com/djrapitops/plan/data/store/mutators/formatting/TimeAmountFormatterExtraZerosTest.java +++ b/Plan/src/test/java/com/djrapitops/plan/data/store/mutators/formatting/TimeAmountFormatterExtraZerosTest.java @@ -58,7 +58,7 @@ public class TimeAmountFormatterExtraZerosTest { @Test public void exampleTwo() { - String expected = "1 year, 1 month, 5d "; + String expected = "1 year, 1 month, 5d 00:00:00"; long ms = TimeAmount.DAY.ms() * 400L; String result = timeAmountFormatter.apply(ms);