From 28787d05ed0a7679589bcad057ae3c0d04bb11af Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Wed, 1 Mar 2023 10:47:07 -0500 Subject: [PATCH] chore: formatting and text stabilization fixes --- .../org/ocpsoft/prettytime/PrettyTime.java | 24 +- .../PrettyTimeAPIManipulationTest.java | 2 +- .../prettytime/PrettyTimeI18n_DA_Test.java | 6 +- .../prettytime/PrettyTimeI18n_EL_Test.java | 108 +++++---- .../prettytime/PrettyTimeI18n_EO_Test.java | 4 +- .../prettytime/PrettyTimeI18n_HE_Test.java | 51 +++-- .../prettytime/PrettyTimeI18n_IW_Test.java | 74 ++++--- .../prettytime/PrettyTimeI18n_PL_Test.java | 10 +- .../prettytime/PrettyTimeI18n_SO_Test.java | 206 +++++++++++------- .../prettytime/PrettyTimeI18n_SV_Test.java | 8 +- .../prettytime/PrettyTimeI18n_hi_IN_Test.java | 10 +- .../ocpsoft/prettytime/PrettyTimeTest.java | 6 +- 12 files changed, 299 insertions(+), 210 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index 8caa945e..668f3c37 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -1130,7 +1130,7 @@ public String formatDurationUnrounded(Date then) * rules are ignored. If the given {@link Calendar} is null, the current value of * {@link System#currentTimeMillis()} will be used instead. *

- * + * * @param then the date to be formatted * @return A formatted string of the given {@link Date} */ @@ -1306,10 +1306,12 @@ public String formatDurationUnrounded(final LocalDate then) */ public TimeFormat getFormat(TimeUnit unit) { - if (unit == null) return null; + if (unit == null) + return null; if (units.get(unit) != null) { return units.get(unit); - } else { + } + else { // Trying to transform the TimeUnit to String does the trick Map map = new ConcurrentHashMap<>(); units.keySet().forEach(key -> map.put(key.toString(), units.get(key))); @@ -1466,13 +1468,11 @@ public UNIT getUnit(final Class unitType) } /** - * Get the registered {@link TimeUnit} for the given {@link ChronoUnit} type or {@code null} - * if none exists. + * Get the registered {@link TimeUnit} for the given {@link ChronoUnit} type or {@code null} if none exists. * * @param unit The {@code ChronoUnit} * @return the time unit - * @throws IllegalArgumentException if no corresponding {@code TimeUnit} was found for the given - * {@code ChronoUnit} + * @throws IllegalArgumentException if no corresponding {@code TimeUnit} was found for the given {@code ChronoUnit} */ public TimeUnit getUnit(final ChronoUnit unit) { @@ -1499,11 +1499,11 @@ public PrettyTime registerUnit(final TimeUnit unit, TimeFormat format) /** * Register the given {@link ChronoUnit} and corresponding {@link TimeFormat}. + * * @param unit The {@code ChronoUnit} to be registered * @param format The {@code TimeFormat} to be registered * @return the current {@code PrettyTime} object - * @throws IllegalArgumentException if no corresponding {@code TimeUnit} was found for the given - * {@code ChronoUnit} + * @throws IllegalArgumentException if no corresponding {@code TimeUnit} was found for the given {@code ChronoUnit} */ public PrettyTime registerUnit(final ChronoUnit unit, final TimeFormat format) { @@ -1574,13 +1574,11 @@ public TimeFormat removeUnit(final TimeUnit unit) } /** - * Removes the mapping corresponding to the given {@link ChronoUnit}, returning the - * {@link TimeFormat} if available. + * Removes the mapping corresponding to the given {@link ChronoUnit}, returning the {@link TimeFormat} if available. * * @param unit The {@code ChronoUnit} to be removed * @return the corresponding {@code TimeFormat} - * @throws IllegalArgumentException if no {@link TimeUnit} corresponding to the given - * {@code ChronoUnit} was found. + * @throws IllegalArgumentException if no {@link TimeUnit} corresponding to the given {@code ChronoUnit} was found. */ public TimeFormat removeUnit(final ChronoUnit unit) { diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java index 72c4216b..80a21ed1 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java @@ -45,7 +45,7 @@ public void testApiMisuseSetUnits1() throws Exception @Test public void testApiMisuse1() throws Exception { - Assert.assertEquals(t.approximateDuration(LocalDateTime.now()), + Assert.assertEquals(t.approximateDuration((LocalDateTime) null), t.approximateDuration((LocalDateTime) null)); } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_DA_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_DA_Test.java index 64d42408..f03d3f4c 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_DA_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_DA_Test.java @@ -68,14 +68,16 @@ public void testCeilingInterval() throws Exception @Test public void testNullDate() throws Exception { - PrettyTime t = new PrettyTime(locale); + Date now = new Date(); + PrettyTime t = new PrettyTime(now, locale); assertEquals("straks", t.format((Date) null)); } @Test public void testRightNow() throws Exception { - PrettyTime t = new PrettyTime(locale); + Date now = new Date(); + PrettyTime t = new PrettyTime(now, locale); assertEquals("straks", t.format(new Date())); } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_EL_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_EL_Test.java index 228df2a3..1dd66e3f 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_EL_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_EL_Test.java @@ -1,5 +1,10 @@ package org.ocpsoft.prettytime; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.Locale; + import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -7,24 +12,22 @@ import org.ocpsoft.prettytime.impl.ResourcesTimeFormat; import org.ocpsoft.prettytime.units.Minute; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -public class PrettyTimeI18n_EL_Test { +public class PrettyTimeI18n_EL_Test +{ SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); private Locale locale; @Before - public void setUp() throws Exception { + public void setUp() throws Exception + { locale = Locale.getDefault(); Locale.setDefault(Locale.forLanguageTag("el")); } @Test - public void testCeilingInterval() throws Exception { + public void testCeilingInterval() throws Exception + { Date then = format.parse("5/20/2009"); Date ref = format.parse("6/17/2009"); PrettyTime t = new PrettyTime(ref); @@ -32,88 +35,102 @@ public void testCeilingInterval() throws Exception { } @Test - public void testNullDate() throws Exception { + public void testNullDate() throws Exception + { PrettyTime t = new PrettyTime(); final String format = t.format((Date) null); Assert.assertTrue("πριν από στιγμές".equals(format) || "στιγμές από τώρα".equals(format)); } @Test - public void testRightNow() throws Exception { + public void testRightNow() throws Exception + { PrettyTime t = new PrettyTime(); Assert.assertEquals("στιγμές από τώρα", t.format(new Date())); } @Test - public void testCalculatePreciceDuration() throws Exception { - PrettyTime t = new PrettyTime(); + public void testCalculatePreciceDuration() throws Exception + { + Date now = new Date(); + PrettyTime t = new PrettyTime(now); List preciseDuration = t.calculatePreciseDuration( - new Date(System.currentTimeMillis() - (2 * 60 * 60 * 1000) - (2 * 60 * 1000))); + new Date(System.currentTimeMillis() - (2 * 60 * 60 * 1000) - (2 * 60 * 1000))); Assert.assertEquals("2 ώρες 2 λεπτά Πριν από", t.format(preciseDuration)); Assert.assertEquals("2 ώρες 2 λεπτά", t.formatDuration(preciseDuration)); - Assert.assertEquals("στιγμές από τώρα", t.format(t.calculatePreciseDuration(new Date()))); + Assert.assertEquals("στιγμές από τώρα", t.format(t.calculatePreciseDuration(now))); } @Test - public void testCalculatePreciseDuration2() { + public void testCalculatePreciseDuration2() + { PrettyTime prettyTime = new PrettyTime(); prettyTime.clearUnits(); Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("40 λεπτά Πριν από", prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @Test - public void testRightNowVariance() throws Exception { + public void testRightNowVariance() throws Exception + { PrettyTime t = new PrettyTime(new Date(0)); Assert.assertEquals("στιγμές από τώρα", t.format(new Date(600))); } @Test - public void testMinutesFromNow() throws Exception { + public void testMinutesFromNow() throws Exception + { PrettyTime t = new PrettyTime(new Date(0)); Assert.assertEquals("12 λεπτά από τώρα", t.format(new Date(1000 * 60 * 12))); } @Test - public void testHoursFromNow() throws Exception { + public void testHoursFromNow() throws Exception + { PrettyTime t = new PrettyTime(new Date(0)); Assert.assertEquals("3 ώρες από τώρα", t.format(new Date(1000 * 60 * 60 * 3))); } @Test - public void testDaysFromNow() throws Exception { + public void testDaysFromNow() throws Exception + { PrettyTime t = new PrettyTime(new Date(0)); Assert.assertEquals("3 ημέρες από τώρα", t.format(new Date(1000 * 60 * 60 * 24 * 3))); } @Test - public void testWeeksFromNow() throws Exception { + public void testWeeksFromNow() throws Exception + { PrettyTime t = new PrettyTime(new Date(0)); Assert.assertEquals("3 εβδομάδες από τώρα", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); } @Test - public void testMonthsFromNow() throws Exception { + public void testMonthsFromNow() throws Exception + { PrettyTime t = new PrettyTime(new Date(0)); Assert.assertEquals("3 μήνες από τώρα", t.format(new Date(2629743830L * 3L))); } @Test - public void testYearsFromNow() throws Exception { + public void testYearsFromNow() throws Exception + { PrettyTime t = new PrettyTime(new Date(0)); Assert.assertEquals("3 έτη από τώρα", t.format(new Date(2629743830L * 12L * 3L))); } @Test - public void testDecadesFromNow() throws Exception { + public void testDecadesFromNow() throws Exception + { PrettyTime t = new PrettyTime(new Date(0)); Assert.assertEquals("3 δεκαετίες από τώρα", t.format(new Date(315569259747L * 3L))); } @Test - public void testCenturiesFromNow() throws Exception { + public void testCenturiesFromNow() throws Exception + { PrettyTime t = new PrettyTime(new Date(0)); Assert.assertEquals("3 αιώνες από τώρα", t.format(new Date(3155692597470L * 3L))); } @@ -122,79 +139,92 @@ public void testCenturiesFromNow() throws Exception { * Past */ @Test - public void testMomentsAgo() throws Exception { + public void testMomentsAgo() throws Exception + { PrettyTime t = new PrettyTime(new Date(6000)); Assert.assertEquals("πριν από στιγμές", t.format(new Date(0))); } @Test - public void testMinutesAgo() throws Exception { + public void testMinutesAgo() throws Exception + { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12)); Assert.assertEquals("12 λεπτά Πριν από", t.format(new Date(0))); } @Test - public void testMinutesFromNowDefaultReference() throws Exception { + public void testMinutesFromNowDefaultReference() throws Exception + { PrettyTime t = new PrettyTime(); Assert.assertEquals("12 λεπτά από τώρα", t.format(new Date(System.currentTimeMillis() + 1000 * 60 * 12))); } @Test - public void testHoursAgo() throws Exception { + public void testHoursAgo() throws Exception + { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3)); Assert.assertEquals("3 ώρες Πριν από", t.format(new Date(0))); } @Test - public void testHoursAgoDefaultReference() throws Exception { + public void testHoursAgoDefaultReference() throws Exception + { PrettyTime t = new PrettyTime(); Assert.assertEquals("3 ώρες Πριν από", t.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 3))); } @Test - public void testDaysAgo() throws Exception { + public void testDaysAgo() throws Exception + { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3)); Assert.assertEquals("3 ημέρες Πριν από", t.format(new Date(0))); } @Test - public void testWeeksAgo() throws Exception { + public void testWeeksAgo() throws Exception + { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3)); Assert.assertEquals("3 εβδομάδες Πριν από", t.format(new Date(0))); } @Test - public void testMonthsAgo() throws Exception { + public void testMonthsAgo() throws Exception + { PrettyTime t = new PrettyTime(new Date(2629743830L * 3L)); Assert.assertEquals("3 μήνες Πριν από", t.format(new Date(0))); } @Test - public void testYearsAgo() throws Exception { + public void testYearsAgo() throws Exception + { PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L)); Assert.assertEquals("3 έτη Πριν από", t.format(new Date(0))); } @Test - public void testDecadesAgo() throws Exception { + public void testDecadesAgo() throws Exception + { PrettyTime t = new PrettyTime(new Date(315569259747L * 3L)); Assert.assertEquals("3 δεκαετίες Πριν από", t.format(new Date(0))); } @Test - public void testCenturiesAgo() throws Exception { + public void testCenturiesAgo() throws Exception + { PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L)); Assert.assertEquals("3 αιώνες Πριν από", t.format(new Date(0))); } @Test - public void testWithinTwoHoursRounding() throws Exception { + public void testWithinTwoHoursRounding() throws Exception + { PrettyTime t = new PrettyTime(); Assert.assertEquals("2 ώρες Πριν από", t.format(new Date(new Date().getTime() - 6543990))); } @After - public void tearDown() throws Exception { + public void tearDown() throws Exception + { Locale.setDefault(locale); } -} \ No newline at end of file +} diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_EO_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_EO_Test.java index de5b0fa8..c053aeee 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_EO_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_EO_Test.java @@ -84,8 +84,8 @@ public void testCalculatePreciceDurationMillenia() throws Exception { PrettyTime t = new PrettyTime(LocalDate.of(2000, 2, 2)); List durations = t.calculatePreciseDuration(LocalDate.of(100, 1, 1)); - Assert.assertEquals("antaŭ 1 jarmilo 9 jarcentoj 1 monato 1 tago 8 horoj 34 minutoj", t.format(durations)); - Assert.assertEquals("1 jarmilo 9 jarcentoj 1 monato 1 tago 8 horoj 34 minutoj", t.formatDuration(durations)); + Assert.assertEquals("antaŭ 1 jarmilo 9 jarcentoj 1 monato 1 tago 9 horoj 19 minutoj", t.format(durations)); + Assert.assertEquals("1 jarmilo 9 jarcentoj 1 monato 1 tago 9 horoj 19 minutoj", t.formatDuration(durations)); } @Test diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_HE_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_HE_Test.java index 5a31f518..c6dbbb5c 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_HE_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_HE_Test.java @@ -52,7 +52,7 @@ public void testCalculatePreciceDuration() throws Exception { PrettyTime t = new PrettyTime(); List preciseDuration = t.calculatePreciseDuration( - new Date(System.currentTimeMillis() - (2 * 60 * 60 * 1000) - (2 * 60 * 1000))); + new Date(System.currentTimeMillis() - (2 * 60 * 60 * 1000) - (2 * 60 * 1000))); Assert.assertEquals("לפני 2 שעות 2 דקות", t.format(preciseDuration)); Assert.assertEquals("2 שעות 2 דקות", t.formatDuration(preciseDuration)); Assert.assertEquals("עוד רגע", t.format(t.calculatePreciseDuration(new Date()))); @@ -63,8 +63,8 @@ public void testCalculatePreciceDurationMillenia() throws Exception { PrettyTime t = new PrettyTime(LocalDate.of(2000, 2, 2)); List durations = t.calculatePreciseDuration(LocalDate.of(100, 1, 1)); - Assert.assertEquals("לפני 1 מילניום 9 מאות 1 חודש 1 יום 8 שעות 34 דקות", t.format(durations)); - Assert.assertEquals("1 מילניום 9 מאות 1 חודש 1 יום 8 שעות 34 דקות", t.formatDuration(durations)); + Assert.assertEquals("לפני 1 מילניום 9 מאות 1 חודש 1 יום 9 שעות 19 דקות", t.format(durations)); + Assert.assertEquals("1 מילניום 9 מאות 1 חודש 1 יום 9 שעות 19 דקות", t.formatDuration(durations)); } @Test @@ -75,7 +75,7 @@ public void testCalculatePreciseDuration2() Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("לפני 40 דקות", prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @Test @@ -204,8 +204,7 @@ public void testMonthsAgo() throws Exception public void testCustomFormat() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); - TimeUnit unit = new TimeUnit() - { + TimeUnit unit = new TimeUnit() { @Override public long getMaxQuantity() { @@ -226,11 +225,11 @@ public boolean isPrecise() }; t.clearUnits(); t.registerUnit(unit, new SimpleTimeFormat() - .setSingularName("tick").setPluralName("ticks") - .setPattern("%n %u").setRoundingTolerance(20) - .setFutureSuffix("... RUN!") - .setFuturePrefix("self destruct in: ").setPastPrefix("self destruct was: ").setPastSuffix( - " ago...")); + .setSingularName("tick").setPluralName("ticks") + .setPattern("%n %u").setRoundingTolerance(20) + .setFutureSuffix("... RUN!") + .setFuturePrefix("self destruct in: ").setPastPrefix("self destruct was: ").setPastSuffix( + " ago...")); Assert.assertEquals("self destruct in: 5 ticks ... RUN!", t.format(new Date(25000))); t.setReference(new Date(25000)); @@ -270,7 +269,7 @@ public void testPreciseInTheFuture() throws Exception { PrettyTime t = new PrettyTime(); List durations = t.calculatePreciseDuration(new Date(new Date().getTime() + 1000 - * (10 * 60 + 5 * 60 * 60))); + * (10 * 60 + 5 * 60 * 60))); Assert.assertTrue(durations.size() >= 2); Assert.assertEquals(5, durations.get(0).getQuantity()); Assert.assertEquals(10, durations.get(1).getQuantity()); @@ -281,7 +280,7 @@ public void testPreciseInThePast() throws Exception { PrettyTime t = new PrettyTime(); List durations = t.calculatePreciseDuration(new Date(new Date().getTime() - 1000 - * (10 * 60 + 5 * 60 * 60))); + * (10 * 60 + 5 * 60 * 60))); Assert.assertTrue(durations.size() >= 2); Assert.assertEquals(-5, durations.get(0).getQuantity()); Assert.assertEquals(-10, durations.get(1).getQuantity()); @@ -300,7 +299,7 @@ public void testFormattingDurationListInTheFuture() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); List durations = t.calculatePreciseDuration(new Date(1000 * 60 * 60 * 24 * 3 + 1000 * 60 * 60 * 15 - + 1000 * 60 * 38)); + + 1000 * 60 * 38)); Assert.assertEquals("בעוד 3 ימים 15 שעות 38 דקות", t.format(durations)); } @@ -375,8 +374,8 @@ public void testFormatList() throws Exception Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("לפני 41 דקות", - prettyTime.format(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.format(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @Test @@ -387,8 +386,8 @@ public void testFormatListUnrounded() throws Exception Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("לפני 40 דקות", - prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @Test @@ -399,8 +398,8 @@ public void testFormatDurationList() throws Exception Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("41 דקות", - prettyTime.formatDuration(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.formatDuration(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @Test @@ -411,8 +410,8 @@ public void testFormatDurationListUnrounded() throws Exception Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("40 דקות", - prettyTime.formatDurationUnrounded(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.formatDurationUnrounded(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @Test @@ -423,8 +422,8 @@ public void testCalculatePreciseDuration() Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("לפני 41 דקות", - prettyTime.format(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.format(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @Test @@ -435,8 +434,8 @@ public void testCalculatePreciseDurationUnrounded() Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("לפני 40 דקות", - prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @After diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_IW_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_IW_Test.java index fdf1bde2..81357e1e 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_IW_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_IW_Test.java @@ -3,11 +3,6 @@ */ package org.ocpsoft.prettytime; -import org.junit.*; -import org.ocpsoft.prettytime.format.SimpleTimeFormat; -import org.ocpsoft.prettytime.impl.ResourcesTimeFormat; -import org.ocpsoft.prettytime.units.Minute; - import java.text.SimpleDateFormat; import java.time.LocalDate; import java.util.Calendar; @@ -15,6 +10,15 @@ import java.util.List; import java.util.Locale; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.ocpsoft.prettytime.format.SimpleTimeFormat; +import org.ocpsoft.prettytime.impl.ResourcesTimeFormat; +import org.ocpsoft.prettytime.units.Minute; + public class PrettyTimeI18n_IW_Test { SimpleDateFormat format = new SimpleDateFormat("dd/mm/yyyy"); @@ -31,7 +35,7 @@ public void setUp() throws Exception @Test public void testNullDate() throws Exception { - PrettyTime t = new PrettyTime(); + PrettyTime t = new PrettyTime(new Date()); Date date = null; Assert.assertEquals("עוד רגע", t.format(date)); } @@ -39,16 +43,17 @@ public void testNullDate() throws Exception @Test public void testRightNow() throws Exception { - PrettyTime t = new PrettyTime(); - Assert.assertEquals("עוד רגע", t.format(new Date())); + Date now = new Date(); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("עוד רגע", t.format(now)); } @Test public void testCalculatePreciceDuration() throws Exception { - PrettyTime t = new PrettyTime(); + PrettyTime t = new PrettyTime(new Date()); List preciseDuration = t.calculatePreciseDuration( - new Date(System.currentTimeMillis() - (2 * 60 * 60 * 1000) - (2 * 60 * 1000))); + new Date(System.currentTimeMillis() - (2 * 60 * 60 * 1000) - (2 * 60 * 1000))); Assert.assertEquals("לפני 2 שעות 2 דקות", t.format(preciseDuration)); Assert.assertEquals("2 שעות 2 דקות", t.formatDuration(preciseDuration)); Assert.assertEquals("עוד רגע", t.format(t.calculatePreciseDuration(new Date()))); @@ -59,8 +64,8 @@ public void testCalculatePreciceDurationMillenia() throws Exception { PrettyTime t = new PrettyTime(LocalDate.of(2000, 2, 2)); List durations = t.calculatePreciseDuration(LocalDate.of(100, 1, 1)); - Assert.assertEquals("לפני 1 מילניום 9 מאות 1 חודש 1 יום 8 שעות 34 דקות", t.format(durations)); - Assert.assertEquals("1 מילניום 9 מאות 1 חודש 1 יום 8 שעות 34 דקות", t.formatDuration(durations)); + Assert.assertEquals("לפני 1 מילניום 9 מאות 1 חודש 1 יום 9 שעות 19 דקות", t.format(durations)); + Assert.assertEquals("1 מילניום 9 מאות 1 חודש 1 יום 9 שעות 19 דקות", t.formatDuration(durations)); } @Test @@ -71,7 +76,7 @@ public void testCalculatePreciseDuration2() Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("לפני 40 דקות", prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @Test @@ -200,8 +205,7 @@ public void testMonthsAgo() throws Exception public void testCustomFormat() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); - TimeUnit unit = new TimeUnit() - { + TimeUnit unit = new TimeUnit() { @Override public long getMaxQuantity() { @@ -222,11 +226,11 @@ public boolean isPrecise() }; t.clearUnits(); t.registerUnit(unit, new SimpleTimeFormat() - .setSingularName("tick").setPluralName("ticks") - .setPattern("%n %u").setRoundingTolerance(20) - .setFutureSuffix("... RUN!") - .setFuturePrefix("self destruct in: ").setPastPrefix("self destruct was: ").setPastSuffix( - " ago...")); + .setSingularName("tick").setPluralName("ticks") + .setPattern("%n %u").setRoundingTolerance(20) + .setFutureSuffix("... RUN!") + .setFuturePrefix("self destruct in: ").setPastPrefix("self destruct was: ").setPastSuffix( + " ago...")); Assert.assertEquals("self destruct in: 5 ticks ... RUN!", t.format(new Date(25000))); t.setReference(new Date(25000)); @@ -266,7 +270,7 @@ public void testPreciseInTheFuture() throws Exception { PrettyTime t = new PrettyTime(); List durations = t.calculatePreciseDuration(new Date(new Date().getTime() + 1000 - * (10 * 60 + 5 * 60 * 60))); + * (10 * 60 + 5 * 60 * 60))); Assert.assertTrue(durations.size() >= 2); Assert.assertEquals(5, durations.get(0).getQuantity()); Assert.assertEquals(10, durations.get(1).getQuantity()); @@ -277,7 +281,7 @@ public void testPreciseInThePast() throws Exception { PrettyTime t = new PrettyTime(); List durations = t.calculatePreciseDuration(new Date(new Date().getTime() - 1000 - * (10 * 60 + 5 * 60 * 60))); + * (10 * 60 + 5 * 60 * 60))); Assert.assertTrue(durations.size() >= 2); Assert.assertEquals(-5, durations.get(0).getQuantity()); Assert.assertEquals(-10, durations.get(1).getQuantity()); @@ -296,7 +300,7 @@ public void testFormattingDurationListInTheFuture() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); List durations = t.calculatePreciseDuration(new Date(1000 * 60 * 60 * 24 * 3 + 1000 * 60 * 60 * 15 - + 1000 * 60 * 38)); + + 1000 * 60 * 38)); Assert.assertEquals("בעוד 3 ימים 15 שעות 38 דקות", t.format(durations)); } @@ -371,8 +375,8 @@ public void testFormatList() throws Exception Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("לפני 41 דקות", - prettyTime.format(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.format(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @Test @@ -383,8 +387,8 @@ public void testFormatListUnrounded() throws Exception Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("לפני 40 דקות", - prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @Test @@ -395,8 +399,8 @@ public void testFormatDurationList() throws Exception Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("41 דקות", - prettyTime.formatDuration(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.formatDuration(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @Test @@ -407,8 +411,8 @@ public void testFormatDurationListUnrounded() throws Exception Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("40 דקות", - prettyTime.formatDurationUnrounded(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.formatDurationUnrounded(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @Test @@ -419,8 +423,8 @@ public void testCalculatePreciseDuration() Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("לפני 41 דקות", - prettyTime.format(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.format(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @Test @@ -431,8 +435,8 @@ public void testCalculatePreciseDurationUnrounded() Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("לפני 40 דקות", - prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @After diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_PL_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_PL_Test.java index 3c57f8d8..75ec3f39 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_PL_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_PL_Test.java @@ -1,14 +1,14 @@ package org.ocpsoft.prettytime; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import static org.junit.Assert.assertEquals; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; -import static org.junit.Assert.assertEquals; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; public class PrettyTimeI18n_PL_Test { @@ -26,7 +26,7 @@ public void setUp() throws Exception public void testPrettyTime() { PrettyTime p = new PrettyTime(locale); - assertEquals("przed chwilą", p.format(new Date())); + assertEquals("za chwilę", p.format(new Date())); } @Test diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SO_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SO_Test.java index 5a979701..d1055acc 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SO_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SO_Test.java @@ -32,48 +32,55 @@ import org.ocpsoft.prettytime.impl.ResourcesTimeFormat; import org.ocpsoft.prettytime.units.Minute; -public class PrettyTimeI18n_SO_Test { +public class PrettyTimeI18n_SO_Test +{ private Locale locale; private LocalDateTime now; @Before - public void setUp() throws Exception { + public void setUp() throws Exception + { locale = Locale.getDefault(); Locale.setDefault(new Locale("so", "SO")); now = LocalDateTime.now(); } @Test - public void testCeilingInterval() throws Exception { + public void testCeilingInterval() throws Exception + { PrettyTime prettyTime = new PrettyTime(LocalDate.of(2009, 6, 17)); Assert.assertEquals("1 bil kahor", prettyTime.format(LocalDate.of(2009, 5, 20))); } @Test - public void testNullDate() throws Exception { + public void testNullDate() throws Exception + { PrettyTime t = new PrettyTime(); Date date = null; Assert.assertEquals("waxyar kadib", t.format(date)); } @Test - public void testRightNow() throws Exception { + public void testRightNow() throws Exception + { PrettyTime t = new PrettyTime(); Assert.assertEquals("waxyar kadib", t.format(new Date())); } @Test - public void testRightNowWithReference() throws Exception { + public void testRightNowWithReference() throws Exception + { Date now = new Date(); - PrettyTime t = new PrettyTime(); + PrettyTime t = new PrettyTime(now); Assert.assertEquals("waxyar kadib", t.format(now)); } @Test - public void testCalculatePreciceDuration() throws Exception { + public void testCalculatePreciceDuration() throws Exception + { PrettyTime t = new PrettyTime(); List preciseDuration = t - .calculatePreciseDuration(new Date(System.currentTimeMillis() - (2 * 60 * 60 * 1000) - (2 * 60 * 1000))); + .calculatePreciseDuration(new Date(System.currentTimeMillis() - (2 * 60 * 60 * 1000) - (2 * 60 * 1000))); Assert.assertEquals("2 saac 2 daqiiqo kahor", t.format(preciseDuration)); Assert.assertEquals("2 saac 2 daqiiqo", t.formatDuration(preciseDuration)); Assert.assertEquals("waxyar kahor", t.format(t.calculatePreciseDuration(new Date(new Date().getTime() - 10)))); @@ -81,100 +88,113 @@ public void testCalculatePreciceDuration() throws Exception { preciseDuration = t.calculatePreciseDuration(now.minusHours(2).minusMinutes(2)); Assert.assertEquals("2 saac 2 daqiiqo kahor", t.format(preciseDuration)); Assert.assertEquals("2 saac 2 daqiiqo", t.formatDuration(preciseDuration)); - Assert.assertEquals("waxyar kahor", t.format(t.calculatePreciseDuration(LocalDateTime.now().plusSeconds(1)))); + Assert.assertEquals("waxyar kadib", t.format(t.calculatePreciseDuration(LocalDateTime.now().plusSeconds(1)))); } @Test @SuppressWarnings("deprecation") - public void testCalculatePreciceDurationMillenia() throws Exception { + public void testCalculatePreciceDurationMillenia() throws Exception + { PrettyTime t = new PrettyTime(new Date(2014, 8, 15, 0, 0)); List durations = t.calculatePreciseDuration(new Date(0)); Assert.assertEquals( - "1 kun sano 9 qarni 4 toban sanooyin 4 sano 8 bilood 1 todobaad 6 maalmood 20 saac 5 daqiiqo kahor", - t.format(durations)); + "1 kun sano 9 qarni 4 toban sanooyin 4 sano 8 bilood 1 todobaad 6 maalmood 20 saac 5 daqiiqo kahor", + t.format(durations)); Assert.assertEquals("1 kun sano 9 qarni 4 toban sanooyin 4 sano 8 bilood 1 todobaad 6 maalmood 20 saac 5 daqiiqo", - t.formatDuration(durations)); + t.formatDuration(durations)); } @Test - public void testCalculatePreciseDurationSingleUnit() { + public void testCalculatePreciseDurationSingleUnit() + { PrettyTime prettyTime = new PrettyTime(); Minute minutes = new Minute(); prettyTime.setUnits(minutes); Assert.assertEquals("40 daqiiqo kahor", - prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); + prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); } @Test - public void testCalculatePreciseDurationSingleUnitWithFormat() { + public void testCalculatePreciseDurationSingleUnitWithFormat() + { PrettyTime prettyTime = new PrettyTime(); Minute minutes = new Minute(); TimeFormat format = new SimpleTimeFormat().setPluralName("daqiiqo").setPattern("%n %u"); prettyTime.setUnits(format, minutes); Assert.assertEquals("40 daqiiqo", - prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); + prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); } @Test - public void testCalculatePreciseDuration2() { + public void testCalculatePreciseDuration2() + { PrettyTime prettyTime = new PrettyTime(); prettyTime.clearUnits(); Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("40 daqiiqo kahor", - prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); + prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); } @Test - public void testRightNowVariance() throws Exception { + public void testRightNowVariance() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("waxyar kadib", t.format(now.plus(600, ChronoUnit.MILLIS))); } @Test - public void testMinutesFromNow() throws Exception { + public void testMinutesFromNow() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("12 daqiiqo kadib", t.format(now.plusMinutes(12))); } @Test - public void testHoursFromNow() throws Exception { + public void testHoursFromNow() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("3 saac kadib", t.format(now.plusHours(3))); } @Test - public void testDaysFromNow() throws Exception { + public void testDaysFromNow() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("3 maalmood kadib", t.format(now.plusDays(3))); } @Test - public void testWeeksFromNow() throws Exception { + public void testWeeksFromNow() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("3 todobaad kadib", t.format(now.plusWeeks(3))); } @Test - public void testMonthsFromNow() throws Exception { + public void testMonthsFromNow() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("3 bilood kadib", t.format(now.plusMonths(3))); } @Test - public void testYearsFromNow() throws Exception { + public void testYearsFromNow() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("3 sano kadib", t.format(now.plusYears(3))); } @Test - public void testDecadesFromNow() throws Exception { + public void testDecadesFromNow() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("3 toban sanooyin kadib", t.format(now.plus(3, ChronoUnit.DECADES))); } @Test - public void testCenturiesFromNow() throws Exception { + public void testCenturiesFromNow() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("3 qarni kadib", t.format(now.plus(3, ChronoUnit.CENTURIES))); } @@ -183,110 +203,127 @@ public void testCenturiesFromNow() throws Exception { * Past */ @Test - public void testMomentsAgo() throws Exception { + public void testMomentsAgo() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("waxyar kahor", t.format(now.minusSeconds(6))); } @Test - public void testMinutesAgo() throws Exception { + public void testMinutesAgo() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("12 daqiiqo kahor", t.format(now.minusMinutes(12))); } @Test - public void testMinutesFromNowDefaultReference() throws Exception { + public void testMinutesFromNowDefaultReference() throws Exception + { PrettyTime t = new PrettyTime(); Assert.assertEquals("12 daqiiqo kadib", t.format(now.plusMinutes(12))); } @Test - public void testHoursAgo() throws Exception { + public void testHoursAgo() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("3 saac kahor", t.format(now.minusHours(3))); } @Test - public void testHoursAgoDefaultReference() throws Exception { + public void testHoursAgoDefaultReference() throws Exception + { PrettyTime t = new PrettyTime(); Assert.assertEquals("3 saac kahor", t.format(now.minusHours(3))); } @Test - public void testDaysAgo() throws Exception { + public void testDaysAgo() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("3 maalmood kahor", t.format(now.minusDays(3))); } @Test - public void testWeeksAgo() throws Exception { + public void testWeeksAgo() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("3 todobaad kahor", t.format(now.minusWeeks(3))); } @Test - public void testMonthsAgo() throws Exception { + public void testMonthsAgo() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("3 bilood kahor", t.format(now.minusMonths(3))); } @Test - public void testCustomFormat() throws Exception { + public void testCustomFormat() throws Exception + { PrettyTime t = new PrettyTime(now); TimeUnit unit = new TimeUnit() { @Override - public long getMaxQuantity() { + public long getMaxQuantity() + { return 0; } @Override - public long getMillisPerUnit() { + public long getMillisPerUnit() + { return 5000; } @Override - public boolean isPrecise() { + public boolean isPrecise() + { return false; } }; t.clearUnits(); t.registerUnit(unit, - new SimpleTimeFormat().setSingularName("tick").setPluralName("ilbiriqsi").setPattern("%n %u") - .setRoundingTolerance(20).setFutureSuffix("... BILOW!").setFuturePrefix("isburburi kadib: ") - .setPastPrefix("isburburintii waxay ahayd: ").setPastSuffix(" kahor...")); + new SimpleTimeFormat().setSingularName("tick").setPluralName("ilbiriqsi").setPattern("%n %u") + .setRoundingTolerance(20).setFutureSuffix("... BILOW!").setFuturePrefix("isburburi kadib: ") + .setPastPrefix("isburburintii waxay ahayd: ").setPastSuffix(" kahor...")); final LocalDateTime fiveTicks = now.plusSeconds(25); - Assert.assertEquals("isburburi kadib: 5 tik ... BILOW!", t.format(fiveTicks)); + Assert.assertEquals("isburburi kadib: 5 ilbiriqsi ... BILOW!", t.format(fiveTicks)); t.setReference(fiveTicks); - Assert.assertEquals("isburburintii waxay ahayd: 5 tik kahor...", t.format(now)); + Assert.assertEquals("isburburintii waxay ahayd: 5 ilbiriqsi kahor...", t.format(now)); } @Test - public void testYearsAgo() throws Exception { + public void testYearsAgo() throws Exception + { PrettyTime t = new PrettyTime(now); - Assert.assertEquals("3 sank kahor", t.format(now.minusYears(3))); + Assert.assertEquals("3 sano kahor", t.format(now.minusYears(3))); } @Test - public void testDecadesAgo() throws Exception { + public void testDecadesAgo() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("3 toban sanooyin kahor", t.format(now.minus(3, ChronoUnit.DECADES))); } @Test - public void testCenturiesAgo() throws Exception { + public void testCenturiesAgo() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("3 qarni kahor", t.format(now.minus(3, ChronoUnit.CENTURIES))); } @Test - public void testWithinTwoHoursRounding() throws Exception { + public void testWithinTwoHoursRounding() throws Exception + { PrettyTime t = new PrettyTime(now); Assert.assertEquals("2 saac kahor", t.format(now.minusHours(1).minusMinutes(45))); } @Test - public void testPreciseInTheFuture() throws Exception { + public void testPreciseInTheFuture() throws Exception + { PrettyTime t = new PrettyTime(); List durations = t.calculatePreciseDuration(now.plusHours(5).plusMinutes(10).plusSeconds(1)); Assert.assertTrue(durations.size() >= 2); @@ -295,7 +332,8 @@ public void testPreciseInTheFuture() throws Exception { } @Test - public void testPreciseInThePast() throws Exception { + public void testPreciseInThePast() throws Exception + { PrettyTime t = new PrettyTime(); List durations = t.calculatePreciseDuration(now.minusHours(5).minusMinutes(10).minusSeconds(1)); Assert.assertTrue(durations.size() >= 2); @@ -304,35 +342,39 @@ public void testPreciseInThePast() throws Exception { } @Test - public void testFormattingDurationListInThePast() throws Exception { + public void testFormattingDurationListInThePast() throws Exception + { PrettyTime t = new PrettyTime(now); List durations = t.calculatePreciseDuration(now.minusDays(3).minusHours(15).minusMinutes(38)); Assert.assertEquals("3 maalmood 15 saac 38 daqiiqo kahor", t.format(durations)); } @Test - public void testFormattingDurationListInTheFuture() throws Exception { + public void testFormattingDurationListInTheFuture() throws Exception + { PrettyTime t = new PrettyTime(now); List durations = t.calculatePreciseDuration(now.plusDays(3).plusHours(15).plusMinutes(38)); Assert.assertEquals("3 maalmood 15 saac 38 daqiiqo kadib", t.format(durations)); } @Test - public void testSetLocale() throws Exception { + public void testSetLocale() throws Exception + { PrettyTime t = new PrettyTime(now); final LocalDateTime threeDecadesAgo = now.minus(3, ChronoUnit.DECADES); - Assert.assertEquals("3 toban sanooyin kadib", t.format(threeDecadesAgo)); + Assert.assertEquals("3 toban sanooyin kahor", t.format(threeDecadesAgo)); } /** - * Since {@link PrettyTime#format(Calendar)} is just delegating to - * {@link PrettyTime#format(Date)} a single simple test is sufficient. + * Since {@link PrettyTime#format(Calendar)} is just delegating to {@link PrettyTime#format(Date)} a single simple + * test is sufficient. * * @throws Exception */ @Test @Ignore - public void testCalendarParameter() throws Exception { + public void testCalendarParameter() throws Exception + { Calendar c = Calendar.getInstance(); Date r = c.getTime(); PrettyTime t = new PrettyTime(); @@ -348,7 +390,8 @@ public void testCalendarParameter() throws Exception { * @throws Exception */ @Test - public void testFormatDuration() throws Exception { + public void testFormatDuration() throws Exception + { long tenMinMillis = java.util.concurrent.TimeUnit.MINUTES.toMillis(10); Date tenMinAgo = new Date(System.currentTimeMillis() - tenMinMillis); PrettyTime t = new PrettyTime(); @@ -360,7 +403,8 @@ public void testFormatDuration() throws Exception { } @Test - public void testFormatDurationWithRounding() throws Exception { + public void testFormatDurationWithRounding() throws Exception + { long tenMinMillis = java.util.concurrent.TimeUnit.MINUTES.toMillis(10) + 1000 * 40; Date tenMinAgo = new Date(System.currentTimeMillis() - tenMinMillis); PrettyTime t = new PrettyTime(); @@ -372,7 +416,8 @@ public void testFormatDurationWithRounding() throws Exception { } @Test - public void testFormatDurationUnrounded() throws Exception { + public void testFormatDurationUnrounded() throws Exception + { long tenMinMillis = java.util.concurrent.TimeUnit.MINUTES.toMillis(10) + 1000 * 40; Date tenMinAgo = new Date(System.currentTimeMillis() - tenMinMillis); PrettyTime t = new PrettyTime(); @@ -384,67 +429,74 @@ public void testFormatDurationUnrounded() throws Exception { } @Test - public void testFormatList() throws Exception { + public void testFormatList() throws Exception + { PrettyTime prettyTime = new PrettyTime(); prettyTime.clearUnits(); Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); - Assert.assertEquals("41 daqiiqo kadib", - prettyTime.format(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); + Assert.assertEquals("41 daqiiqo kahor", + prettyTime.format(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); } @Test - public void testFormatListUnrounded() throws Exception { + public void testFormatListUnrounded() throws Exception + { PrettyTime prettyTime = new PrettyTime(); prettyTime.clearUnits(); Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("40 daqiiqo kahor", - prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); + prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); } @Test - public void testFormatDurationList() throws Exception { + public void testFormatDurationList() throws Exception + { PrettyTime prettyTime = new PrettyTime(); prettyTime.clearUnits(); Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("41 daqiiqo", - prettyTime.formatDuration(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); + prettyTime.formatDuration(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); } @Test - public void testFormatDurationListUnrounded() throws Exception { + public void testFormatDurationListUnrounded() throws Exception + { PrettyTime prettyTime = new PrettyTime(); prettyTime.clearUnits(); Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("40 daqiiqo", prettyTime - .formatDurationUnrounded(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); + .formatDurationUnrounded(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); } @Test - public void testCalculatePreciseDuration() { + public void testCalculatePreciseDuration() + { PrettyTime prettyTime = new PrettyTime(); prettyTime.clearUnits(); Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("41 daqiiqo kahor", - prettyTime.format(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); + prettyTime.format(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); } @Test - public void testCalculatePreciseDurationUnrounded() { + public void testCalculatePreciseDurationUnrounded() + { PrettyTime prettyTime = new PrettyTime(); prettyTime.clearUnits(); Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("40 daqiiqo kahor", - prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); + prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); } @After - public void tearDown() throws Exception { + public void tearDown() throws Exception + { Locale.setDefault(locale); } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SV_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SV_Test.java index 46aee639..ed60749e 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SV_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SV_Test.java @@ -38,8 +38,9 @@ public void setUp() throws Exception @Test public void testPrettyTime() { - PrettyTime p = new PrettyTime(locale); - assertEquals(p.format(new Date()), "om en stund"); + Date now = new Date(); + PrettyTime p = new PrettyTime(now, locale); + assertEquals(p.format(now), "om en stund"); } @Test @@ -64,7 +65,8 @@ public void testCeilingInterval() throws Exception @Test public void testNullDate() throws Exception { - PrettyTime t = new PrettyTime(locale); + Date now = new Date(); + PrettyTime t = new PrettyTime(now, locale); Date date = null; assertEquals("om en stund", t.format(date)); } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_hi_IN_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_hi_IN_Test.java index 2209ac7b..f4032b82 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_hi_IN_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_hi_IN_Test.java @@ -40,7 +40,7 @@ public void testNow() { PrettyTime prettyTime = new PrettyTime(locale); prettyTime.format(new Date()); - assertEquals("अभी", prettyTime.format(new Date())); + assertEquals("कुछ पल बाद", prettyTime.format(new Date())); } @Test @@ -57,21 +57,21 @@ public void testNullDate() throws Exception { PrettyTime t = new PrettyTime(); Date date = null; - assertEquals("अभी", t.format(date)); + assertEquals("कुछ पल बाद", t.format(date)); } @Test public void testRightNow() throws Exception { PrettyTime t = new PrettyTime(); - assertEquals("अभी", t.format(new Date())); + assertEquals("कुछ पल बाद", t.format(new Date())); } @Test public void testRightNowVariance() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); - assertEquals("अभी", t.format(new Date(600))); + assertEquals("कुछ पल बाद", t.format(new Date(600))); } @Test @@ -143,7 +143,7 @@ public void testCenturiesFromNow() throws Exception public void testMomentsAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(6000)); - assertEquals("अभी", t.format(new Date(0))); + assertEquals("अभी-अभी", t.format(new Date(0))); } @Test diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java index b9cdbc23..b0ace507 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java @@ -71,8 +71,10 @@ public void testRightNow() throws Exception public void testRightNowWithReference() throws Exception { Date now = new Date(); - PrettyTime t = new PrettyTime(); - Assert.assertEquals("moments from now", t.format(now)); + Date ref = new Date(); + PrettyTime t = new PrettyTime(ref); + String formatted = t.format(now); + Assert.assertEquals("moments from now", formatted); } @Test