From 444ab407623217e2392a35d39d47b0e74980c66a Mon Sep 17 00:00:00 2001 From: Franco Rapetti Date: Thu, 9 Nov 2017 17:16:28 -0300 Subject: [PATCH 001/147] fix just now suffix for spanish language --- .../src/main/java/org/ocpsoft/prettytime/i18n/Resources_es.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_es.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_es.java index 3d860811..f30201fc 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_es.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_es.java @@ -51,7 +51,7 @@ public class Resources_es extends ListResourceBundle { "HourPluralName", "horas" }, { "JustNowPattern", "%u" }, { "JustNowFuturePrefix", "" }, - { "JustNowFutureSuffix", "hace un instante" }, + { "JustNowFutureSuffix", "en un instante" }, { "JustNowPastPrefix", "hace instantes" }, { "JustNowPastSuffix", "" }, { "JustNowSingularName", "" }, From 711044fa2505b9f24a33bd382b23b9c79e4106df Mon Sep 17 00:00:00 2001 From: David Rawson Date: Fri, 17 Nov 2017 08:53:48 +1300 Subject: [PATCH 002/147] add i18n for Greek --- .../ocpsoft/prettytime/i18n/Resources_el.java | 104 +++++++++ .../prettytime/PrettyTimeI18n_EL_Test.java | 200 ++++++++++++++++++ 2 files changed, 304 insertions(+) create mode 100644 core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_el.java create mode 100644 core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_EL_Test.java diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_el.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_el.java new file mode 100644 index 00000000..89e96139 --- /dev/null +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_el.java @@ -0,0 +1,104 @@ +package org.ocpsoft.prettytime.i18n; + +import java.util.ListResourceBundle; + + +public class Resources_el extends ListResourceBundle { + private static final Object[][] OBJECTS = new Object[][]{ + {"CenturyPattern", "%n %u"}, + {"CenturyFuturePrefix", ""}, + {"CenturyFutureSuffix", "από τώρα "}, + {"CenturyPastPrefix", ""}, + {"CenturyPastSuffix", "Πριν από "}, + {"CenturySingularName", "αιώνας"}, + {"CenturyPluralName", "αιώνες"}, + {"DayPattern", "%n %u"}, + {"DayFuturePrefix", ""}, + {"DayFutureSuffix", "από τώρα "}, + {"DayPastPrefix", ""}, + {"DayPastSuffix", "Πριν από "}, + {"DaySingularName", "ημέρα"}, + {"DayPluralName", "ημέρες"}, + {"DecadePattern", "%n %u"}, + {"DecadeFuturePrefix", ""}, + {"DecadeFutureSuffix", "από τώρα "}, + {"DecadePastPrefix", ""}, + {"DecadePastSuffix", "Πριν από "}, + {"DecadeSingularName", "δεκαετία"}, + {"DecadePluralName", "δεκαετίες"}, + {"HourPattern", "%n %u"}, + {"HourFuturePrefix", ""}, + {"HourFutureSuffix", "από τώρα "}, + {"HourPastPrefix", ""}, + {"HourPastSuffix", "Πριν από "}, + {"HourSingularName", "ώρα"}, + {"HourPluralName", "ώρες"}, + {"JustNowPattern", "%u"}, + {"JustNowFuturePrefix", ""}, + {"JustNowFutureSuffix", "στιγμές από τώρα"}, + {"JustNowPastPrefix", "πριν από στιγμές"}, + {"JustNowPastSuffix", ""}, + {"JustNowSingularName", ""}, + {"JustNowPluralName", ""}, + {"MillenniumPattern", "%n %u"}, + {"MillenniumFuturePrefix", ""}, + {"MillenniumFutureSuffix", "από τώρα "}, + {"MillenniumPastPrefix", ""}, + {"MillenniumPastSuffix", "Πριν από "}, + {"MillenniumSingularName", "χιλιετία"}, + {"MillenniumPluralName", "χιλιετίες"}, + {"MillisecondPattern", "%n %u"}, + {"MillisecondFuturePrefix", ""}, + {"MillisecondFutureSuffix", "από τώρα "}, + {"MillisecondPastPrefix", ""}, + {"MillisecondPastSuffix", "Πριν από "}, + {"MillisecondSingularName", "Χιλιοστό του δευτερολέπτου"}, + {"MillisecondPluralName", "Χιλιοστά του δευτερολέπτου"}, + {"MinutePattern", "%n %u"}, + {"MinuteFuturePrefix", ""}, + {"MinuteFutureSuffix", "από τώρα "}, + {"MinutePastPrefix", ""}, + {"MinutePastSuffix", "Πριν από "}, + {"MinuteSingularName", "λεπτό"}, + {"MinutePluralName", "λεπτά"}, + {"MonthPattern", "%n %u"}, + {"MonthFuturePrefix", ""}, + {"MonthFutureSuffix", "από τώρα "}, + {"MonthPastPrefix", ""}, + {"MonthPastSuffix", "Πριν από "}, + {"MonthSingularName", "μήνας"}, + {"MonthPluralName", "μήνες"}, + {"SecondPattern", "%n %u"}, + {"SecondFuturePrefix", ""}, + {"SecondFutureSuffix", "από τώρα "}, + {"SecondPastPrefix", ""}, + {"SecondPastSuffix", "Πριν από "}, + {"SecondSingularName", "δευτερόλεπτο"}, + {"SecondPluralName", "δευτερόλεπτα"}, + {"WeekPattern", "%n %u"}, + {"WeekFuturePrefix", ""}, + {"WeekFutureSuffix", "από τώρα "}, + {"WeekPastPrefix", ""}, + {"WeekPastSuffix", "Πριν από "}, + {"WeekSingularName", "εβδομάδα"}, + {"WeekPluralName", "εβδομάδες"}, + {"YearPattern", "%n %u"}, + {"YearFuturePrefix", ""}, + {"YearFutureSuffix", "από τώρα "}, + {"YearPastPrefix", ""}, + {"YearPastSuffix", "Πριν από "}, + {"YearSingularName", "έτος"}, + {"YearPluralName", "έτη"}, + {"AbstractTimeUnitPattern", ""}, + {"AbstractTimeUnitFuturePrefix", ""}, + {"AbstractTimeUnitFutureSuffix", ""}, + {"AbstractTimeUnitPastPrefix", ""}, + {"AbstractTimeUnitPastSuffix", ""}, + {"AbstractTimeUnitSingularName", ""}, + {"AbstractTimeUnitPluralName", ""}}; + + @Override + public Object[][] getContents() { + return OBJECTS; + } +} \ No newline at end of file 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 new file mode 100644 index 00000000..a437268c --- /dev/null +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_EL_Test.java @@ -0,0 +1,200 @@ +package org.ocpsoft.prettytime; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +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 { + SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); + + private Locale locale; + + @Before + public void setUp() throws Exception { + locale = Locale.getDefault(); + Locale.setDefault(Locale.forLanguageTag("el")); + } + + @Test + public void testCeilingInterval() throws Exception { + Date then = format.parse("5/20/2009"); + Date ref = format.parse("6/17/2009"); + PrettyTime t = new PrettyTime(ref); + Assert.assertEquals("1 μήνας Πριν από", t.format(then)); + } + + @Test + public void testNullDate() throws Exception { + PrettyTime t = new PrettyTime(); + Date date = null; + Assert.assertEquals("στιγμές από τώρα", t.format(date)); + } + + @Test + 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(); + List preciseDuration = t.calculatePreciseDuration( + 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()))); + } + + @Test + 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)))); + } + + @Test + 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 { + PrettyTime t = new PrettyTime(new Date(0)); + Assert.assertEquals("12 λεπτά από τώρα", t.format(new Date(1000 * 60 * 12))); + } + + @Test + 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 { + 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 { + 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 { + PrettyTime t = new PrettyTime(new Date(0)); + Assert.assertEquals("3 μήνες από τώρα", t.format(new Date(2629743830L * 3L))); + } + + @Test + 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 { + PrettyTime t = new PrettyTime(new Date(0)); + Assert.assertEquals("3 δεκαετίες από τώρα", t.format(new Date(315569259747L * 3L))); + } + + @Test + public void testCenturiesFromNow() throws Exception { + PrettyTime t = new PrettyTime(new Date(0)); + Assert.assertEquals("3 αιώνες από τώρα", t.format(new Date(3155692597470L * 3L))); + } + + /* + * Past + */ + @Test + 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 { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12)); + Assert.assertEquals("12 λεπτά Πριν από", t.format(new Date(0))); + } + + @Test + 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 { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3)); + Assert.assertEquals("3 ώρες Πριν από", t.format(new Date(0))); + } + + @Test + 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 { + 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 { + 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 { + PrettyTime t = new PrettyTime(new Date(2629743830L * 3L)); + Assert.assertEquals("3 μήνες Πριν από", t.format(new Date(0))); + } + + @Test + 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 { + PrettyTime t = new PrettyTime(new Date(315569259747L * 3L)); + Assert.assertEquals("3 δεκαετίες Πριν από", t.format(new Date(0))); + } + + @Test + 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 { + PrettyTime t = new PrettyTime(); + Assert.assertEquals("2 ώρες Πριν από", t.format(new Date(new Date().getTime() - 6543990))); + } + + @After + public void tearDown() throws Exception { + Locale.setDefault(locale); + } +} \ No newline at end of file From 78a80f2c6ef6ee14ae598043954deba53ee75bed Mon Sep 17 00:00:00 2001 From: ricocaribe Date: Wed, 28 Feb 2018 10:23:35 +0100 Subject: [PATCH 003/147] Create Resources_gl.java --- .../ocpsoft/prettytime/i18n/Resources_gl.java | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_gl.java diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_gl.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_gl.java new file mode 100644 index 00000000..9794543d --- /dev/null +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_gl.java @@ -0,0 +1,121 @@ +/* + * Copyright 2012 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ocpsoft.prettytime.i18n; + +import java.util.ListResourceBundle; + +public class Resources_gl extends ListResourceBundle +{ + + private static final Object[][] OBJECTS = new Object[][] { + { "CenturyPattern", "%n %u" }, + { "CenturyFuturePrefix", "en " }, + { "CenturyFutureSuffix", "" }, + { "CenturyPastPrefix", "fai " }, + { "CenturyPastSuffix", "" }, + { "CenturySingularName", "século" }, + { "CenturyPluralName", "séculos" }, + { "DayPattern", "%n %u" }, + { "DayFuturePrefix", "en" }, + { "DayFutureSuffix", "" }, + { "DayPastPrefix", "fai " }, + { "DayPastSuffix", "" }, + { "DaySingularName", "día " }, + { "DayPluralName", "días" }, + { "DecadePattern", "%acn %u" }, + { "DecadeFuturePrefix", "en " }, + { "DecadeFutureSuffix", "" }, + { "DecadePastPrefix", "fai " }, + { "DecadePastSuffix", "" }, + { "DecadeSingularName", "década" }, + { "DecadePluralName", "décadas" }, + { "HourPattern", "%n %u" }, + { "HourFuturePrefix", "en " }, + { "HourFutureSuffix", "" }, + { "HourPastPrefix", "fai " }, + { "HourPastSuffix", "" }, + { "HourSingularName", "hora" }, + { "HourPluralName", "horas" }, + { "JustNowPattern", "%u" }, + { "JustNowFuturePrefix", "" }, + { "JustNowFutureSuffix", "fai un momento" }, + { "JustNowPastPrefix", "hai momentos" }, + { "JustNowPastSuffix", "" }, + { "JustNowSingularName", "" }, + { "JustNowPluralName", "" }, + { "MillenniumPattern", "%n %u" }, + { "MillenniumFuturePrefix", "en " }, + { "MillenniumFutureSuffix", "" }, + { "MillenniumPastPrefix", "fai " }, + { "MillenniumPastSuffix", "" }, + { "MillenniumSingularName", "milenio" }, + { "MillenniumPluralName", "milenios" }, + { "MillisecondPattern", "%n %u" }, + { "MillisecondFuturePrefix", "en " }, + { "MillisecondFutureSuffix", "" }, + { "MillisecondPastPrefix", "fai " }, + { "MillisecondPastSuffix", "" }, + { "MillisecondSingularName", "milisegundo" }, + { "MillisecondPluralName", "milisegundos" }, + { "MinutePattern", "%n %u" }, + { "MinuteFuturePrefix", "en " }, + { "MinuteFutureSuffix", "" }, + { "MinutePastPrefix", "fai " }, + { "MinutePastSuffix", "" }, + { "MinuteSingularName", "minuto" }, + { "MinutePluralName", "minutos" }, + { "MonthPattern", "%n %u" }, + { "MonthFuturePrefix", "en " }, + { "MonthFutureSuffix", "" }, + { "MonthPastPrefix", "fai " }, + { "MonthPastSuffix", "" }, + { "MonthSingularName", "mes" }, + { "MonthPluralName", "meses" }, + { "SecondPattern", "%n %u" }, + { "SecondFuturePrefix", "en " }, + { "SecondFutureSuffix", "" }, + { "SecondPastPrefix", "fai " }, + { "SecondPastSuffix", "" }, + { "SecondSingularName", "segundo" }, + { "SecondPluralName", "segundos" }, + { "WeekPattern", "%n %u" }, + { "WeekFuturePrefix", "en " }, + { "WeekFutureSuffix", "" }, + { "WeekPastPrefix", "fai " }, + { "WeekPastSuffix", "" }, + { "WeekSingularName", "semana" }, + { "WeekPluralName", "semanas" }, + { "YearPattern", "%n %u" }, + { "YearFuturePrefix", "en " }, + { "YearFutureSuffix", "" }, + { "YearPastPrefix", "fai " }, + { "YearPastSuffix", "" }, + { "YearSingularName", "ano" }, + { "YearPluralName", "anos" }, + { "AbstractTimeUnitPattern", "" }, + { "AbstractTimeUnitFuturePrefix", "" }, + { "AbstractTimeUnitFutureSuffix", "" }, + { "AbstractTimeUnitPastPrefix", "" }, + { "AbstractTimeUnitPastSuffix", "" }, + { "AbstractTimeUnitSingularName", "" }, + { "AbstractTimeUnitPluralName", "" } }; + + @Override + protected Object[][] getContents() + { + return OBJECTS; + } +} From 646fade2ccdbc172ba54b643339a7233b8cf7f0f Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Tue, 6 Mar 2018 15:13:25 -0500 Subject: [PATCH 004/147] [maven-release-plugin] prepare release 4.0.1.Final --- core/pom.xml | 6 +++--- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 76ae3b4d..34ede634 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.1-SNAPSHOT + 4.0.1.Final ../pom.xml @@ -22,8 +22,8 @@ Pretty Time Core org.ocpsoft.prettytime.core - - + + <_exportcontents>org.ocpsoft.prettytime* diff --git a/jsf/pom.xml b/jsf/pom.xml index 789f001a..de8db8e5 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.1-SNAPSHOT + 4.0.1.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 74e23ad4..46d3ecf9 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.1-SNAPSHOT + 4.0.1.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 724bac8e..f53a020f 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.1-SNAPSHOT + 4.0.1.Final ../pom.xml diff --git a/pom.xml b/pom.xml index 3b752f68..937d8453 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 4.0.1-SNAPSHOT + 4.0.1.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -46,7 +46,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 4.0.1.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index e2eed87d..38631f00 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 4.0.1-SNAPSHOT + 4.0.1.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 4.0.1-SNAPSHOT + 4.0.1.Final diff --git a/samples/pom.xml b/samples/pom.xml index c1a2e2b9..1b1666a6 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.1-SNAPSHOT + 4.0.1.Final 4.0.0 From a93e6060407bcdf05fbe182de4101a0f71f870e2 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Tue, 6 Mar 2018 15:13:25 -0500 Subject: [PATCH 005/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 34ede634..eeaa7c75 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.1.Final + 4.0.2-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index de8db8e5..9a8a0bd1 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.1.Final + 4.0.2-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 46d3ecf9..d80f2c18 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.1.Final + 4.0.2-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index f53a020f..28e75177 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.1.Final + 4.0.2-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index 937d8453..ad085bb6 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 4.0.1.Final + 4.0.2-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -46,7 +46,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 4.0.1.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 38631f00..57d462ae 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 4.0.1.Final + 4.0.2-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 4.0.1.Final + 4.0.2-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index 1b1666a6..2c68dce7 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.1.Final + 4.0.2-SNAPSHOT 4.0.0 From 59e82f1902040f9b2e7f05a78e47678118086da0 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Tue, 6 Mar 2018 15:20:40 -0500 Subject: [PATCH 006/147] Add force release note --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 7bdc699e..bcf2efcc 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,7 @@ To use prettytime in android, first add the following dependency to your app lev When using Android with ProGuard, you must add the following to your ProGuard configuration script: -keep class org.ocpsoft.prettytime.i18n.** + +DEVELOPMENT +=========== +force-release: mvn release:prepare release:perform -DskipTests=true -DdevelopmentVersion=4.0.2-SNAPSHOT -DreleaseVersion=4.0.1.Final -Dtag=4.0.1.Final -Darguments="-DskipTests=true -Dmaven.test.skip=true" From 6e1101b8256042b944ed15cd3515690e2dd4de97 Mon Sep 17 00:00:00 2001 From: Musasshi90 Date: Mon, 12 Mar 2018 15:35:05 +0800 Subject: [PATCH 007/147] Create Resources_ms.java create resources_ms.java --- core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java | 1 + 1 file changed, 1 insertion(+) create mode 100644 core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java @@ -0,0 +1 @@ + From 52e0f9a7f40475119b9feaecbf437a2ab70d20cc Mon Sep 17 00:00:00 2001 From: Musasshi90 Date: Mon, 12 Mar 2018 15:41:42 +0800 Subject: [PATCH 008/147] Update Resources_ms.java update resources_ms.java --- .../ocpsoft/prettytime/i18n/Resources_ms.java | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java index 8b137891..a8544f22 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java @@ -1 +1,122 @@ +/* + * Copyright 2012 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ocpsoft.prettytime.i18n; + +import java.util.ListResourceBundle; + +public class Resources_zh extends ListResourceBundle +{ + + private static final Object[][] OBJECTS = new Object[][] { + { "CenturyPattern", "%n %u" }, + { "CenturyFuturePrefix", "" }, + { "CenturyFutureSuffix", "Selepas" }, + { "CenturyPastPrefix", "" }, + { "CenturyPastSuffix", "Sebelum ini" }, + { "CenturySingularName", "Abad" }, + { "CenturyPluralName", "世纪" }, + { "DayPattern", "%n %u" }, + { "DayFuturePrefix", "" }, + { "DayFutureSuffix", "Selepas" }, + { "DayPastPrefix", "" }, + { "DayPastSuffix", "Sebelum ini" }, + { "DaySingularName", "Hari" }, + { "DayPluralName", "Hari" }, + { "DecadePattern", "%n%u" }, + { "DecadeFuturePrefix", "" }, + { "DecadeFutureSuffix", "Selepas" }, + { "DecadePastPrefix", "" }, + { "DecadePastSuffix", "Sebelum" }, + { "DecadeSingularName", "0 Tahun" }, + { "DecadePluralName", "0 Tahun" }, + { "HourPattern", "%n %u" }, + { "HourFuturePrefix", "" }, + { "HourFutureSuffix", "Selepas" }, + { "HourPastPrefix", "" }, + { "HourPastSuffix", "Sebelum" }, + { "HourSingularName", "Jam" }, + { "HourPluralName", "Jam" }, + { "JustNowPattern", "%u" }, + { "JustNowFuturePrefix", "" }, + { "JustNowFutureSuffix", "Hanya sekarang" }, + { "JustNowPastPrefix", "Sebelum ini" }, + { "JustNowPastSuffix", "" }, + { "JustNowSingularName", "" }, + { "JustNowPluralName", "" }, + { "MillenniumPattern", "%n %u" }, + { "MillenniumFuturePrefix", "" }, + { "MillenniumFutureSuffix", "Selepas" }, + { "MillenniumPastPrefix", "" }, + { "MillenniumPastSuffix", "Sebelum ini" }, + { "MillenniumSingularName", "Millennium" }, + { "MillenniumPluralName", "Millennium" }, + { "MillisecondPattern", "%n %u" }, + { "MillisecondFuturePrefix", "" }, + { "MillisecondFutureSuffix", "Selepas ini" }, + { "MillisecondPastPrefix", "" }, + { "MillisecondPastSuffix", "Sebelum" }, + { "MillisecondSingularName", "Milisaat" }, + { "MillisecondPluralName", "Milisaat" }, + { "MinutePattern", "%n %u" }, + { "MinuteFuturePrefix", "" }, + { "MinuteFutureSuffix", "Selepas" }, + { "MinutePastPrefix", "" }, + { "MinutePastSuffix", "Sebelum ini" }, + { "MinuteSingularName", "Minit" }, + { "MinutePluralName", "Minit" }, + { "MonthPattern", "%n %u" }, + { "MonthFuturePrefix", "" }, + { "MonthFutureSuffix", "Selepas" }, + { "MonthPastPrefix", "" }, + { "MonthPastSuffix", "Sebelum" }, + { "MonthSingularName", "Bulan" }, + { "MonthPluralName", "Bulan" }, + { "SecondPattern", "%n %u" }, + { "SecondFuturePrefix", "" }, + { "SecondFutureSuffix", "Selepas" }, + { "SecondPastPrefix", "" }, + { "SecondPastSuffix", "Sebelum ini" }, + { "SecondSingularName", "saat" }, + { "SecondPluralName", "saat" }, + { "WeekPattern", "%n %u" }, + { "WeekFuturePrefix", "" }, + { "WeekFutureSuffix", "Selepas" }, + { "WeekPastPrefix", "" }, + { "WeekPastSuffix", "Sebelum ini" }, + { "WeekSingularName", "Minggu" }, + { "WeekPluralName", "Minggu" }, + { "YearPattern", "%n %u" }, + { "YearFuturePrefix", "" }, + { "YearFutureSuffix", "Selepas" }, + { "YearPastPrefix", "" }, + { "YearPastSuffix", "Sebelum" }, + { "YearSingularName", "Tahun" }, + { "YearPluralName", "Tahun" }, + { "AbstractTimeUnitPattern", "" }, + { "AbstractTimeUnitFuturePrefix", "" }, + { "AbstractTimeUnitFutureSuffix", "" }, + { "AbstractTimeUnitPastPrefix", "" }, + { "AbstractTimeUnitPastSuffix", "" }, + { "AbstractTimeUnitSingularName", "" }, + { "AbstractTimeUnitPluralName", "" } }; + + @Override + protected Object[][] getContents() + { + return OBJECTS; + } +} From ec30eccd760fc6a258c23b297e8d78dc8a47ffd7 Mon Sep 17 00:00:00 2001 From: Musasshi90 Date: Mon, 12 Mar 2018 15:44:27 +0800 Subject: [PATCH 009/147] Update Resources_ms.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change 世纪 to abad --- .../src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java index a8544f22..4e9246b8 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java @@ -28,7 +28,7 @@ public class Resources_zh extends ListResourceBundle { "CenturyPastPrefix", "" }, { "CenturyPastSuffix", "Sebelum ini" }, { "CenturySingularName", "Abad" }, - { "CenturyPluralName", "世纪" }, + { "CenturyPluralName", "Abad" }, { "DayPattern", "%n %u" }, { "DayFuturePrefix", "" }, { "DayFutureSuffix", "Selepas" }, From 7f6b95c2931fa64873fd05d85daf472d082579de Mon Sep 17 00:00:00 2001 From: Musasshi90 Date: Mon, 12 Mar 2018 15:51:12 +0800 Subject: [PATCH 010/147] Create PrettyTimeI18n_MS_Test.java create PrettyTimel18n_MS_Test.java --- .../prettytime/PrettyTimeI18n_MS_Test.java | 231 ++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java new file mode 100644 index 00000000..7d577c5b --- /dev/null +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java @@ -0,0 +1,231 @@ +package org.ocpsoft.prettytime; + +import static org.junit.Assert.assertEquals; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Created by edward_chiang on 13/6/27. + */ +public class PrettyTimeI18n_zh_TW_Test +{ + private final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); + private Locale locale; + + @Before + public void setUp() throws Exception + { + locale = Locale.TRADITIONAL_CHINESE; + Locale.setDefault(Locale.TRADITIONAL_CHINESE); + } + + @Test + public void testPrettyTime() + { + PrettyTime p = new PrettyTime(locale); + assertEquals("Hanya sekarang", p.format(new Date())); + } + + @Test + public void testPrettyTimeCenturies() + { + PrettyTime p = new PrettyTime(new Date(3155692597470L * 3L), locale); + assertEquals("3 Abad yang lalu", p.format(new Date(0))); + + p = new PrettyTime(new Date(0), locale); + assertEquals("3 Selepas abad ini", p.format(new Date(3155692597470L * 3L))); + } + + @Test + public void testCeilingInterval() throws Exception + { + Date then = format.parse("20/5/2009"); + Date ref = format.parse("17/6/2009"); + PrettyTime t = new PrettyTime(ref, locale); + assertEquals("1 Bulan yang lalu", t.format(then)); + } + + @Test + public void testNullDate() throws Exception + { + PrettyTime t = new PrettyTime(locale); + Date date = null; + assertEquals("Hanya sekarang", t.format(date)); + } + + @Test + public void testRightNow() throws Exception + { + PrettyTime t = new PrettyTime(locale); + assertEquals("Hanya sekarang", t.format(new Date())); + } + + @Test + public void testRightNowVariance() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("Hanya sekarang", t.format(new Date(600))); + } + + @Test + public void testMinutesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("12 Selepas beberapa minit", t.format(new Date(1000 * 60 * 12))); + } + + @Test + public void testHoursFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 Selepas beberapa jam", t.format(new Date(1000 * 60 * 60 * 3))); + } + + @Test + public void testDaysFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 Hari kemudian", t.format(new Date(1000 * 60 * 60 * 24 * 3))); + } + + @Test + public void testWeeksFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 Minggu kemudian", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); + } + + @Test + public void testMonthsFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 Bulan kemudian", t.format(new Date(2629743830L * 3L))); + } + + @Test + public void testYearsFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 Tahun kemudian", t.format(new Date(2629743830L * 12L * 3L))); + } + + @Test + public void testDecadesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("30 Tahun kemudian", t.format(new Date(315569259747L * 3L))); + } + + @Test + public void testCenturiesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 Selepas abad ini", t.format(new Date(3155692597470L * 3L))); + } + + /* + * Past + */ + @Test + public void testMomentsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(6000), locale); + assertEquals("Sebelum ini", t.format(new Date(0))); + } + + @Test + public void testMinutesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale); + assertEquals("12 Minit yang lalu", t.format(new Date(0))); + } + + @Test + public void test1HourAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 1), locale); + assertEquals("1 Jam yang lalu", t.format(new Date(0))); + } + + @Test + public void test3HoursAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale); + assertEquals("3 Jam yang lalu", t.format(new Date(0))); + } + + @Test + public void test6HoursAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 6), locale); + assertEquals("6 Jam yang lalu", t.format(new Date(0))); + } + + @Test + public void testDaysAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale); + assertEquals("3 Hari yang lalu", t.format(new Date(0))); + } + + @Test + public void testWeeksAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale); + assertEquals("3 Minggu yang lalu", t.format(new Date(0))); + } + + @Test + public void testMonthsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale); + assertEquals("3 Bulan yang lalu", t.format(new Date(0))); + } + + @Test + public void testYearsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale); + assertEquals("3 Tahun yang lalu", t.format(new Date(0))); + } + + @Test + public void test8YearsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 8L), locale); + assertEquals("8 Tahun yang lalu", t.format(new Date(0))); + } + + @Test + public void testDecadesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale); + assertEquals("30 Tahun yang lalu", t.format(new Date(0))); + } + + @Test + public void test8DecadesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(315569259747L * 8L), locale); + assertEquals("80 Tahun yang lalu", t.format(new Date(0))); + } + + @Test + public void testCenturiesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale); + assertEquals("3 Abad yang lalu", t.format(new Date(0))); + } + + @After + public void tearDown() throws Exception + { + Locale.setDefault(locale); + } +} From d1b666642bab8386d492c075352f88867a204379 Mon Sep 17 00:00:00 2001 From: Musasshi90 Date: Mon, 12 Mar 2018 16:00:27 +0800 Subject: [PATCH 011/147] Update PrettyTimeI18n_MS_Test.java update the class name --- .../java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java index 7d577c5b..8eb51f65 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java @@ -13,7 +13,7 @@ /** * Created by edward_chiang on 13/6/27. */ -public class PrettyTimeI18n_zh_TW_Test +public class PrettyTimeI18n_MS_Test { private final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); private Locale locale; From ee084642f3e08dd63171fb3880c28d75cff3131e Mon Sep 17 00:00:00 2001 From: Musasshi90 Date: Mon, 12 Mar 2018 16:01:02 +0800 Subject: [PATCH 012/147] Update Resources_ms.java update the class name --- .../src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java index 4e9246b8..5277e7c1 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java @@ -18,7 +18,7 @@ import java.util.ListResourceBundle; -public class Resources_zh extends ListResourceBundle +public class Resources_ms extends ListResourceBundle { private static final Object[][] OBJECTS = new Object[][] { From 23b77e4a726d9d73869a8a9543460ff80d2a466b Mon Sep 17 00:00:00 2001 From: Musasshi90 Date: Mon, 12 Mar 2018 16:58:45 +0800 Subject: [PATCH 013/147] Update PrettyTimeI18n_MS_Test.java update the test --- .../prettytime/PrettyTimeI18n_MS_Test.java | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java index 8eb51f65..58eb8192 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java @@ -21,25 +21,25 @@ public class PrettyTimeI18n_MS_Test @Before public void setUp() throws Exception { - locale = Locale.TRADITIONAL_CHINESE; - Locale.setDefault(Locale.TRADITIONAL_CHINESE); + locale = new Locale("ms"); + Locale.setDefault(new Locale("ms")); } @Test public void testPrettyTime() { PrettyTime p = new PrettyTime(locale); - assertEquals("Hanya sekarang", p.format(new Date())); + assertEquals("hanya sekarang", p.format(new Date())); } @Test public void testPrettyTimeCenturies() { PrettyTime p = new PrettyTime(new Date(3155692597470L * 3L), locale); - assertEquals("3 Abad yang lalu", p.format(new Date(0))); + assertEquals("3 abad yang lalu", p.format(new Date(0))); p = new PrettyTime(new Date(0), locale); - assertEquals("3 Selepas abad ini", p.format(new Date(3155692597470L * 3L))); + assertEquals("3 abad kemudian", p.format(new Date(3155692597470L * 3L))); } @Test @@ -48,7 +48,7 @@ public void testCeilingInterval() throws Exception Date then = format.parse("20/5/2009"); Date ref = format.parse("17/6/2009"); PrettyTime t = new PrettyTime(ref, locale); - assertEquals("1 Bulan yang lalu", t.format(then)); + assertEquals("1 bulan yang lalu", t.format(then)); } @Test @@ -56,77 +56,77 @@ public void testNullDate() throws Exception { PrettyTime t = new PrettyTime(locale); Date date = null; - assertEquals("Hanya sekarang", t.format(date)); + assertEquals("hanya sekarang", t.format(date)); } @Test public void testRightNow() throws Exception { PrettyTime t = new PrettyTime(locale); - assertEquals("Hanya sekarang", t.format(new Date())); + assertEquals("hanya sekarang", t.format(new Date())); } @Test public void testRightNowVariance() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("Hanya sekarang", t.format(new Date(600))); + assertEquals("hanya sekarang", t.format(new Date(600))); } @Test public void testMinutesFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("12 Selepas beberapa minit", t.format(new Date(1000 * 60 * 12))); + assertEquals("12 minit kemudian", t.format(new Date(1000 * 60 * 12))); } @Test public void testHoursFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("3 Selepas beberapa jam", t.format(new Date(1000 * 60 * 60 * 3))); + assertEquals("3 jam kemudian", t.format(new Date(1000 * 60 * 60 * 3))); } @Test public void testDaysFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("3 Hari kemudian", t.format(new Date(1000 * 60 * 60 * 24 * 3))); + assertEquals("3 hari kemudian", t.format(new Date(1000 * 60 * 60 * 24 * 3))); } @Test public void testWeeksFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("3 Minggu kemudian", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); + assertEquals("3 minggu kemudian", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); } @Test public void testMonthsFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("3 Bulan kemudian", t.format(new Date(2629743830L * 3L))); + assertEquals("3 bulan kemudian", t.format(new Date(2629743830L * 3L))); } @Test public void testYearsFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("3 Tahun kemudian", t.format(new Date(2629743830L * 12L * 3L))); + assertEquals("3 tahun kemudian", t.format(new Date(2629743830L * 12L * 3L))); } @Test public void testDecadesFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("30 Tahun kemudian", t.format(new Date(315569259747L * 3L))); + assertEquals("30 tahun kemudian", t.format(new Date(315569259747L * 3L))); } @Test public void testCenturiesFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("3 Selepas abad ini", t.format(new Date(3155692597470L * 3L))); + assertEquals("3 abad kemudian", t.format(new Date(3155692597470L * 3L))); } /* @@ -136,91 +136,91 @@ public void testCenturiesFromNow() throws Exception public void testMomentsAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(6000), locale); - assertEquals("Sebelum ini", t.format(new Date(0))); + assertEquals("hanya sekarang", t.format(new Date(0))); } @Test public void testMinutesAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale); - assertEquals("12 Minit yang lalu", t.format(new Date(0))); + assertEquals("12 minit yang lalu", t.format(new Date(0))); } @Test public void test1HourAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 1), locale); - assertEquals("1 Jam yang lalu", t.format(new Date(0))); + assertEquals("1 jam yang lalu", t.format(new Date(0))); } @Test public void test3HoursAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale); - assertEquals("3 Jam yang lalu", t.format(new Date(0))); + assertEquals("3 jam yang lalu", t.format(new Date(0))); } @Test public void test6HoursAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 6), locale); - assertEquals("6 Jam yang lalu", t.format(new Date(0))); + assertEquals("6 jam yang lalu", t.format(new Date(0))); } @Test public void testDaysAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale); - assertEquals("3 Hari yang lalu", t.format(new Date(0))); + assertEquals("3 hari yang lalu", t.format(new Date(0))); } @Test public void testWeeksAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale); - assertEquals("3 Minggu yang lalu", t.format(new Date(0))); + assertEquals("3 minggu yang lalu", t.format(new Date(0))); } @Test public void testMonthsAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale); - assertEquals("3 Bulan yang lalu", t.format(new Date(0))); + assertEquals("3 bulan yang lalu", t.format(new Date(0))); } @Test public void testYearsAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale); - assertEquals("3 Tahun yang lalu", t.format(new Date(0))); + assertEquals("3 tahun yang lalu", t.format(new Date(0))); } @Test public void test8YearsAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 8L), locale); - assertEquals("8 Tahun yang lalu", t.format(new Date(0))); + assertEquals("8 tahun yang lalu", t.format(new Date(0))); } @Test public void testDecadesAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale); - assertEquals("30 Tahun yang lalu", t.format(new Date(0))); + assertEquals("30 tahun yang lalu", t.format(new Date(0))); } @Test public void test8DecadesAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(315569259747L * 8L), locale); - assertEquals("80 Tahun yang lalu", t.format(new Date(0))); + assertEquals("80 tahun yang lalu", t.format(new Date(0))); } @Test public void testCenturiesAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale); - assertEquals("3 Abad yang lalu", t.format(new Date(0))); + assertEquals("3 abad yang lalu", t.format(new Date(0))); } @After From 93e244d1caedcf68fda4c5b74848c8ad7ce460c2 Mon Sep 17 00:00:00 2001 From: Musasshi90 Date: Mon, 12 Mar 2018 16:59:16 +0800 Subject: [PATCH 014/147] Update Resources_ms.java --- .../ocpsoft/prettytime/i18n/Resources_ms.java | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java index 5277e7c1..0e638a67 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java @@ -24,36 +24,36 @@ public class Resources_ms extends ListResourceBundle private static final Object[][] OBJECTS = new Object[][] { { "CenturyPattern", "%n %u" }, { "CenturyFuturePrefix", "" }, - { "CenturyFutureSuffix", "Selepas" }, + { "CenturyFutureSuffix", "kemudian" }, { "CenturyPastPrefix", "" }, - { "CenturyPastSuffix", "Sebelum ini" }, - { "CenturySingularName", "Abad" }, - { "CenturyPluralName", "Abad" }, + { "CenturyPastSuffix", "yang lalu" }, + { "CenturySingularName", "abad" }, + { "CenturyPluralName", "abad" }, { "DayPattern", "%n %u" }, { "DayFuturePrefix", "" }, - { "DayFutureSuffix", "Selepas" }, + { "DayFutureSuffix", "kemudian" }, { "DayPastPrefix", "" }, - { "DayPastSuffix", "Sebelum ini" }, - { "DaySingularName", "Hari" }, - { "DayPluralName", "Hari" }, + { "DayPastSuffix", "yang lalu" }, + { "DaySingularName", "hari" }, + { "DayPluralName", "hari" }, { "DecadePattern", "%n%u" }, { "DecadeFuturePrefix", "" }, - { "DecadeFutureSuffix", "Selepas" }, + { "DecadeFutureSuffix", "kemudian" }, { "DecadePastPrefix", "" }, - { "DecadePastSuffix", "Sebelum" }, - { "DecadeSingularName", "0 Tahun" }, - { "DecadePluralName", "0 Tahun" }, + { "DecadePastSuffix", "yang lalu" }, + { "DecadeSingularName", "0 tahun" }, + { "DecadePluralName", "0 tahun" }, { "HourPattern", "%n %u" }, { "HourFuturePrefix", "" }, - { "HourFutureSuffix", "Selepas" }, + { "HourFutureSuffix", "kemudian" }, { "HourPastPrefix", "" }, - { "HourPastSuffix", "Sebelum" }, - { "HourSingularName", "Jam" }, - { "HourPluralName", "Jam" }, + { "HourPastSuffix", "yang lalu" }, + { "HourSingularName", "jam" }, + { "HourPluralName", "jam" }, { "JustNowPattern", "%u" }, { "JustNowFuturePrefix", "" }, - { "JustNowFutureSuffix", "Hanya sekarang" }, - { "JustNowPastPrefix", "Sebelum ini" }, + { "JustNowFutureSuffix", "hanya sekarang" }, + { "JustNowPastPrefix", "hanya sekarang" }, { "JustNowPastSuffix", "" }, { "JustNowSingularName", "" }, { "JustNowPluralName", "" }, @@ -73,18 +73,18 @@ public class Resources_ms extends ListResourceBundle { "MillisecondPluralName", "Milisaat" }, { "MinutePattern", "%n %u" }, { "MinuteFuturePrefix", "" }, - { "MinuteFutureSuffix", "Selepas" }, + { "MinuteFutureSuffix", "kemudian" }, { "MinutePastPrefix", "" }, - { "MinutePastSuffix", "Sebelum ini" }, - { "MinuteSingularName", "Minit" }, - { "MinutePluralName", "Minit" }, + { "MinutePastSuffix", "yang lalu" }, + { "MinuteSingularName", "minit" }, + { "MinutePluralName", "minit" }, { "MonthPattern", "%n %u" }, { "MonthFuturePrefix", "" }, - { "MonthFutureSuffix", "Selepas" }, + { "MonthFutureSuffix", "kemudian" }, { "MonthPastPrefix", "" }, - { "MonthPastSuffix", "Sebelum" }, - { "MonthSingularName", "Bulan" }, - { "MonthPluralName", "Bulan" }, + { "MonthPastSuffix", "yang lalu" }, + { "MonthSingularName", "bulan" }, + { "MonthPluralName", "bulan" }, { "SecondPattern", "%n %u" }, { "SecondFuturePrefix", "" }, { "SecondFutureSuffix", "Selepas" }, @@ -94,18 +94,18 @@ public class Resources_ms extends ListResourceBundle { "SecondPluralName", "saat" }, { "WeekPattern", "%n %u" }, { "WeekFuturePrefix", "" }, - { "WeekFutureSuffix", "Selepas" }, + { "WeekFutureSuffix", "kemudian" }, { "WeekPastPrefix", "" }, - { "WeekPastSuffix", "Sebelum ini" }, - { "WeekSingularName", "Minggu" }, - { "WeekPluralName", "Minggu" }, + { "WeekPastSuffix", "yang lalu" }, + { "WeekSingularName", "minggu" }, + { "WeekPluralName", "minggu" }, { "YearPattern", "%n %u" }, { "YearFuturePrefix", "" }, - { "YearFutureSuffix", "Selepas" }, + { "YearFutureSuffix", "kemudian" }, { "YearPastPrefix", "" }, - { "YearPastSuffix", "Sebelum" }, - { "YearSingularName", "Tahun" }, - { "YearPluralName", "Tahun" }, + { "YearPastSuffix", "yang lalu" }, + { "YearSingularName", "tahun" }, + { "YearPluralName", "tahun" }, { "AbstractTimeUnitPattern", "" }, { "AbstractTimeUnitFuturePrefix", "" }, { "AbstractTimeUnitFutureSuffix", "" }, From 5473cb7f5653c59a594a1454c05e2e48e6e78903 Mon Sep 17 00:00:00 2001 From: Musasshi90 Date: Tue, 13 Mar 2018 10:40:15 +0800 Subject: [PATCH 015/147] update the "hanya sekarang" to "tadi" update the "hanya sekarang" to "tadi" --- .../ocpsoft/prettytime/i18n/Resources_ms.java | 339 ++++++++++++------ 1 file changed, 224 insertions(+), 115 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java index 0e638a67..2d4e8e2d 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java @@ -1,122 +1,231 @@ +package org.ocpsoft.prettytime; -/* - * Copyright 2012 Lincoln Baxter, III - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.ocpsoft.prettytime.i18n; +import static org.junit.Assert.assertEquals; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; -import java.util.ListResourceBundle; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; -public class Resources_ms extends ListResourceBundle +/** + * Created by edward_chiang on 13/6/27. + */ +public class PrettyTimeI18n_MS_Test { + private final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); + private Locale locale; + + @Before + public void setUp() throws Exception + { + locale = new Locale("ms"); + Locale.setDefault(new Locale("ms")); + } - private static final Object[][] OBJECTS = new Object[][] { - { "CenturyPattern", "%n %u" }, - { "CenturyFuturePrefix", "" }, - { "CenturyFutureSuffix", "kemudian" }, - { "CenturyPastPrefix", "" }, - { "CenturyPastSuffix", "yang lalu" }, - { "CenturySingularName", "abad" }, - { "CenturyPluralName", "abad" }, - { "DayPattern", "%n %u" }, - { "DayFuturePrefix", "" }, - { "DayFutureSuffix", "kemudian" }, - { "DayPastPrefix", "" }, - { "DayPastSuffix", "yang lalu" }, - { "DaySingularName", "hari" }, - { "DayPluralName", "hari" }, - { "DecadePattern", "%n%u" }, - { "DecadeFuturePrefix", "" }, - { "DecadeFutureSuffix", "kemudian" }, - { "DecadePastPrefix", "" }, - { "DecadePastSuffix", "yang lalu" }, - { "DecadeSingularName", "0 tahun" }, - { "DecadePluralName", "0 tahun" }, - { "HourPattern", "%n %u" }, - { "HourFuturePrefix", "" }, - { "HourFutureSuffix", "kemudian" }, - { "HourPastPrefix", "" }, - { "HourPastSuffix", "yang lalu" }, - { "HourSingularName", "jam" }, - { "HourPluralName", "jam" }, - { "JustNowPattern", "%u" }, - { "JustNowFuturePrefix", "" }, - { "JustNowFutureSuffix", "hanya sekarang" }, - { "JustNowPastPrefix", "hanya sekarang" }, - { "JustNowPastSuffix", "" }, - { "JustNowSingularName", "" }, - { "JustNowPluralName", "" }, - { "MillenniumPattern", "%n %u" }, - { "MillenniumFuturePrefix", "" }, - { "MillenniumFutureSuffix", "Selepas" }, - { "MillenniumPastPrefix", "" }, - { "MillenniumPastSuffix", "Sebelum ini" }, - { "MillenniumSingularName", "Millennium" }, - { "MillenniumPluralName", "Millennium" }, - { "MillisecondPattern", "%n %u" }, - { "MillisecondFuturePrefix", "" }, - { "MillisecondFutureSuffix", "Selepas ini" }, - { "MillisecondPastPrefix", "" }, - { "MillisecondPastSuffix", "Sebelum" }, - { "MillisecondSingularName", "Milisaat" }, - { "MillisecondPluralName", "Milisaat" }, - { "MinutePattern", "%n %u" }, - { "MinuteFuturePrefix", "" }, - { "MinuteFutureSuffix", "kemudian" }, - { "MinutePastPrefix", "" }, - { "MinutePastSuffix", "yang lalu" }, - { "MinuteSingularName", "minit" }, - { "MinutePluralName", "minit" }, - { "MonthPattern", "%n %u" }, - { "MonthFuturePrefix", "" }, - { "MonthFutureSuffix", "kemudian" }, - { "MonthPastPrefix", "" }, - { "MonthPastSuffix", "yang lalu" }, - { "MonthSingularName", "bulan" }, - { "MonthPluralName", "bulan" }, - { "SecondPattern", "%n %u" }, - { "SecondFuturePrefix", "" }, - { "SecondFutureSuffix", "Selepas" }, - { "SecondPastPrefix", "" }, - { "SecondPastSuffix", "Sebelum ini" }, - { "SecondSingularName", "saat" }, - { "SecondPluralName", "saat" }, - { "WeekPattern", "%n %u" }, - { "WeekFuturePrefix", "" }, - { "WeekFutureSuffix", "kemudian" }, - { "WeekPastPrefix", "" }, - { "WeekPastSuffix", "yang lalu" }, - { "WeekSingularName", "minggu" }, - { "WeekPluralName", "minggu" }, - { "YearPattern", "%n %u" }, - { "YearFuturePrefix", "" }, - { "YearFutureSuffix", "kemudian" }, - { "YearPastPrefix", "" }, - { "YearPastSuffix", "yang lalu" }, - { "YearSingularName", "tahun" }, - { "YearPluralName", "tahun" }, - { "AbstractTimeUnitPattern", "" }, - { "AbstractTimeUnitFuturePrefix", "" }, - { "AbstractTimeUnitFutureSuffix", "" }, - { "AbstractTimeUnitPastPrefix", "" }, - { "AbstractTimeUnitPastSuffix", "" }, - { "AbstractTimeUnitSingularName", "" }, - { "AbstractTimeUnitPluralName", "" } }; - - @Override - protected Object[][] getContents() - { - return OBJECTS; + @Test + public void testPrettyTime() + { + PrettyTime p = new PrettyTime(locale); + assertEquals("tadi", p.format(new Date())); + } + + @Test + public void testPrettyTimeCenturies() + { + PrettyTime p = new PrettyTime(new Date(3155692597470L * 3L), locale); + assertEquals("3 abad yang lalu", p.format(new Date(0))); + + p = new PrettyTime(new Date(0), locale); + assertEquals("3 abad kemudian", p.format(new Date(3155692597470L * 3L))); + } + + @Test + public void testCeilingInterval() throws Exception + { + Date then = format.parse("20/5/2009"); + Date ref = format.parse("17/6/2009"); + PrettyTime t = new PrettyTime(ref, locale); + assertEquals("1 bulan yang lalu", t.format(then)); + } + + @Test + public void testNullDate() throws Exception + { + PrettyTime t = new PrettyTime(locale); + Date date = null; + assertEquals("tadi", t.format(date)); + } + + @Test + public void testRightNow() throws Exception + { + PrettyTime t = new PrettyTime(locale); + assertEquals("tadi", t.format(new Date())); + } + + @Test + public void testRightNowVariance() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("tadi", t.format(new Date(600))); + } + + @Test + public void testMinutesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("12 minit kemudian", t.format(new Date(1000 * 60 * 12))); + } + + @Test + public void testHoursFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 jam kemudian", t.format(new Date(1000 * 60 * 60 * 3))); + } + + @Test + public void testDaysFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 hari kemudian", t.format(new Date(1000 * 60 * 60 * 24 * 3))); + } + + @Test + public void testWeeksFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 minggu kemudian", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); + } + + @Test + public void testMonthsFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 bulan kemudian", t.format(new Date(2629743830L * 3L))); + } + + @Test + public void testYearsFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 tahun kemudian", t.format(new Date(2629743830L * 12L * 3L))); + } + + @Test + public void testDecadesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("30 tahun kemudian", t.format(new Date(315569259747L * 3L))); + } + + @Test + public void testCenturiesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 abad kemudian", t.format(new Date(3155692597470L * 3L))); + } + + /* + * Past + */ + @Test + public void testMomentsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(6000), locale); + assertEquals("tadi", t.format(new Date(0))); + } + + @Test + public void testMinutesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale); + assertEquals("12 minit yang lalu", t.format(new Date(0))); + } + + @Test + public void test1HourAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 1), locale); + assertEquals("1 jam yang lalu", t.format(new Date(0))); + } + + @Test + public void test3HoursAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale); + assertEquals("3 jam yang lalu", t.format(new Date(0))); + } + + @Test + public void test6HoursAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 6), locale); + assertEquals("6 jam yang lalu", t.format(new Date(0))); + } + + @Test + public void testDaysAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale); + assertEquals("3 hari yang lalu", t.format(new Date(0))); + } + + @Test + public void testWeeksAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale); + assertEquals("3 minggu yang lalu", t.format(new Date(0))); + } + + @Test + public void testMonthsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale); + assertEquals("3 bulan yang lalu", t.format(new Date(0))); + } + + @Test + public void testYearsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale); + assertEquals("3 tahun yang lalu", t.format(new Date(0))); + } + + @Test + public void test8YearsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 8L), locale); + assertEquals("8 tahun yang lalu", t.format(new Date(0))); + } + + @Test + public void testDecadesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale); + assertEquals("30 tahun yang lalu", t.format(new Date(0))); + } + + @Test + public void test8DecadesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(315569259747L * 8L), locale); + assertEquals("80 tahun yang lalu", t.format(new Date(0))); + } + + @Test + public void testCenturiesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale); + assertEquals("3 abad yang lalu", t.format(new Date(0))); + } + + @After + public void tearDown() throws Exception + { + Locale.setDefault(locale); } } From f1337a7110582268118fba0261998905aeb85f69 Mon Sep 17 00:00:00 2001 From: Musasshi90 Date: Tue, 13 Mar 2018 10:40:47 +0800 Subject: [PATCH 016/147] update the typo update the typo --- .../ocpsoft/prettytime/i18n/Resources_ms.java | 339 ++++++------------ 1 file changed, 115 insertions(+), 224 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java index 2d4e8e2d..9a8f478f 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java @@ -1,231 +1,122 @@ -package org.ocpsoft.prettytime; -import static org.junit.Assert.assertEquals; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * Created by edward_chiang on 13/6/27. +/* + * Copyright 2012 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -public class PrettyTimeI18n_MS_Test -{ - private final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); - private Locale locale; - - @Before - public void setUp() throws Exception - { - locale = new Locale("ms"); - Locale.setDefault(new Locale("ms")); - } - - @Test - public void testPrettyTime() - { - PrettyTime p = new PrettyTime(locale); - assertEquals("tadi", p.format(new Date())); - } +package org.ocpsoft.prettytime.i18n; - @Test - public void testPrettyTimeCenturies() - { - PrettyTime p = new PrettyTime(new Date(3155692597470L * 3L), locale); - assertEquals("3 abad yang lalu", p.format(new Date(0))); +import java.util.ListResourceBundle; - p = new PrettyTime(new Date(0), locale); - assertEquals("3 abad kemudian", p.format(new Date(3155692597470L * 3L))); - } - - @Test - public void testCeilingInterval() throws Exception - { - Date then = format.parse("20/5/2009"); - Date ref = format.parse("17/6/2009"); - PrettyTime t = new PrettyTime(ref, locale); - assertEquals("1 bulan yang lalu", t.format(then)); - } - - @Test - public void testNullDate() throws Exception - { - PrettyTime t = new PrettyTime(locale); - Date date = null; - assertEquals("tadi", t.format(date)); - } - - @Test - public void testRightNow() throws Exception - { - PrettyTime t = new PrettyTime(locale); - assertEquals("tadi", t.format(new Date())); - } - - @Test - public void testRightNowVariance() throws Exception - { - PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("tadi", t.format(new Date(600))); - } - - @Test - public void testMinutesFromNow() throws Exception - { - PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("12 minit kemudian", t.format(new Date(1000 * 60 * 12))); - } - - @Test - public void testHoursFromNow() throws Exception - { - PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("3 jam kemudian", t.format(new Date(1000 * 60 * 60 * 3))); - } - - @Test - public void testDaysFromNow() throws Exception - { - PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("3 hari kemudian", t.format(new Date(1000 * 60 * 60 * 24 * 3))); - } - - @Test - public void testWeeksFromNow() throws Exception - { - PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("3 minggu kemudian", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); - } - - @Test - public void testMonthsFromNow() throws Exception - { - PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("3 bulan kemudian", t.format(new Date(2629743830L * 3L))); - } - - @Test - public void testYearsFromNow() throws Exception - { - PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("3 tahun kemudian", t.format(new Date(2629743830L * 12L * 3L))); - } - - @Test - public void testDecadesFromNow() throws Exception - { - PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("30 tahun kemudian", t.format(new Date(315569259747L * 3L))); - } - - @Test - public void testCenturiesFromNow() throws Exception - { - PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("3 abad kemudian", t.format(new Date(3155692597470L * 3L))); - } - - /* - * Past - */ - @Test - public void testMomentsAgo() throws Exception - { - PrettyTime t = new PrettyTime(new Date(6000), locale); - assertEquals("tadi", t.format(new Date(0))); - } - - @Test - public void testMinutesAgo() throws Exception - { - PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale); - assertEquals("12 minit yang lalu", t.format(new Date(0))); - } - - @Test - public void test1HourAgo() throws Exception - { - PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 1), locale); - assertEquals("1 jam yang lalu", t.format(new Date(0))); - } - - @Test - public void test3HoursAgo() throws Exception - { - PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale); - assertEquals("3 jam yang lalu", t.format(new Date(0))); - } - - @Test - public void test6HoursAgo() throws Exception - { - PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 6), locale); - assertEquals("6 jam yang lalu", t.format(new Date(0))); - } - - @Test - public void testDaysAgo() throws Exception - { - PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale); - assertEquals("3 hari yang lalu", t.format(new Date(0))); - } - - @Test - public void testWeeksAgo() throws Exception - { - PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale); - assertEquals("3 minggu yang lalu", t.format(new Date(0))); - } - - @Test - public void testMonthsAgo() throws Exception - { - PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale); - assertEquals("3 bulan yang lalu", t.format(new Date(0))); - } - - @Test - public void testYearsAgo() throws Exception - { - PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale); - assertEquals("3 tahun yang lalu", t.format(new Date(0))); - } - - @Test - public void test8YearsAgo() throws Exception - { - PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 8L), locale); - assertEquals("8 tahun yang lalu", t.format(new Date(0))); - } - - @Test - public void testDecadesAgo() throws Exception - { - PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale); - assertEquals("30 tahun yang lalu", t.format(new Date(0))); - } - - @Test - public void test8DecadesAgo() throws Exception - { - PrettyTime t = new PrettyTime(new Date(315569259747L * 8L), locale); - assertEquals("80 tahun yang lalu", t.format(new Date(0))); - } - - @Test - public void testCenturiesAgo() throws Exception - { - PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale); - assertEquals("3 abad yang lalu", t.format(new Date(0))); - } +public class Resources_ms extends ListResourceBundle +{ - @After - public void tearDown() throws Exception - { - Locale.setDefault(locale); + private static final Object[][] OBJECTS = new Object[][] { + { "CenturyPattern", "%n %u" }, + { "CenturyFuturePrefix", "" }, + { "CenturyFutureSuffix", "kemudian" }, + { "CenturyPastPrefix", "" }, + { "CenturyPastSuffix", "yang lalu" }, + { "CenturySingularName", "abad" }, + { "CenturyPluralName", "abad" }, + { "DayPattern", "%n %u" }, + { "DayFuturePrefix", "" }, + { "DayFutureSuffix", "kemudian" }, + { "DayPastPrefix", "" }, + { "DayPastSuffix", "yang lalu" }, + { "DaySingularName", "hari" }, + { "DayPluralName", "hari" }, + { "DecadePattern", "%n%u" }, + { "DecadeFuturePrefix", "" }, + { "DecadeFutureSuffix", "kemudian" }, + { "DecadePastPrefix", "" }, + { "DecadePastSuffix", "yang lalu" }, + { "DecadeSingularName", "0 tahun" }, + { "DecadePluralName", "0 tahun" }, + { "HourPattern", "%n %u" }, + { "HourFuturePrefix", "" }, + { "HourFutureSuffix", "kemudian" }, + { "HourPastPrefix", "" }, + { "HourPastSuffix", "yang lalu" }, + { "HourSingularName", "jam" }, + { "HourPluralName", "jam" }, + { "JustNowPattern", "%u" }, + { "JustNowFuturePrefix", "" }, + { "JustNowFutureSuffix", "tadi" }, + { "JustNowPastPrefix", "tadi" }, + { "JustNowPastSuffix", "" }, + { "JustNowSingularName", "" }, + { "JustNowPluralName", "" }, + { "MillenniumPattern", "%n %u" }, + { "MillenniumFuturePrefix", "" }, + { "MillenniumFutureSuffix", "Selepas" }, + { "MillenniumPastPrefix", "" }, + { "MillenniumPastSuffix", "Sebelum ini" }, + { "MillenniumSingularName", "Millennium" }, + { "MillenniumPluralName", "Millennium" }, + { "MillisecondPattern", "%n %u" }, + { "MillisecondFuturePrefix", "" }, + { "MillisecondFutureSuffix", "Selepas ini" }, + { "MillisecondPastPrefix", "" }, + { "MillisecondPastSuffix", "Sebelum" }, + { "MillisecondSingularName", "Milisaat" }, + { "MillisecondPluralName", "Milisaat" }, + { "MinutePattern", "%n %u" }, + { "MinuteFuturePrefix", "" }, + { "MinuteFutureSuffix", "kemudian" }, + { "MinutePastPrefix", "" }, + { "MinutePastSuffix", "yang lalu" }, + { "MinuteSingularName", "minit" }, + { "MinutePluralName", "minit" }, + { "MonthPattern", "%n %u" }, + { "MonthFuturePrefix", "" }, + { "MonthFutureSuffix", "kemudian" }, + { "MonthPastPrefix", "" }, + { "MonthPastSuffix", "yang lalu" }, + { "MonthSingularName", "bulan" }, + { "MonthPluralName", "bulan" }, + { "SecondPattern", "%n %u" }, + { "SecondFuturePrefix", "" }, + { "SecondFutureSuffix", "Selepas" }, + { "SecondPastPrefix", "" }, + { "SecondPastSuffix", "Sebelum ini" }, + { "SecondSingularName", "saat" }, + { "SecondPluralName", "saat" }, + { "WeekPattern", "%n %u" }, + { "WeekFuturePrefix", "" }, + { "WeekFutureSuffix", "kemudian" }, + { "WeekPastPrefix", "" }, + { "WeekPastSuffix", "yang lalu" }, + { "WeekSingularName", "minggu" }, + { "WeekPluralName", "minggu" }, + { "YearPattern", "%n %u" }, + { "YearFuturePrefix", "" }, + { "YearFutureSuffix", "kemudian" }, + { "YearPastPrefix", "" }, + { "YearPastSuffix", "yang lalu" }, + { "YearSingularName", "tahun" }, + { "YearPluralName", "tahun" }, + { "AbstractTimeUnitPattern", "" }, + { "AbstractTimeUnitFuturePrefix", "" }, + { "AbstractTimeUnitFutureSuffix", "" }, + { "AbstractTimeUnitPastPrefix", "" }, + { "AbstractTimeUnitPastSuffix", "" }, + { "AbstractTimeUnitSingularName", "" }, + { "AbstractTimeUnitPluralName", "" } }; + + @Override + protected Object[][] getContents() + { + return OBJECTS; } } From f06fc41e8dfe3528ee0342a9e46a957a34493c9e Mon Sep 17 00:00:00 2001 From: Musasshi90 Date: Tue, 13 Mar 2018 10:41:23 +0800 Subject: [PATCH 017/147] update the typo in testing --- .../org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java index 58eb8192..2d4e8e2d 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java @@ -29,7 +29,7 @@ public void setUp() throws Exception public void testPrettyTime() { PrettyTime p = new PrettyTime(locale); - assertEquals("hanya sekarang", p.format(new Date())); + assertEquals("tadi", p.format(new Date())); } @Test @@ -56,21 +56,21 @@ public void testNullDate() throws Exception { PrettyTime t = new PrettyTime(locale); Date date = null; - assertEquals("hanya sekarang", t.format(date)); + assertEquals("tadi", t.format(date)); } @Test public void testRightNow() throws Exception { PrettyTime t = new PrettyTime(locale); - assertEquals("hanya sekarang", t.format(new Date())); + assertEquals("tadi", t.format(new Date())); } @Test public void testRightNowVariance() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("hanya sekarang", t.format(new Date(600))); + assertEquals("tadi", t.format(new Date(600))); } @Test @@ -136,7 +136,7 @@ public void testCenturiesFromNow() throws Exception public void testMomentsAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(6000), locale); - assertEquals("hanya sekarang", t.format(new Date(0))); + assertEquals("tadi", t.format(new Date(0))); } @Test From a7e4cdef5633468a6807cc39eefea27eb678d87e Mon Sep 17 00:00:00 2001 From: Musasshi90 Date: Tue, 13 Mar 2018 12:13:46 +0800 Subject: [PATCH 018/147] Change some of the typo Change some of the typo --- .../ocpsoft/prettytime/i18n/Resources_ms.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java index 9a8f478f..79fc13f1 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java @@ -59,18 +59,18 @@ public class Resources_ms extends ListResourceBundle { "JustNowPluralName", "" }, { "MillenniumPattern", "%n %u" }, { "MillenniumFuturePrefix", "" }, - { "MillenniumFutureSuffix", "Selepas" }, + { "MillenniumFutureSuffix", "kemudian" }, { "MillenniumPastPrefix", "" }, - { "MillenniumPastSuffix", "Sebelum ini" }, - { "MillenniumSingularName", "Millennium" }, - { "MillenniumPluralName", "Millennium" }, + { "MillenniumPastSuffix", "yang lalu" }, + { "MillenniumSingularName", "millennium" }, + { "MillenniumPluralName", "millennium" }, { "MillisecondPattern", "%n %u" }, { "MillisecondFuturePrefix", "" }, - { "MillisecondFutureSuffix", "Selepas ini" }, + { "MillisecondFutureSuffix", "kemudian" }, { "MillisecondPastPrefix", "" }, - { "MillisecondPastSuffix", "Sebelum" }, - { "MillisecondSingularName", "Milisaat" }, - { "MillisecondPluralName", "Milisaat" }, + { "MillisecondPastSuffix", "yang lalu" }, + { "MillisecondSingularName", "milisaat" }, + { "MillisecondPluralName", "milisaat" }, { "MinutePattern", "%n %u" }, { "MinuteFuturePrefix", "" }, { "MinuteFutureSuffix", "kemudian" }, @@ -87,9 +87,9 @@ public class Resources_ms extends ListResourceBundle { "MonthPluralName", "bulan" }, { "SecondPattern", "%n %u" }, { "SecondFuturePrefix", "" }, - { "SecondFutureSuffix", "Selepas" }, + { "SecondFutureSuffix", "kemudian" }, { "SecondPastPrefix", "" }, - { "SecondPastSuffix", "Sebelum ini" }, + { "SecondPastSuffix", "yang lalu" }, { "SecondSingularName", "saat" }, { "SecondPluralName", "saat" }, { "WeekPattern", "%n %u" }, From 0e1f3e0f24f82bc272a047a4e869acc1ebe2a0b2 Mon Sep 17 00:00:00 2001 From: Ali Akram Date: Wed, 9 May 2018 15:00:11 +0500 Subject: [PATCH 019/147] Create Resources_ur.java --- core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ur.java | 1 + 1 file changed, 1 insertion(+) create mode 100644 core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ur.java diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ur.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ur.java new file mode 100644 index 00000000..ce013625 --- /dev/null +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ur.java @@ -0,0 +1 @@ +hello From d0c45fabb61cdc453de272b4769dda79437b09db Mon Sep 17 00:00:00 2001 From: "ali.akram" Date: Wed, 9 May 2018 16:09:44 +0500 Subject: [PATCH 020/147] Added Urdu unit --- .../ocpsoft/prettytime/i18n/Resources_ur.java | 124 +++++++++++++++++- 1 file changed, 123 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ur.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ur.java index ce013625..844d7970 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ur.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ur.java @@ -1 +1,123 @@ -hello +/* + * Copyright 2012 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ocpsoft.prettytime.i18n; + +import java.util.ListResourceBundle; + +public class Resources_en extends ListResourceBundle +{ + private static final Object[][] OBJECTS = new Object[][] { + + { "CenturyPattern", "%n %u" }, + { "CenturyFuturePrefix", "" }, + { "CenturyFutureSuffix", " ابھی سے" }, + { "CenturyPastPrefix", "" }, + { "CenturyPastSuffix", " پہلے" }, + { "CenturySingularName", "صدی" }, + { "CenturyPluralName", "صدیوں" }, + { "DayPattern", "%n %u" }, + { "DayFuturePrefix", "" }, + { "DayFutureSuffix", " ابھی سے" }, + { "DayPastPrefix", "" }, + { "DayPastSuffix", " پہلے" }, + { "DaySingularName", "دن" }, + { "DayPluralName", "دنوں" }, + { "DecadePattern", "%n %u" }, + { "DecadeFuturePrefix", "" }, + { "DecadeFutureSuffix", " ابھی سے" }, + { "DecadePastPrefix", "" }, + { "DecadePastSuffix", " پہلے" }, + { "DecadeSingularName", "دہائی" }, + { "DecadePluralName", "دہائی" }, + { "HourPattern", "%n %u" }, + { "HourFuturePrefix", "" }, + { "HourFutureSuffix", " ابھی سے" }, + { "HourPastPrefix", "" }, + { "HourPastSuffix", " پہلے" }, + { "HourSingularName", "گھنٹہ" }, + { "HourPluralName", "گھنٹے" }, + { "JustNowPattern", "%u" }, + { "JustNowFuturePrefix", "" }, + { "JustNowFutureSuffix", "اب سے لمحات" }, + { "JustNowPastPrefix", "لمحات پہلے" }, + { "JustNowPastSuffix", "" }, + { "JustNowSingularName", "" }, + { "JustNowPluralName", "" }, + { "MillenniumPattern", "%n %u" }, + { "MillenniumFuturePrefix", "" }, + { "MillenniumFutureSuffix", " ابھی سے" }, + { "MillenniumPastPrefix", "" }, + { "MillenniumPastSuffix", " پہلے" }, + { "MillenniumSingularName", "ہزار سال" }, + { "MillenniumPluralName", "صدیوں" }, + { "MillisecondPattern", "%n %u" }, + { "MillisecondFuturePrefix", "" }, + { "MillisecondFutureSuffix", " ابھی سے" }, + { "MillisecondPastPrefix", "" }, + { "MillisecondPastSuffix", " پہلے" }, + { "MillisecondSingularName", "ملی سیکنڈ" }, + { "MillisecondPluralName", "ملی سیکنڈ" }, + { "MinutePattern", "%n %u" }, + { "MinuteFuturePrefix", "" }, + { "MinuteFutureSuffix", " ابھی سے" }, + { "MinutePastPrefix", "" }, + { "MinutePastSuffix", " پہلے" }, + { "MinuteSingularName", "منٹ" }, + { "MinutePluralName", "منٹس " }, + { "MonthPattern", "%n %u" }, + { "MonthFuturePrefix", "" }, + { "MonthFutureSuffix", " ابھی سے" }, + { "MonthPastPrefix", "" }, + { "MonthPastSuffix", " پہلے" }, + { "MonthSingularName", "مہینہ " }, + { "MonthPluralName", "مہینے" }, + { "SecondPattern", "%n %u" }, + { "SecondFuturePrefix", "" }, + { "SecondFutureSuffix", " ابھی سے" }, + { "SecondPastPrefix", "" }, + { "SecondPastSuffix", " پہلے" }, + { "SecondSingularName", "سیکنڈ" }, + { "SecondPluralName", " سیکنڈز" }, + { "WeekPattern", "%n %u" }, + { "WeekFuturePrefix", "" }, + { "WeekFutureSuffix", " ابھی سے" }, + { "WeekPastPrefix", "" }, + { "WeekPastSuffix", " پہلے" }, + { "WeekSingularName", "ہفتہ" }, + { "WeekPluralName", "ہفتے" }, + { "YearPattern", "%n %u" }, + { "YearFuturePrefix", "" }, + { "YearFutureSuffix", " ابھی سے" }, + { "YearPastPrefix", "" }, + { "YearPastSuffix", " پہلے" }, + { "YearSingularName", "سال" }, + { "YearPluralName", "سالو" }, + { "AbstractTimeUnitPattern", "" }, + { "AbstractTimeUnitFuturePrefix", "" }, + { "AbstractTimeUnitFutureSuffix", "" }, + { "AbstractTimeUnitPastPrefix", "" }, + { "AbstractTimeUnitPastSuffix", "" }, + { "AbstractTimeUnitSingularName", "" }, + { "AbstractTimeUnitPluralName", "" } }; + + + @Override + public Object[][] getContents() + { + return OBJECTS; + } + +} \ No newline at end of file From 8a742bd1d8eaacc2a36865d144a43ea0211e25b7 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Mon, 21 May 2018 10:44:24 -0400 Subject: [PATCH 021/147] Fix compilation error --- .../main/java/org/ocpsoft/prettytime/i18n/Resources_ur.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ur.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ur.java index 844d7970..81ee329b 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ur.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ur.java @@ -17,7 +17,7 @@ import java.util.ListResourceBundle; -public class Resources_en extends ListResourceBundle +public class Resources_ur extends ListResourceBundle { private static final Object[][] OBJECTS = new Object[][] { @@ -120,4 +120,4 @@ public Object[][] getContents() return OBJECTS; } -} \ No newline at end of file +} From d42a9111128a3ccedfd10066e6ccba351a40b0f9 Mon Sep 17 00:00:00 2001 From: david-serrano Date: Tue, 7 Aug 2018 14:22:15 +0100 Subject: [PATCH 022/147] add Bengali translations --- .../ocpsoft/prettytime/i18n/Resources_bn.java | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_bn.java diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_bn.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_bn.java new file mode 100644 index 00000000..29a01e37 --- /dev/null +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_bn.java @@ -0,0 +1,120 @@ +/* + * Copyright 2012 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ocpsoft.prettytime.i18n; + +import java.util.ListResourceBundle; + +public class Resources_bg extends ListResourceBundle +{ + private static final Object[][] OBJECTS = new Object[][] { + { "CenturyPattern", "%n %u" }, + { "CenturyFuturePrefix", "" }, + { "CenturyFutureSuffix", " এখন থেকে" }, + { "CenturyPastPrefix", "" }, + { "CenturyPastSuffix", " আগে" }, + { "CenturySingularName", "শতাব্দী" }, + { "CenturyPluralName", "শতাব্দীর পর শতাব্দী" }, + { "DayPattern", "%n %u" }, + { "DayFuturePrefix", "" }, + { "DayFutureSuffix", " এখন থেকে" }, + { "DayPastPrefix", "" }, + { "DayPastSuffix", " আগে" }, + { "DaySingularName", "দিন" }, + { "DayPluralName", "দিন" }, + { "DecadePattern", "%n %u" }, + { "DecadeFuturePrefix", "" }, + { "DecadeFutureSuffix", " এখন থেকে" }, + { "DecadePastPrefix", "" }, + { "DecadePastSuffix", " আগে" }, + { "DecadeSingularName", "দশক" }, + { "DecadePluralName", "কয়েক দশক ধরে" }, + { "HourPattern", "%n %u" }, + { "HourFuturePrefix", "" }, + { "HourFutureSuffix", " এখন থেকে" }, + { "HourPastPrefix", "" }, + { "HourPastSuffix", " আগে" }, + { "HourSingularName", "ঘন্টা" }, + { "HourPluralName", "ঘন্টার" }, + { "JustNowPattern", "%u" }, + { "JustNowFuturePrefix", "" }, + { "JustNowFutureSuffix", "" }, + { "JustNowPastPrefix", "এই মাত্র" }, + { "JustNowPastSuffix", "" }, + { "JustNowSingularName", "" }, + { "JustNowPluralName", "" }, + { "MillenniumPattern", "%n %u" }, + { "MillenniumFuturePrefix", "" }, + { "MillenniumFutureSuffix", " এখন থেকে" }, + { "MillenniumPastPrefix", "" }, + { "MillenniumPastSuffix", " আগে" }, + { "MillenniumSingularName", "সহস্রক" }, + { "MillenniumPluralName", "সহস্রাব্দ" }, + { "MillisecondPattern", "%n %u" }, + { "MillisecondFuturePrefix", "" }, + { "MillisecondFutureSuffix", " এখন থেকে" }, + { "MillisecondPastPrefix", "" }, + { "MillisecondPastSuffix", " আগে" }, + { "MillisecondSingularName", "মিলিসেকেন্ডে" }, + { "MillisecondPluralName", "মিলিসেকেন্ড" }, + { "MinutePattern", "%n %u" }, + { "MinuteFuturePrefix", "" }, + { "MinuteFutureSuffix", " এখন থেকে" }, + { "MinutePastPrefix", "" }, + { "MinutePastSuffix", " আগে" }, + { "MinuteSingularName", "মিনিট" }, + { "MinutePluralName", "কয়েক মিনিট" }, + { "MonthPattern", "%n %u" }, + { "MonthFuturePrefix", "" }, + { "MonthFutureSuffix", " এখন থেকে" }, + { "MonthPastPrefix", "" }, + { "MonthPastSuffix", " আগে" }, + { "MonthSingularName", "মাস" }, + { "MonthPluralName", "কয়েক মাস" }, + { "SecondPattern", "%n %u" }, + { "SecondFuturePrefix", " এখন থেকে" }, + { "SecondFutureSuffix", "" }, + { "SecondPastPrefix", "" }, + { "SecondPastSuffix", " আগে" }, + { "SecondSingularName", "দ্বিতীয়" }, + { "SecondPluralName", "সেকেন্ড" }, + { "WeekPattern", "%n %u" }, + { "WeekFuturePrefix", "" }, + { "WeekFutureSuffix", " এখন থেকে" }, + { "WeekPastPrefix", "" }, + { "WeekPastSuffix", " আগে" }, + { "WeekSingularName", "সপ্তাহ" }, + { "WeekPluralName", "কয়েক সপ্তাহ" }, + { "YearPattern", "%n %u" }, + { "YearFuturePrefix", "" }, + { "YearFutureSuffix", " এখন থেকে" }, + { "YearPastPrefix", "" }, + { "YearPastSuffix", " আগে" }, + { "YearSingularName", "বছর" }, + { "YearPluralName", "কয়েক বছর" }, + { "AbstractTimeUnitPattern", "" }, + { "AbstractTimeUnitFuturePrefix", "" }, + { "AbstractTimeUnitFutureSuffix", "" }, + { "AbstractTimeUnitPastPrefix", "" }, + { "AbstractTimeUnitPastSuffix", "" }, + { "AbstractTimeUnitSingularName", "" }, + { "AbstractTimeUnitPluralName", "" } }; + + @Override + public Object[][] getContents() + { + return OBJECTS; + } +} From 259a8dec822c2830ca9ed5960e94931b9392111d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=E1=BA=A1m=20Ti=E1=BA=BFn=20Th=C3=A0nh?= Date: Mon, 20 Aug 2018 23:45:02 +0530 Subject: [PATCH 023/147] Update translation for Vietnamese Update "JustNow" section --- .../main/java/org/ocpsoft/prettytime/i18n/Resources_vi.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_vi.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_vi.java index d9dddd1b..13508f16 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_vi.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_vi.java @@ -50,9 +50,9 @@ public class Resources_vi extends ListResourceBundle { "HourPluralName", "giờ" }, { "JustNowPattern", "%u" }, { "JustNowFuturePrefix", "" }, - { "JustNowFutureSuffix", " khắc sau" }, + { "JustNowFutureSuffix", " vài giây" }, { "JustNowPastPrefix", "cách đây " }, - { "JustNowPastSuffix", " khắc" }, + { "JustNowPastSuffix", " giây" }, { "JustNowSingularName", "" }, { "JustNowPluralName", "" }, { "MillenniumPattern", "%n %u" }, @@ -118,4 +118,4 @@ public Object[][] getContents() return OBJECTS; } -} \ No newline at end of file +} From 8f889276a09ea440430e36da94b9389a3fb9b822 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Thu, 14 Feb 2019 21:03:30 +0400 Subject: [PATCH 024/147] Fixed that setLocale method can't change format language It's a bug with mutable cached units. If you call setLocale to change language then cached units is not updated and will return old values (e.g. language don't switches). --- core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index 3517ff80..914a538e 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -728,6 +728,7 @@ public PrettyTime setLocale(Locale locale) if (format instanceof LocaleAware) ((LocaleAware) format).setLocale(locale); } + cachedUnits = null; return this; } From 602b3a9bb6efbc9f7032fb7307f4866227aa4135 Mon Sep 17 00:00:00 2001 From: Josh Friend Date: Fri, 11 Oct 2019 15:07:55 -0400 Subject: [PATCH 025/147] Add consumer proguard rules This will automatically configure proguard for R8 shrinker users --- README.md | 8 +++----- core/src/main/resources/META-INF/proguard/prettytime.pro | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) create mode 100644 core/src/main/resources/META-INF/proguard/prettytime.pro diff --git a/README.md b/README.md index bcf2efcc..e6545487 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,11 @@ Learn more at http://ocpsoft.org/prettytime/ Android ======= -To use prettytime in android, first add the following dependency to your app level build.gradle +To use prettytime in android, first add the following dependency to your app level build.gradle - compile 'org.ocpsoft.prettytime:prettytime:4.0.1.Final' + implementation 'org.ocpsoft.prettytime:prettytime:4.0.1.Final' -When using Android with ProGuard, you must add the following to your ProGuard configuration script: - - -keep class org.ocpsoft.prettytime.i18n.** +ProGuard rules are automatically configured for you if you use the R8 shrinker (which is the default since version 3.4.0 of the Android Gradle Plugin). If you are using an older version of AGP, add the ProGuard rules from [this file](core/src/main/resources/META-INF/proguard/prettytime.pro) DEVELOPMENT =========== diff --git a/core/src/main/resources/META-INF/proguard/prettytime.pro b/core/src/main/resources/META-INF/proguard/prettytime.pro new file mode 100644 index 00000000..83144338 --- /dev/null +++ b/core/src/main/resources/META-INF/proguard/prettytime.pro @@ -0,0 +1 @@ +-keep class org.ocpsoft.prettytime.i18n.** From 50824d52ded618ad9927410921a45d3096fabbc3 Mon Sep 17 00:00:00 2001 From: bopol Date: Fri, 10 Jan 2020 10:52:41 +0100 Subject: [PATCH 026/147] fixed bengali file written bg instead of bn --- .../src/main/java/org/ocpsoft/prettytime/i18n/Resources_bn.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_bn.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_bn.java index 29a01e37..75ba2495 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_bn.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_bn.java @@ -17,7 +17,7 @@ import java.util.ListResourceBundle; -public class Resources_bg extends ListResourceBundle +public class Resources_bn extends ListResourceBundle { private static final Object[][] OBJECTS = new Object[][] { { "CenturyPattern", "%n %u" }, From 6b8904276cb8421aa0d78aee8aef1bc4af7e5e74 Mon Sep 17 00:00:00 2001 From: bopol Date: Fri, 10 Jan 2020 11:46:37 +0100 Subject: [PATCH 027/147] added esperanto --- .../ocpsoft/prettytime/i18n/Resources_eo.java | 105 +++++ .../prettytime/PrettyTimeI18n_EO_Test.java | 421 ++++++++++++++++++ 2 files changed, 526 insertions(+) create mode 100644 core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_eo.java create mode 100644 core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_EO_Test.java diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_eo.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_eo.java new file mode 100644 index 00000000..7c946d83 --- /dev/null +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_eo.java @@ -0,0 +1,105 @@ +package org.ocpsoft.prettytime.i18n; + +import java.util.ListResourceBundle; + +public class Resources_eo extends ListResourceBundle { + + private static final Object[][] OBJECTS = new Object[][]{ + {"CenturyPattern", "%n %u"}, + {"CenturyFuturePrefix", "post "}, + {"CenturyFutureSuffix", ""}, + {"CenturyPastPrefix", "antaŭ "}, + {"CenturyPastSuffix", ""}, + {"CenturySingularName", "jarcento"}, + {"CenturyPluralName", "jarcentoj"}, + {"DayPattern", "%n %u"}, + {"DayFuturePrefix", "post "}, + {"DayFutureSuffix", ""}, + {"DayPastPrefix", "antaŭ "}, + {"DayPastSuffix", ""}, + {"DaySingularName", "tago"}, + {"DayPluralName", "tagoj"}, + {"DecadePattern", "%n %u"}, + {"DecadeFuturePrefix", "post "}, + {"DecadeFutureSuffix", ""}, + {"DecadePastPrefix", "antaŭ "}, + {"DecadePastSuffix", ""}, + {"DecadeSingularName", "jardeko"}, + {"DecadePluralName", "jardekoj"}, + {"HourPattern", "%n %u"}, + {"HourFuturePrefix", "post "}, + {"HourFutureSuffix", ""}, + {"HourPastPrefix", "antaŭ "}, + {"HourPastSuffix", ""}, + {"HourSingularName", "horo"}, + {"HourPluralName", "horoj"}, + {"JustNowPattern", "%u"}, + {"JustNowFuturePrefix", ""}, + {"JustNowFutureSuffix", "nun"}, + {"JustNowPastPrefix", "nun"}, + {"JustNowPastSuffix", ""}, + {"JustNowSingularName", ""}, + {"JustNowPluralName", ""}, + {"MillenniumPattern", "%n %u"}, + {"MillenniumFuturePrefix", "post "}, + {"MillenniumFutureSuffix", ""}, + {"MillenniumPastPrefix", "antaŭ "}, + {"MillenniumPastSuffix", ""}, + {"MillenniumSingularName", "jarmilo"}, + {"MillenniumPluralName", "jarmiloj"}, + {"MillisecondPattern", "%n %u"}, + {"MillisecondFuturePrefix", "post "}, + {"MillisecondFutureSuffix", ""}, + {"MillisecondPastPrefix", "antaŭ "}, + {"MillisecondPastSuffix", ""}, + {"MillisecondSingularName", "milisekundo"}, + {"MillisecondPluralName", "milisekundoj"}, + {"MinutePattern", "%n %u"}, + {"MinuteFuturePrefix", "post "}, + {"MinuteFutureSuffix", ""}, + {"MinutePastPrefix", "antaŭ "}, + {"MinutePastSuffix", ""}, + {"MinuteSingularName", "minuto"}, + {"MinutePluralName", "minutoj"}, + {"MonthPattern", "%n %u"}, + {"MonthFuturePrefix", "post "}, + {"MonthFutureSuffix", ""}, + {"MonthPastPrefix", "antaŭ "}, + {"MonthPastSuffix", ""}, + {"MonthSingularName", "monato"}, + {"MonthPluralName", "monatoj"}, + {"SecondPattern", "%n %u"}, + {"SecondFuturePrefix", "post "}, + {"SecondFutureSuffix", ""}, + {"SecondPastPrefix", "antaŭ "}, + {"SecondPastSuffix", ""}, + {"SecondSingularName", "sekundo"}, + {"SecondPluralName", "sekundoj"}, + {"WeekPattern", "%n %u"}, + {"WeekFuturePrefix", "post "}, + {"WeekFutureSuffix", ""}, + {"WeekPastPrefix", "antaŭ "}, + {"WeekPastSuffix", ""}, + {"WeekSingularName", "semajno"}, + {"WeekPluralName", "semajnoj"}, + {"YearPattern", "%n %u"}, + {"YearFuturePrefix", "post "}, + {"YearFutureSuffix", ""}, + {"YearPastPrefix", "antaŭ "}, + {"YearPastSuffix", ""}, + {"YearSingularName", "jaro"}, + {"YearPluralName", "jaroj"}, + {"AbstractTimeUnitPattern", ""}, + {"AbstractTimeUnitFuturePrefix", ""}, + {"AbstractTimeUnitFutureSuffix", ""}, + {"AbstractTimeUnitPastPrefix", ""}, + {"AbstractTimeUnitPastSuffix", ""}, + {"AbstractTimeUnitSingularName", ""}, + {"AbstractTimeUnitPluralName", ""} + }; + + @Override + protected Object[][] getContents() { + return OBJECTS; + } +} 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 new file mode 100644 index 00000000..eb446e45 --- /dev/null +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_EO_Test.java @@ -0,0 +1,421 @@ +/* + * Copyright 2012 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ocpsoft.prettytime; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +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_EO_Test { + SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); + + private Locale locale; + + @Before + public void setUp() throws Exception { + locale = new Locale("eo"); + Locale.setDefault(locale); + } + + @Test + public void testCeilingInterval() throws Exception { + Date then = format.parse("5/20/2009"); + Date ref = format.parse("6/17/2009"); + PrettyTime t = new PrettyTime(ref); + Assert.assertEquals("antaŭ 1 monato", t.format(then)); + } + + @Test + public void testNullDate() throws Exception { + PrettyTime t = new PrettyTime(); + Date date = null; + Assert.assertEquals("nun", t.format(date)); + } + + @Test + public void testRightNow() throws Exception { + PrettyTime t = new PrettyTime(); + Assert.assertEquals("nun", t.format(new Date())); + } + + @Test + public void testCalculatePreciceDuration() throws Exception { + PrettyTime t = new PrettyTime(); + List preciseDuration = t.calculatePreciseDuration( + new Date(System.currentTimeMillis() - (2 * 60 * 60 * 1000) - (2 * 60 * 1000))); + Assert.assertEquals("antaŭ 2 horoj 2 minutoj", t.format(preciseDuration)); + Assert.assertEquals("2 horoj 2 minutoj", t.formatDuration(preciseDuration)); + Assert.assertEquals("nun", t.format(t.calculatePreciseDuration(new Date()))); + } + + @Test + @SuppressWarnings("deprecation") + 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("antaŭ 1 jarmilo 9 jarcentoj 4 jardekoj 4 jaroj 8 monatoj 1 semajno 6 tagoj 14 horoj 5 minutoj", + t.format(durations)); + Assert.assertEquals("1 jarmilo 9 jarcentoj 4 jardekoj 4 jaroj 8 monatoj 1 semajno 6 tagoj 14 horoj 5 minutoj", + t.formatDuration(durations)); + } + + @Test + public void testCalculatePreciseDuration2() { + PrettyTime prettyTime = new PrettyTime(); + prettyTime.clearUnits(); + Minute minutoj = new Minute(); + prettyTime.registerUnit(minutoj, new ResourcesTimeFormat(minutoj)); + Assert.assertEquals("antaŭ 40 minutoj", prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + } + + @Test + public void testRightNowVariance() throws Exception { + PrettyTime t = new PrettyTime(new Date(0)); + Assert.assertEquals("nun", t.format(new Date(600))); + } + + @Test + public void testMinutesFromNow() throws Exception { + PrettyTime t = new PrettyTime(new Date(0)); + Assert.assertEquals("post 12 minutoj", t.format(new Date(1000 * 60 * 12))); + } + + @Test + public void testHoursFromNow() throws Exception { + PrettyTime t = new PrettyTime(new Date(0)); + Assert.assertEquals("post 3 horoj", t.format(new Date(1000 * 60 * 60 * 3))); + } + + @Test + public void testDaysFromNow() throws Exception { + PrettyTime t = new PrettyTime(new Date(0)); + Assert.assertEquals("post 3 tagoj", t.format(new Date(1000 * 60 * 60 * 24 * 3))); + } + + @Test + public void testWeeksFromNow() throws Exception { + PrettyTime t = new PrettyTime(new Date(0)); + Assert.assertEquals("post 3 semajnoj", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); + } + + @Test + public void testMonthsFromNow() throws Exception { + PrettyTime t = new PrettyTime(new Date(0)); + Assert.assertEquals("post 3 monatoj", t.format(new Date(2629743830L * 3L))); + } + + @Test + public void testYearsFromNow() throws Exception { + PrettyTime t = new PrettyTime(new Date(0)); + Assert.assertEquals("post 3 jaroj", t.format(new Date(2629743830L * 12L * 3L))); + } + + @Test + public void testDecadesFromNow() throws Exception { + PrettyTime t = new PrettyTime(new Date(0)); + Assert.assertEquals("post 3 jardekoj", t.format(new Date(315569259747L * 3L))); + } + + @Test + public void testCenturiesFromNow() throws Exception { + PrettyTime t = new PrettyTime(new Date(0)); + Assert.assertEquals("post 3 jarcentoj", t.format(new Date(3155692597470L * 3L))); + } + + /* + * Past + */ + @Test + public void testMomentsAgo() throws Exception { + PrettyTime t = new PrettyTime(new Date(6000)); + Assert.assertEquals("nun", t.format(new Date(0))); + } + + @Test + public void testMinutesAgo() throws Exception { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12)); + Assert.assertEquals("antaŭ 12 minutoj", t.format(new Date(0))); + } + + @Test + public void testMinutesFromNowDefaultReference() throws Exception { + PrettyTime t = new PrettyTime(); + Assert.assertEquals("post 12 minutoj", t.format(new Date(System.currentTimeMillis() + 1000 * 60 * 12))); + } + + @Test + public void testHoursAgo() throws Exception { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3)); + Assert.assertEquals("antaŭ 3 horoj", t.format(new Date(0))); + } + + @Test + public void testHoursAgoDefaultReference() throws Exception { + PrettyTime t = new PrettyTime(); + Assert.assertEquals("antaŭ 3 horoj", t.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 3))); + } + + @Test + public void testDaysAgo() throws Exception { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3)); + Assert.assertEquals("antaŭ 3 tagoj", t.format(new Date(0))); + } + + @Test + public void testWeeksAgo() throws Exception { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3)); + Assert.assertEquals("antaŭ 3 semajnoj", t.format(new Date(0))); + } + + @Test + public void testMonthsAgo() throws Exception { + PrettyTime t = new PrettyTime(new Date(2629743830L * 3L)); + Assert.assertEquals("antaŭ 3 monatoj", t.format(new Date(0))); + } + + @Test + public void testCustomFormat() throws Exception { + PrettyTime t = new PrettyTime(new Date(0)); + TimeUnit unit = new TimeUnit() { + @Override + public long getMaxQuantity() { + return 0; + } + + @Override + public long getMillisPerUnit() { + return 5000; + } + + @Override + public boolean isPrecise() { + return false; + } + }; + 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( + "...")); + + Assert.assertEquals("self destruct in: 5 ticks ... RUN!", t.format(new Date(25000))); + t.setReference(new Date(25000)); + Assert.assertEquals("self destruct was: 5 ticks ...", t.format(new Date(0))); + } + + @Test + public void testYearsAgo() throws Exception { + PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L)); + Assert.assertEquals("antaŭ 3 jaroj", t.format(new Date(0))); + } + + @Test + public void testDecadesAgo() throws Exception { + PrettyTime t = new PrettyTime(new Date(315569259747L * 3L)); + Assert.assertEquals("antaŭ 3 jardekoj", t.format(new Date(0))); + } + + @Test + public void testCenturiesAgo() throws Exception { + PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L)); + Assert.assertEquals("antaŭ 3 jarcentoj", t.format(new Date(0))); + } + + @Test + public void testWithinTwoHoursRounding() throws Exception { + PrettyTime t = new PrettyTime(); + Assert.assertEquals("antaŭ 2 horoj", t.format(new Date(new Date().getTime() - 6543990))); + } + + @Test + public void testPreciseInTheFuture() throws Exception { + PrettyTime t = new PrettyTime(); + List durations = t.calculatePreciseDuration(new Date(new Date().getTime() + 1000 + * (10 * 60 + 5 * 60 * 60))); + Assert.assertTrue(durations.size() >= 2); + Assert.assertEquals(5, durations.get(0).getQuantity()); + Assert.assertEquals(10, durations.get(1).getQuantity()); + } + + @Test + public void testPreciseInThePast() throws Exception { + PrettyTime t = new PrettyTime(); + List durations = t.calculatePreciseDuration(new Date(new Date().getTime() - 1000 + * (10 * 60 + 5 * 60 * 60))); + Assert.assertTrue(durations.size() >= 2); + Assert.assertEquals(-5, durations.get(0).getQuantity()); + Assert.assertEquals(-10, durations.get(1).getQuantity()); + } + + @Test + public void testFormattingDurationListInThePast() throws Exception { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3 + 1000 * 60 * 60 * 15 + 1000 * 60 * 38)); + List durations = t.calculatePreciseDuration(new Date(0)); + Assert.assertEquals("antaŭ 3 tagoj 15 horoj 38 minutoj", t.format(durations)); + } + + @Test + 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)); + Assert.assertEquals("post 3 tagoj 15 horoj 38 minutoj", t.format(durations)); + } + + @Test + public void testSetLocale() throws Exception { + PrettyTime t = new PrettyTime(new Date(315569259747L * 3L)); + Assert.assertEquals("antaŭ 3 jardekoj", t.format(new Date(0))); + t.setLocale(Locale.GERMAN); + Assert.assertEquals("vor 3 Jahrzehnten", t.format(new Date(0))); + } + + /** + * 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 { + Calendar c = Calendar.getInstance(); + Date r = c.getTime(); + PrettyTime t = new PrettyTime(); + t.setLocale(Locale.ENGLISH); + t.setReference(r); + c.add(Calendar.YEAR, -1); + Assert.assertEquals("1 year", t.format(c)); + } + + /** + * Tests formatApproximateDuration and by proxy, formatDuration. + * + * @throws Exception + */ + @Test + 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(); + String result = t.formatDuration(tenMinAgo); + Assert.assertTrue(result.equals("10 minutoj")); + } + + @Test + 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(); + String result = t.formatDuration(tenMinAgo); + Assert.assertTrue(result.equals("11 minutoj")); + } + + @Test + 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(); + String result = t.formatDurationUnrounded(tenMinAgo); + Assert.assertTrue(result.equals("10 minutoj")); + } + + @Test + public void testFormatList() throws Exception { + PrettyTime prettyTime = new PrettyTime(); + prettyTime.clearUnits(); + Minute minutoj = new Minute(); + prettyTime.registerUnit(minutoj, new ResourcesTimeFormat(minutoj)); + Assert.assertEquals("antaŭ 41 minutoj", + prettyTime.format(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + } + + @Test + public void testFormatListUnrounded() throws Exception { + PrettyTime prettyTime = new PrettyTime(); + prettyTime.clearUnits(); + Minute minutoj = new Minute(); + prettyTime.registerUnit(minutoj, new ResourcesTimeFormat(minutoj)); + Assert.assertEquals("antaŭ 40 minutoj", + prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + } + + @Test + public void testFormatDurationList() throws Exception { + PrettyTime prettyTime = new PrettyTime(); + prettyTime.clearUnits(); + Minute minutoj = new Minute(); + prettyTime.registerUnit(minutoj, new ResourcesTimeFormat(minutoj)); + Assert.assertEquals("41 minutoj", + prettyTime.formatDuration(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + } + + @Test + public void testFormatDurationListUnrounded() throws Exception { + PrettyTime prettyTime = new PrettyTime(); + prettyTime.clearUnits(); + Minute minutoj = new Minute(); + prettyTime.registerUnit(minutoj, new ResourcesTimeFormat(minutoj)); + Assert.assertEquals("40 minutoj", + prettyTime.formatDurationUnrounded(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + } + + @Test + public void testCalculatePreciseDuration() { + PrettyTime prettyTime = new PrettyTime(); + prettyTime.clearUnits(); + Minute minutoj = new Minute(); + prettyTime.registerUnit(minutoj, new ResourcesTimeFormat(minutoj)); + Assert.assertEquals("antaŭ 41 minutoj", + prettyTime.format(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + } + + @Test + public void testCalculatePreciseDurationUnrounded() { + PrettyTime prettyTime = new PrettyTime(); + prettyTime.clearUnits(); + Minute minutoj = new Minute(); + prettyTime.registerUnit(minutoj, new ResourcesTimeFormat(minutoj)); + Assert.assertEquals("antaŭ 40 minutoj", + prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( + new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + } + + @After + public void tearDown() throws Exception { + Locale.setDefault(locale); + } + +} From 0407d194788f31dfeb087dd367fecf66ed43b5fc Mon Sep 17 00:00:00 2001 From: bopol Date: Fri, 10 Jan 2020 11:50:46 +0100 Subject: [PATCH 028/147] fixed testCalculatePreciceDurationMillenia() in english test file. see https://i.imgur.com/A9H9U1d.png --- core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java index 7c546679..7a60f2ef 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java @@ -84,9 +84,9 @@ 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 millennium 9 centuries 4 decades 4 years 8 months 1 week 6 days 20 hours 5 minutes ago", + Assert.assertEquals("1 millennium 9 centuries 4 decades 4 years 8 months 1 week 6 days 14 hours 5 minutes ago", t.format(durations)); - Assert.assertEquals("1 millennium 9 centuries 4 decades 4 years 8 months 1 week 6 days 20 hours 5 minutes", + Assert.assertEquals("1 millennium 9 centuries 4 decades 4 years 8 months 1 week 6 days 14 hours 5 minutes", t.formatDuration(durations)); } From e97389ad792e1c770ec09eb49440a750d153926a Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sun, 26 Jan 2020 11:53:28 -0500 Subject: [PATCH 029/147] Update parent pom --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ad085bb6..ad47b05f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft ocpsoft-parent - 14 + 15 org.ocpsoft.prettytime From 5c28499f1dbf35e281b5ca8133636be3932ffc60 Mon Sep 17 00:00:00 2001 From: Oliver Becker Date: Thu, 6 Feb 2020 21:35:23 +0100 Subject: [PATCH 030/147] Fix #180: Not working setLocale method --- .../java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java index 2e8a0106..6dafa2c3 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java +++ b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java @@ -15,7 +15,6 @@ */ public class ResourcesTimeFormat extends SimpleTimeFormat implements TimeFormat, LocaleAware { - private ResourceBundle bundle; private final ResourcesTimeUnit unit; private TimeFormat override; private String overrideResourceBundle; // If used this bundle will override the included bundle @@ -34,6 +33,7 @@ public ResourcesTimeFormat(ResourcesTimeUnit unit, String overrideResourceBundle @Override public ResourcesTimeFormat setLocale(Locale locale) { + ResourceBundle bundle = null; if (overrideResourceBundle != null) { try { // Attempt to load the bundle that the user passed in, maybe it exists, maybe not @@ -117,4 +117,4 @@ public String formatUnrounded(Duration duration) { return override == null ? super.formatUnrounded(duration) : override.formatUnrounded(duration); } -} \ No newline at end of file +} From aa34e7df6daa97a057133a4dc190b1e2ddf76d42 Mon Sep 17 00:00:00 2001 From: Michael LAGUERRE Date: Mon, 17 Feb 2020 11:47:19 +0100 Subject: [PATCH 031/147] Added latin serbian --- .../prettytime/i18n/Resources_sr_Latn.java | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sr_Latn.java diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sr_Latn.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sr_Latn.java new file mode 100644 index 00000000..b865bc99 --- /dev/null +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sr_Latn.java @@ -0,0 +1,122 @@ +/* + * Copyright 2012 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ocpsoft.prettytime.i18n; + +import java.util.ListResourceBundle; + +public class Resources_sr_Latn extends ListResourceBundle +{ + + private static final Object[][] OBJECTS = new Object[][] + { + {"CenturyPattern", "%n %u"}, + {"CenturyFuturePrefix", "za "}, + {"CenturyFutureSuffix", ""}, + {"CenturyPastPrefix", "pre "}, + {"CenturyPastSuffix", ""}, + {"CenturySingularName", "veka"}, + {"CenturyPluralName", "vekova"}, + {"DayPattern", "%n %u"}, + {"DayFuturePrefix", "za "}, + {"DayFutureSuffix", ""}, + {"DayPastPrefix", "pre "}, + {"DayPastSuffix", ""}, + {"DaySingularName", "dan"}, + {"DayPluralName", "dana"}, + {"DecadePattern", "%n %u"}, + {"DecadeFuturePrefix", "za "}, + {"DecadeFutureSuffix", ""}, + {"DecadePastPrefix", "pre "}, + {"DecadePastSuffix", ""}, + {"DecadeSingularName", "deceniju"}, + {"DecadePluralName", "decenija"}, + {"HourPattern", "%n %u"}, + {"HourFuturePrefix", "za "}, + {"HourFutureSuffix", ""}, + {"HourPastPrefix", "pre "}, + {"HourPastSuffix", ""}, + {"HourSingularName", "sat"}, + {"HourPluralName", "sati"}, + {"JustNowPattern", "%u"}, + {"JustNowFuturePrefix", ""}, + {"JustNowFutureSuffix", "upravo sada"}, + {"JustNowPastPrefix", "upravo sada"}, + {"JustNowPastSuffix", ""}, + {"JustNowSingularName", ""}, + {"JustNowPluralName", ""}, + {"MillenniumPattern", "%n %u"}, + {"MillenniumFuturePrefix", "za "}, + {"MillenniumFutureSuffix", ""}, + {"MillenniumPastPrefix", "pre "}, + {"MillenniumPastSuffix", ""}, + {"MillenniumSingularName", "milenijuma"}, + {"MillenniumPluralName", "milenijuma"}, + {"MillisecondPattern", "%n %u"}, + {"MillisecondFuturePrefix", "za "}, + {"MillisecondFutureSuffix", ""}, + {"MillisecondPastPrefix", "pre "}, + {"MillisecondPastSuffix", ""}, + {"MillisecondSingularName", "milisekunde"}, + {"MillisecondPluralName", "milisekundi"}, + {"MinutePattern", "%n %u"}, + {"MinuteFuturePrefix", "za "}, + {"MinuteFutureSuffix", ""}, + {"MinutePastPrefix", "pre "}, + {"MinutePastSuffix", ""}, + {"MinuteSingularName", "minut"}, + {"MinutePluralName", "minuta"}, + {"MonthPattern", "%n %u"}, + {"MonthFuturePrefix", "za "}, + {"MonthFutureSuffix", ""}, + {"MonthPastPrefix", "pre "}, + {"MonthPastSuffix", ""}, + {"MonthSingularName", "mesec"}, + {"MonthPluralName", "meseca"}, + {"SecondPattern", "%n %u"}, + {"SecondFuturePrefix", "za "}, + {"SecondFutureSuffix", ""}, + {"SecondPastPrefix", "pre "}, + {"SecondPastSuffix", ""}, + {"SecondSingularName", "sekundu"}, + {"SecondPluralName", "sekunde"}, + {"WeekPattern", "%n %u"}, + {"WeekFuturePrefix", "za "}, + {"WeekFutureSuffix", ""}, + {"WeekPastPrefix", "pre "}, + {"WeekPastSuffix", ""}, + {"WeekSingularName", "nedelju"}, + {"WeekPluralName", "nedelje"}, + {"YearPattern", "%n %u"}, + {"YearFuturePrefix", "za "}, + {"YearFutureSuffix", ""}, + {"YearPastPrefix", "pre "}, + {"YearPastSuffix", ""}, + {"YearSingularName", "godinu"}, + {"YearPluralName", "godine"}, + {"AbstractTimeUnitPattern", ""}, + {"AbstractTimeUnitFuturePrefix", ""}, + {"AbstractTimeUnitFutureSuffix", ""}, + {"AbstractTimeUnitPastPrefix", ""}, + {"AbstractTimeUnitPastSuffix", ""}, + {"AbstractTimeUnitSingularName", ""}, + {"AbstractTimeUnitPluralName", ""} }; + + @Override + protected Object[][] getContents() + { + return OBJECTS; + } +} From cc534d6b79680fdcd2c198ba6b27c4fee3428038 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sun, 26 Jan 2020 11:54:32 -0500 Subject: [PATCH 032/147] [maven-release-plugin] prepare release 4.0.3.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index eeaa7c75..5862cdbf 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.2-SNAPSHOT + 4.0.3.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 9a8a0bd1..11cecf24 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.2-SNAPSHOT + 4.0.3.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index d80f2c18..efa54bfa 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.2-SNAPSHOT + 4.0.3.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 28e75177..d69bcfd2 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.2-SNAPSHOT + 4.0.3.Final ../pom.xml diff --git a/pom.xml b/pom.xml index ad47b05f..54bd5fee 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 4.0.2-SNAPSHOT + 4.0.3.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -46,7 +46,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 4.0.3.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 57d462ae..d2cfe6ad 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 4.0.2-SNAPSHOT + 4.0.3.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 4.0.2-SNAPSHOT + 4.0.3.Final diff --git a/samples/pom.xml b/samples/pom.xml index 2c68dce7..1e726e19 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.2-SNAPSHOT + 4.0.3.Final 4.0.0 From 67a2ae0a90db5317729baa4ba0dbbaf6f4e42465 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sun, 26 Jan 2020 11:54:32 -0500 Subject: [PATCH 033/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 5862cdbf..94ac56ff 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.3.Final + 4.0.4-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 11cecf24..c942eb88 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.3.Final + 4.0.4-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index efa54bfa..7b12652c 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.3.Final + 4.0.4-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index d69bcfd2..48046720 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.3.Final + 4.0.4-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index 54bd5fee..4fecb3d9 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 4.0.3.Final + 4.0.4-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -46,7 +46,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 4.0.3.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index d2cfe6ad..8e680d67 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 4.0.3.Final + 4.0.4-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 4.0.3.Final + 4.0.4-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index 1e726e19..a25a5960 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.3.Final + 4.0.4-SNAPSHOT 4.0.0 From 74c40cd30a2c6701398d186a5830b455a40b084c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Feb 2020 13:52:46 +0000 Subject: [PATCH 034/147] Bump jetty-server in /samples/jstl Bumps [jetty-server](https://github.com/eclipse/jetty.project) from 7.2.2.v20101205 to 9.4.17.v20190418. - [Release notes](https://github.com/eclipse/jetty.project/releases) - [Commits](https://github.com/eclipse/jetty.project/compare/jetty-7.2.2.v20101205...jetty-9.4.17.v20190418) Signed-off-by: dependabot[bot] --- samples/jstl/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 8e680d67..67a32d11 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -15,7 +15,7 @@ org.eclipse.jetty jetty-server - 7.2.2.v20101205 + 9.4.17.v20190418 org.eclipse.jetty From fdba48043fa891deee6114b3419a187bc49a21c8 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Tue, 25 Feb 2020 08:53:10 -0500 Subject: [PATCH 035/147] [maven-release-plugin] prepare release 4.0.4.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 94ac56ff..36c96222 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.4-SNAPSHOT + 4.0.4.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index c942eb88..260992dc 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.4-SNAPSHOT + 4.0.4.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 7b12652c..ff7bfffe 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.4-SNAPSHOT + 4.0.4.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 48046720..56ba3aee 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.4-SNAPSHOT + 4.0.4.Final ../pom.xml diff --git a/pom.xml b/pom.xml index 4fecb3d9..420e8a68 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 4.0.4-SNAPSHOT + 4.0.4.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -46,7 +46,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 4.0.4.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 8e680d67..2982e337 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 4.0.4-SNAPSHOT + 4.0.4.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 4.0.4-SNAPSHOT + 4.0.4.Final diff --git a/samples/pom.xml b/samples/pom.xml index a25a5960..37ab6f19 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.4-SNAPSHOT + 4.0.4.Final 4.0.0 From fbc9c478548d63174c824f29d249f6436e7f4638 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Tue, 25 Feb 2020 08:53:10 -0500 Subject: [PATCH 036/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 36c96222..e1534962 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.4.Final + 4.0.5-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 260992dc..702d57d9 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.4.Final + 4.0.5-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index ff7bfffe..2a0f9e53 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.4.Final + 4.0.5-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 56ba3aee..af1ba956 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.4.Final + 4.0.5-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index 420e8a68..be59f6ab 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 4.0.4.Final + 4.0.5-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -46,7 +46,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 4.0.4.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 2982e337..a3ab8a9a 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 4.0.4.Final + 4.0.5-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 4.0.4.Final + 4.0.5-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index 37ab6f19..741a9be8 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.4.Final + 4.0.5-SNAPSHOT 4.0.0 From 832a5b1cbdd3d319ee1a0a87ee364ba0feeb32da Mon Sep 17 00:00:00 2001 From: quannt Date: Fri, 28 Feb 2020 21:20:30 +0700 Subject: [PATCH 037/147] Update translation for Vietnamese --- .../src/main/java/org/ocpsoft/prettytime/i18n/Resources_vi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_vi.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_vi.java index 13508f16..f3c5cfaf 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_vi.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_vi.java @@ -100,7 +100,7 @@ public class Resources_vi extends ListResourceBundle { "YearPattern", "%n %u" }, { "YearFuturePrefix", "" }, { "YearFutureSuffix", " sau" }, - { "YearPastPrefix", "cách đay " }, + { "YearPastPrefix", "cách đây " }, { "YearPastSuffix", "" }, { "YearSingularName", "năm" }, { "YearPluralName", "năm" }, From 6bfec62752bca44dc3fe1ea62ac335bdaefdfac1 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sun, 15 Mar 2020 00:34:34 -0400 Subject: [PATCH 038/147] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e6545487..38dbf0b7 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,12 @@ Android ======= To use prettytime in android, first add the following dependency to your app level build.gradle - implementation 'org.ocpsoft.prettytime:prettytime:4.0.1.Final' + implementation 'org.ocpsoft.prettytime:prettytime:4.0.4.Final' ProGuard rules are automatically configured for you if you use the R8 shrinker (which is the default since version 3.4.0 of the Android Gradle Plugin). If you are using an older version of AGP, add the ProGuard rules from [this file](core/src/main/resources/META-INF/proguard/prettytime.pro) +Be sure to check maven central for the latest version: https://repo1.maven.org/maven2/org/ocpsoft/prettytime/prettytime/ + DEVELOPMENT =========== force-release: mvn release:prepare release:perform -DskipTests=true -DdevelopmentVersion=4.0.2-SNAPSHOT -DreleaseVersion=4.0.1.Final -Dtag=4.0.1.Final -Darguments="-DskipTests=true -Dmaven.test.skip=true" From 0cb55659f7babf0a24031de18f9e49852f7aab70 Mon Sep 17 00:00:00 2001 From: Anxhelo Lushka Date: Tue, 21 Apr 2020 20:07:54 +0200 Subject: [PATCH 039/147] Added Albanian translation and tests --- .../ocpsoft/prettytime/i18n/Resources_sq.java | 121 +++++++++ .../prettytime/PrettyTimeI18n_sq_Test.java | 243 ++++++++++++++++++ 2 files changed, 364 insertions(+) create mode 100644 core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sq.java create mode 100644 core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_sq_Test.java diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sq.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sq.java new file mode 100644 index 00000000..47bcbf99 --- /dev/null +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sq.java @@ -0,0 +1,121 @@ +/* + * Copyright 2012 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ocpsoft.prettytime.i18n; + +import java.util.ListResourceBundle; + +public class Resources_en extends ListResourceBundle +{ + private static final Object[][] OBJECTS = new Object[][] { + { "CenturyPattern", "%n %u" }, + { "CenturyFuturePrefix", "" }, + { "CenturyFutureSuffix", " nga tani" }, + { "CenturyPastPrefix", "" }, + { "CenturyPastSuffix", " më parë" }, + { "CenturySingularName", "shekull" }, + { "CenturyPluralName", "shekuj" }, + { "DayPattern", "%n %u" }, + { "DayFuturePrefix", "" }, + { "DayFutureSuffix", " nga tani" }, + { "DayPastPrefix", "" }, + { "DayPastSuffix", " më parë" }, + { "DaySingularName", "ditë" }, + { "DayPluralName", "ditë" }, + { "DecadePattern", "%n %u" }, + { "DecadeFuturePrefix", "" }, + { "DecadeFutureSuffix", " nga tani" }, + { "DecadePastPrefix", "" }, + { "DecadePastSuffix", " më parë" }, + { "DecadeSingularName", "dekadë" }, + { "DecadePluralName", "dekada" }, + { "HourPattern", "%n %u" }, + { "HourFuturePrefix", "" }, + { "HourFutureSuffix", " nga tani" }, + { "HourPastPrefix", "" }, + { "HourPastSuffix", " më parë" }, + { "HourSingularName", "orë" }, + { "HourPluralName", "orë" }, + { "JustNowPattern", "%u" }, + { "JustNowFuturePrefix", "" }, + { "JustNowFutureSuffix", "momente nga tani" }, + { "JustNowPastPrefix", "momente më parë" }, + { "JustNowPastSuffix", "" }, + { "JustNowSingularName", "" }, + { "JustNowPluralName", "" }, + { "MillenniumPattern", "%n %u" }, + { "MillenniumFuturePrefix", "" }, + { "MillenniumFutureSuffix", " nga tani" }, + { "MillenniumPastPrefix", "" }, + { "MillenniumPastSuffix", " më parë" }, + { "MillenniumSingularName", "mijëvjeçar" }, + { "MillenniumPluralName", "mijëvjeçarë" }, + { "MillisecondPattern", "%n %u" }, + { "MillisecondFuturePrefix", "" }, + { "MillisecondFutureSuffix", " nga tani" }, + { "MillisecondPastPrefix", "" }, + { "MillisecondPastSuffix", " më parë" }, + { "MillisecondSingularName", "milisekondë" }, + { "MillisecondPluralName", "milisekonda" }, + { "MinutePattern", "%n %u" }, + { "MinuteFuturePrefix", "" }, + { "MinuteFutureSuffix", " nga tani" }, + { "MinutePastPrefix", "" }, + { "MinutePastSuffix", " më parë" }, + { "MinuteSingularName", "minutë" }, + { "MinutePluralName", "minuta" }, + { "MonthPattern", "%n %u" }, + { "MonthFuturePrefix", "" }, + { "MonthFutureSuffix", " nga tani" }, + { "MonthPastPrefix", "" }, + { "MonthPastSuffix", " më parë" }, + { "MonthSingularName", "muaj" }, + { "MonthPluralName", "muaj" }, + { "SecondPattern", "%n %u" }, + { "SecondFuturePrefix", "" }, + { "SecondFutureSuffix", " nga tani" }, + { "SecondPastPrefix", "" }, + { "SecondPastSuffix", " më parë" }, + { "SecondSingularName", "sekondë" }, + { "SecondPluralName", "sekonda" }, + { "WeekPattern", "%n %u" }, + { "WeekFuturePrefix", "" }, + { "WeekFutureSuffix", " nga tani" }, + { "WeekPastPrefix", "" }, + { "WeekPastSuffix", " më parë" }, + { "WeekSingularName", "javë" }, + { "WeekPluralName", "javë" }, + { "YearPattern", "%n %u" }, + { "YearFuturePrefix", "" }, + { "YearFutureSuffix", " nga tani" }, + { "YearPastPrefix", "" }, + { "YearPastSuffix", " më parë" }, + { "YearSingularName", "vit" }, + { "YearPluralName", "vite" }, + { "AbstractTimeUnitPattern", "" }, + { "AbstractTimeUnitFuturePrefix", "" }, + { "AbstractTimeUnitFutureSuffix", "" }, + { "AbstractTimeUnitPastPrefix", "" }, + { "AbstractTimeUnitPastSuffix", "" }, + { "AbstractTimeUnitSingularName", "" }, + { "AbstractTimeUnitPluralName", "" } }; + + @Override + public Object[][] getContents() + { + return OBJECTS; + } + +} diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_sq_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_sq_Test.java new file mode 100644 index 00000000..d09e597a --- /dev/null +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_sq_Test.java @@ -0,0 +1,243 @@ +/* + * Copyright 2012 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ocpsoft.prettytime; + +import static org.junit.Assert.assertEquals; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class PrettyTimeI18n_sq_Test +{ + private final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); + private Locale locale; + + @Before + public void setUp() throws Exception + { + locale = new Locale("sq"); + Locale.setDefault(locale); + } + + @Test + public void testPrettyTime() + { + PrettyTime p = new PrettyTime(locale); + assertEquals("tani", p.format(new Date())); + } + + @Test + public void testPrettyTimeCenturies() + { + PrettyTime p = new PrettyTime(new Date(3155692597470L * 3L), locale); + assertEquals("3 shekuj më parë", p.format(new Date(0))); + + p = new PrettyTime(new Date(0), locale); + assertEquals("3 shekuj më vonë", p.format(new Date(3155692597470L * 3L))); + } + + @Test + public void testCeilingInterval() throws Exception + { + Date then = format.parse("20/5/2009"); + Date ref = format.parse("17/6/2009"); + PrettyTime t = new PrettyTime(ref, locale); + assertEquals("1 muaj më parë", t.format(then)); + } + + @Test + public void testNullDate() throws Exception + { + PrettyTime t = new PrettyTime(locale); + Date date = null; + assertEquals("momente nga tani", t.format(date)); + } + + @Test + public void testRightNow() throws Exception + { + PrettyTime t = new PrettyTime(locale); + assertEquals("momente nga tani", t.format(new Date())); + } + + @Test + public void testRightNowVariance() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("momente nga tani", t.format(new Date(600))); + } + + @Test + public void testMinutesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("12 minuta nga tani", t.format(new Date(1000 * 60 * 12))); + } + + @Test + public void testHoursFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 orë nga tani", t.format(new Date(1000 * 60 * 60 * 3))); + } + + @Test + public void testDaysFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 ditë nga tani", t.format(new Date(1000 * 60 * 60 * 24 * 3))); + } + + @Test + public void testWeeksFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 javë nga tani", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); + } + + @Test + public void testMonthsFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 muaj nga tani", t.format(new Date(2629743830L * 3L))); + } + + @Test + public void testYearsFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 vite nga tani", t.format(new Date(2629743830L * 12L * 3L))); + } + + @Test + public void testDecadesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 dekada nga tani", t.format(new Date(315569259747L * 3L))); + } + + @Test + public void testCenturiesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("3 shekuj nga tani", t.format(new Date(3155692597470L * 3L))); + } + + /* + * Past + */ + @Test + public void testMomentsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(6000), locale); + assertEquals("momente më parë", t.format(new Date(0))); + } + + @Test + public void testMinutesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale); + assertEquals("12 minuta më parë", t.format(new Date(0))); + } + + @Test + public void test1HourAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 1), locale); + assertEquals("1 orë më parë", t.format(new Date(0))); + } + + @Test + public void test3HoursAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale); + assertEquals("3 orë më parë", t.format(new Date(0))); + } + + @Test + public void test6HoursAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 6), locale); + assertEquals("6 orë më parë", t.format(new Date(0))); + } + + @Test + public void testDaysAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale); + assertEquals("3 ditë më parë", t.format(new Date(0))); + } + + @Test + public void testWeeksAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale); + assertEquals("3 javë më parë", t.format(new Date(0))); + } + + @Test + public void testMonthsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale); + assertEquals("3 muaj më parë", t.format(new Date(0))); + } + + @Test + public void testYearsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale); + assertEquals("3 vite më parë", t.format(new Date(0))); + } + + @Test + public void test8YearsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 8L), locale); + assertEquals("8 vite më parë", t.format(new Date(0))); + } + + @Test + public void testDecadesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale); + assertEquals("3 dekada më parë", t.format(new Date(0))); + } + + @Test + public void test8DecadesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(315569259747L * 8L), locale); + assertEquals("8 dekada më parë", t.format(new Date(0))); + } + + @Test + public void testCenturiesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale); + assertEquals("3 shekuj më parë", t.format(new Date(0))); + } + + @After + public void tearDown() throws Exception + { + Locale.setDefault(locale); + } +} From 3078f1f196601da7b40e074123a343c9bc81c5d0 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Wed, 29 Apr 2020 08:11:02 -0400 Subject: [PATCH 040/147] Fix resources_sq class naming --- .../src/main/java/org/ocpsoft/prettytime/i18n/Resources_sq.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sq.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sq.java index 47bcbf99..7f790abf 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sq.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sq.java @@ -17,7 +17,7 @@ import java.util.ListResourceBundle; -public class Resources_en extends ListResourceBundle +public class Resources_sq extends ListResourceBundle { private static final Object[][] OBJECTS = new Object[][] { { "CenturyPattern", "%n %u" }, From 17234b71c016599d1df7eafa56353203e398fee5 Mon Sep 17 00:00:00 2001 From: Sergey Zolotarev Date: Sun, 17 May 2020 20:51:33 +0600 Subject: [PATCH 041/147] Fix negative duration in Russian version (#182) --- .../ocpsoft/prettytime/i18n/Resources_ru.java | 12 +- .../prettytime/PrettyTimeI18n_RU_Test.java | 142 +++++++++++++++++- 2 files changed, 139 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ru.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ru.java index 5a80d290..b2cd707b 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ru.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ru.java @@ -36,18 +36,14 @@ public TimeFormatAided(String... plurals) public String format(Duration duration) { long quantity = duration.getQuantityRounded(tolerance); - StringBuilder result = new StringBuilder(); - result.append(quantity); - return result.toString(); + return String.valueOf(quantity); } @Override public String formatUnrounded(Duration duration) { - long quantity = duration.getQuantity(); - StringBuilder result = new StringBuilder(); - result.append(quantity); - return result.toString(); + long quantity = Math.abs(duration.getQuantity()); + return String.valueOf(quantity); } @Override @@ -66,7 +62,7 @@ public String decorateUnrounded(Duration duration, String time) return performDecoration( duration.isInPast(), duration.isInFuture(), - duration.getQuantity(), + Math.abs(duration.getQuantity()), time); } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_RU_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_RU_Test.java index 6a0cae71..fa9486db 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_RU_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_RU_Test.java @@ -140,61 +140,189 @@ public void testMomentsAgo() throws Exception } @Test - public void testMinutesAgo() throws Exception + public void testMinutesAgo1() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60), locale); + assertEquals("1 минуту назад", t.formatUnrounded(new Date(0))); + assertEquals("1 минуту назад", t.format(new Date(0))); + } + + @Test + public void testMinutesAgo2() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 3), locale); + assertEquals("3 минуты назад", t.formatUnrounded(new Date(0))); + assertEquals("3 минуты назад", t.format(new Date(0))); + } + + @Test + public void testMinutesAgo3() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale); + assertEquals("12 минут назад", t.formatUnrounded(new Date(0))); assertEquals("12 минут назад", t.format(new Date(0))); } @Test - public void testHoursAgo() throws Exception + public void testHoursAgo1() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60), locale); + assertEquals("1 час назад", t.formatUnrounded(new Date(0))); + assertEquals("1 час назад", t.format(new Date(0))); + } + + @Test + public void testHoursAgo2() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale); + assertEquals("3 часа назад", t.formatUnrounded(new Date(0))); assertEquals("3 часа назад", t.format(new Date(0))); } @Test - public void testDaysAgo() throws Exception + public void testHoursAgo3() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 5), locale); + assertEquals("5 часов назад", t.formatUnrounded(new Date(0))); + assertEquals("5 часов назад", t.format(new Date(0))); + } + + @Test + public void testDaysAgo1() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24), locale); + assertEquals("1 день назад", t.formatUnrounded(new Date(0))); + assertEquals("1 день назад", t.format(new Date(0))); + } + + @Test + public void testDaysAgo2() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale); + assertEquals("3 дня назад", t.formatUnrounded(new Date(0))); assertEquals("3 дня назад", t.format(new Date(0))); } + @Test + public void testDaysAgo3() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 5), locale); + assertEquals("5 дней назад", t.formatUnrounded(new Date(0))); + assertEquals("5 дней назад", t.format(new Date(0))); + } + @Test public void testWeeksAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7), locale); + assertEquals("1 неделю назад", t.formatUnrounded(new Date(0))); + assertEquals("1 неделю назад", t.format(new Date(0))); + } + + @Test + public void testWeeksAgo2() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale); + assertEquals("3 недели назад", t.formatUnrounded(new Date(0))); assertEquals("3 недели назад", t.format(new Date(0))); } @Test - public void testMonthsAgo() throws Exception + public void testMonthsAgo1() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L), locale); + assertEquals("1 месяц назад", t.formatUnrounded(new Date(0))); + assertEquals("1 месяц назад", t.format(new Date(0))); + } + + @Test + public void testMonthsAgo2() throws Exception { PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale); + assertEquals("3 месяца назад", t.formatUnrounded(new Date(0))); assertEquals("3 месяца назад", t.format(new Date(0))); } @Test - public void testYearsAgo() throws Exception + public void testMonthsAgo3() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 5L), locale); + assertEquals("5 месяцев назад", t.formatUnrounded(new Date(0))); + assertEquals("5 месяцев назад", t.format(new Date(0))); + } + + @Test + public void testYearsAgo1() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 12L), locale); + assertEquals("1 год назад", t.formatUnrounded(new Date(0))); + assertEquals("1 год назад", t.format(new Date(0))); + } + + @Test + public void testYearsAgo2() throws Exception { PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale); + assertEquals("3 года назад", t.formatUnrounded(new Date(0))); assertEquals("3 года назад", t.format(new Date(0))); } @Test - public void testDecadesAgo() throws Exception + public void testYearsAgo3() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 5L), locale); + assertEquals("5 лет назад", t.formatUnrounded(new Date(0))); + assertEquals("5 лет назад", t.format(new Date(0))); + } + + @Test + public void testDecadesAgo1() throws Exception + { + PrettyTime t = new PrettyTime(new Date(315569259747L), locale); + assertEquals("1 десятилетие назад", t.formatUnrounded(new Date(0))); + assertEquals("1 десятилетие назад", t.format(new Date(0))); + } + + @Test + public void testDecadesAgo2() throws Exception { PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale); + assertEquals("3 десятилетия назад", t.formatUnrounded(new Date(0))); assertEquals("3 десятилетия назад", t.format(new Date(0))); } @Test - public void testCenturiesAgo() throws Exception + public void testDecadesAgo3() throws Exception + { + PrettyTime t = new PrettyTime(new Date(315569259747L * 5L), locale); + assertEquals("5 десятилетий назад", t.formatUnrounded(new Date(0))); + assertEquals("5 десятилетий назад", t.format(new Date(0))); + } + + @Test + public void testCenturiesAgo1() throws Exception + { + PrettyTime t = new PrettyTime(new Date(3155692597470L), locale); + assertEquals("1 век назад", t.formatUnrounded(new Date(0))); + assertEquals("1 век назад", t.format(new Date(0))); + } + + @Test + public void testCenturiesAgo2() throws Exception { PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale); + assertEquals("3 века назад", t.formatUnrounded(new Date(0))); assertEquals("3 века назад", t.format(new Date(0))); } + @Test + public void testCenturiesAgo3() throws Exception + { + PrettyTime t = new PrettyTime(new Date(3155692597470L * 5L), locale); + assertEquals("5 веков назад", t.formatUnrounded(new Date(0))); + assertEquals("5 веков назад", t.format(new Date(0))); + } + @After public void tearDown() throws Exception { From 06fabc4baeda9e9b4f7da347deaa42c1005b628c Mon Sep 17 00:00:00 2001 From: Moin Ahmed <42882093+moinahmed9999@users.noreply.github.com> Date: Thu, 11 Jun 2020 11:10:01 +0530 Subject: [PATCH 042/147] Updated prettytime.pro In Android Studio 4.0 there is an error with "-keep class org.ocpsoft.prettytime.i18n.**" but it works with "-keep class org.ocpsoft.prettytime.i18n**" ; that is by removing the dot(.) after i18n --- core/src/main/resources/META-INF/proguard/prettytime.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/META-INF/proguard/prettytime.pro b/core/src/main/resources/META-INF/proguard/prettytime.pro index 83144338..0b40554e 100644 --- a/core/src/main/resources/META-INF/proguard/prettytime.pro +++ b/core/src/main/resources/META-INF/proguard/prettytime.pro @@ -1 +1 @@ --keep class org.ocpsoft.prettytime.i18n.** +-keep class org.ocpsoft.prettytime.i18n** From 8bed2c73ab26a5375166796fc057188887ddb3b6 Mon Sep 17 00:00:00 2001 From: Thomas Heigl Date: Sat, 5 Sep 2020 10:10:05 +0200 Subject: [PATCH 043/147] Precompile pattern and use non-regex version of `replace` --- .../ocpsoft/prettytime/format/SimpleTimeFormat.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java b/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java index 8ea553ca..f8841373 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java +++ b/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java @@ -19,6 +19,8 @@ import org.ocpsoft.prettytime.TimeFormat; import org.ocpsoft.prettytime.TimeUnit; +import java.util.regex.Pattern; + /** * Represents a simple method of formatting a specific {@link Duration} of time * @@ -30,6 +32,8 @@ public class SimpleTimeFormat implements TimeFormat public static final String SIGN = "%s"; public static final String QUANTITY = "%n"; public static final String UNIT = "%u"; + + private static final Pattern PATTERN_MULTIPLE_WHITESPACES = Pattern.compile("\\s{2,}"); private String singularName = ""; private String pluralName = ""; @@ -69,7 +73,7 @@ public String decorate(Duration duration, String time) { result.append(futurePrefix).append(" ").append(time).append(" ").append(futureSuffix); } - return result.toString().replaceAll("\\s+", " ").trim(); + return PATTERN_MULTIPLE_WHITESPACES.matcher(result).replaceAll(" ").trim(); } @Override @@ -90,9 +94,9 @@ private String format(final Duration duration, final boolean round) private String applyPattern(final String sign, final String unit, final long quantity) { - String result = getPattern(quantity).replaceAll(SIGN, sign); - result = result.replaceAll(QUANTITY, String.valueOf(quantity)); - result = result.replaceAll(UNIT, unit); + String result = getPattern(quantity).replace(SIGN, sign); + result = result.replace(QUANTITY, String.valueOf(quantity)); + result = result.replace(UNIT, unit); return result; } From 8712332ba4706bc4aa8ee345b0f5de2d93fb96b1 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Wed, 29 Apr 2020 08:12:03 -0400 Subject: [PATCH 044/147] [maven-release-plugin] prepare release 4.0.5.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index e1534962..0901cc7c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.5-SNAPSHOT + 4.0.5.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 702d57d9..b7e83230 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.5-SNAPSHOT + 4.0.5.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 2a0f9e53..68678b57 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.5-SNAPSHOT + 4.0.5.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index af1ba956..57029eca 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.5-SNAPSHOT + 4.0.5.Final ../pom.xml diff --git a/pom.xml b/pom.xml index be59f6ab..9b140cbb 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 4.0.5-SNAPSHOT + 4.0.5.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -46,7 +46,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 4.0.5.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 7167323b..166e6c1e 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 4.0.5-SNAPSHOT + 4.0.5.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 4.0.5-SNAPSHOT + 4.0.5.Final diff --git a/samples/pom.xml b/samples/pom.xml index 741a9be8..9800005e 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.5-SNAPSHOT + 4.0.5.Final 4.0.0 From ebd6c7495b5e0e4290a6e902334c7e4985024a8a Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Wed, 29 Apr 2020 08:12:03 -0400 Subject: [PATCH 045/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 0901cc7c..da722e23 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.5.Final + 4.0.6-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index b7e83230..c9a0a2a7 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.5.Final + 4.0.6-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 68678b57..ecc4a219 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.5.Final + 4.0.6-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 57029eca..4715bc94 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.5.Final + 4.0.6-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index 9b140cbb..afc209b9 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 4.0.5.Final + 4.0.6-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -46,7 +46,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 4.0.5.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 166e6c1e..2f10aa81 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 4.0.5.Final + 4.0.6-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 4.0.5.Final + 4.0.6-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index 9800005e..09e0c9ac 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.5.Final + 4.0.6-SNAPSHOT 4.0.0 From 4e21f4ec369d3dd38e71ece4e69c6c9def54473f Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sun, 27 Sep 2020 13:38:45 -0400 Subject: [PATCH 046/147] [maven-release-plugin] prepare release 4.0.6.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index da722e23..135b8af3 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.6-SNAPSHOT + 4.0.6.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index c9a0a2a7..c75c2743 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.6-SNAPSHOT + 4.0.6.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index ecc4a219..f24fc07d 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.6-SNAPSHOT + 4.0.6.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 4715bc94..dd2a4779 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.6-SNAPSHOT + 4.0.6.Final ../pom.xml diff --git a/pom.xml b/pom.xml index afc209b9..3163dbc7 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 4.0.6-SNAPSHOT + 4.0.6.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -46,7 +46,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 4.0.6.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 2f10aa81..e4510df0 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 4.0.6-SNAPSHOT + 4.0.6.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 4.0.6-SNAPSHOT + 4.0.6.Final diff --git a/samples/pom.xml b/samples/pom.xml index 09e0c9ac..aa827da9 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.6-SNAPSHOT + 4.0.6.Final 4.0.0 From 935a6de08e592ba4e30256f939f4e6d7ee64ce9c Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sun, 27 Sep 2020 13:38:45 -0400 Subject: [PATCH 047/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 135b8af3..a9b2dc91 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.6.Final + 4.0.7-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index c75c2743..406e0a5b 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.6.Final + 4.0.7-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index f24fc07d..2ea27fc1 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.6.Final + 4.0.7-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index dd2a4779..df5e4b22 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.6.Final + 4.0.7-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index 3163dbc7..90924f57 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 4.0.6.Final + 4.0.7-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -46,7 +46,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 4.0.6.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index e4510df0..f0d807cf 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 4.0.6.Final + 4.0.7-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 4.0.6.Final + 4.0.7-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index aa827da9..a237b0b6 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.6.Final + 4.0.7-SNAPSHOT 4.0.0 From 5034ece1d2fd02eeb97f89d7913d6eb1899b79cd Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 17 Dec 2020 05:10:18 +0530 Subject: [PATCH 048/147] Use Comparator.comparing(). --- .../org/ocpsoft/prettytime/PrettyTime.java | 29 +++---------- .../prettytime/units/TimeUnitComparator.java | 43 ------------------- .../units/TimeUnitComparatorTest.java | 34 --------------- 3 files changed, 5 insertions(+), 101 deletions(-) delete mode 100644 core/src/main/java/org/ocpsoft/prettytime/units/TimeUnitComparator.java delete mode 100644 core/src/test/java/org/ocpsoft/prettytime/units/TimeUnitComparatorTest.java diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index 914a538e..d35bc53f 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -15,31 +15,12 @@ */ package org.ocpsoft.prettytime; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - import org.ocpsoft.prettytime.impl.DurationImpl; import org.ocpsoft.prettytime.impl.ResourcesTimeFormat; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; -import org.ocpsoft.prettytime.units.Century; -import org.ocpsoft.prettytime.units.Day; -import org.ocpsoft.prettytime.units.Decade; -import org.ocpsoft.prettytime.units.Hour; -import org.ocpsoft.prettytime.units.JustNow; -import org.ocpsoft.prettytime.units.Millennium; -import org.ocpsoft.prettytime.units.Millisecond; -import org.ocpsoft.prettytime.units.Minute; -import org.ocpsoft.prettytime.units.Month; -import org.ocpsoft.prettytime.units.Second; -import org.ocpsoft.prettytime.units.TimeUnitComparator; -import org.ocpsoft.prettytime.units.Week; -import org.ocpsoft.prettytime.units.Year; +import org.ocpsoft.prettytime.units.*; + +import java.util.*; /** * A utility for creating social-networking style timestamps. (e.g. "just now", "moments ago", "3 days ago", @@ -618,8 +599,8 @@ public PrettyTime setReference(final Date timestamp) public List getUnits() { if (cachedUnits == null) { - List result = new ArrayList(units.keySet()); - Collections.sort(result, new TimeUnitComparator()); + List result = new ArrayList<>(units.keySet()); + Collections.sort(result, Comparator.comparing(TimeUnit::getMillisPerUnit)); cachedUnits = Collections.unmodifiableList(result); } diff --git a/core/src/main/java/org/ocpsoft/prettytime/units/TimeUnitComparator.java b/core/src/main/java/org/ocpsoft/prettytime/units/TimeUnitComparator.java deleted file mode 100644 index c8c55155..00000000 --- a/core/src/main/java/org/ocpsoft/prettytime/units/TimeUnitComparator.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012 Lincoln Baxter, III - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.ocpsoft.prettytime.units; - -import java.io.Serializable; -import java.util.Comparator; - -import org.ocpsoft.prettytime.TimeUnit; - -/** - * Compares two {@link TimeUnit} objects - * - * @author lb3 - */ -public class TimeUnitComparator implements Comparator, Serializable -{ - - private static final long serialVersionUID = 1L; - - public int compare(final TimeUnit left, final TimeUnit right) - { - if (left.getMillisPerUnit() < right.getMillisPerUnit()) { - return -1; - } - else if (left.getMillisPerUnit() > right.getMillisPerUnit()) { - return 1; - } - return 0; - } -} diff --git a/core/src/test/java/org/ocpsoft/prettytime/units/TimeUnitComparatorTest.java b/core/src/test/java/org/ocpsoft/prettytime/units/TimeUnitComparatorTest.java deleted file mode 100644 index 816a1981..00000000 --- a/core/src/test/java/org/ocpsoft/prettytime/units/TimeUnitComparatorTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2012 Lincoln Baxter, III - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.ocpsoft.prettytime.units; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.ocpsoft.prettytime.units.Day; -import org.ocpsoft.prettytime.units.Hour; -import org.ocpsoft.prettytime.units.TimeUnitComparator; - -public class TimeUnitComparatorTest { - - @Test - public void testComparingOrder() throws Exception - { - TimeUnitComparator comparator = new TimeUnitComparator(); - assertEquals(-1, comparator.compare(new Hour(), new Day())); - } - -} From 9a48c6e04021bce33ad4412a69bf6622a19e4281 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 17 Dec 2020 09:35:43 +0530 Subject: [PATCH 049/147] Use Map#computeIfAbsent(). --- .../ocpsoft/prettytime/i18n/Resources_fi.java | 17 +++++++---------- .../ocpsoft/prettytime/i18n/Resources_ja.java | 17 +++++++---------- .../prettytime/jsf/PrettyTimeConverter.java | 11 ++--------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_fi.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_fi.java index af66972c..3eebd5c7 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_fi.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_fi.java @@ -1,10 +1,5 @@ package org.ocpsoft.prettytime.i18n; -import java.util.ListResourceBundle; -import java.util.ResourceBundle; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - import org.ocpsoft.prettytime.Duration; import org.ocpsoft.prettytime.TimeFormat; import org.ocpsoft.prettytime.TimeUnit; @@ -12,6 +7,11 @@ import org.ocpsoft.prettytime.impl.TimeFormatProvider; import org.ocpsoft.prettytime.units.Day; +import java.util.ListResourceBundle; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.concurrent.ConcurrentHashMap; + public class Resources_fi extends ListResourceBundle implements TimeFormatProvider { @@ -103,7 +103,7 @@ public class Resources_fi extends ListResourceBundle implements TimeFormatProvid { "MillenniumPastSuffix", "sitten" }, { "MillenniumFutureSuffix", "päästä" }, }; - private volatile ConcurrentMap formatMap = new ConcurrentHashMap(); + private final Map formatMap = new ConcurrentHashMap<>(); public Resources_fi() {} @@ -111,10 +111,7 @@ public Resources_fi() @Override public TimeFormat getFormatFor(TimeUnit t) { - if (!formatMap.containsKey(t)) { - formatMap.putIfAbsent(t, new FiTimeFormat(this, t)); - } - return formatMap.get(t); + return formatMap.computeIfAbsent(t, unit -> new FiTimeFormat(this, unit)); } @Override diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ja.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ja.java index 539da9e5..fdff6df1 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ja.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ja.java @@ -1,10 +1,5 @@ package org.ocpsoft.prettytime.i18n; -import java.util.ListResourceBundle; -import java.util.ResourceBundle; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - import org.ocpsoft.prettytime.Duration; import org.ocpsoft.prettytime.TimeFormat; import org.ocpsoft.prettytime.TimeUnit; @@ -12,6 +7,11 @@ import org.ocpsoft.prettytime.units.Decade; import org.ocpsoft.prettytime.units.Millennium; +import java.util.ListResourceBundle; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.concurrent.ConcurrentHashMap; + public class Resources_ja extends ListResourceBundle implements TimeFormatProvider { private static final Object[][] OBJECTS = new Object[][] { @@ -113,15 +113,12 @@ public Object[][] getContents() return OBJECTS; } - private volatile ConcurrentMap formatMap = new ConcurrentHashMap(); + private final Map formatMap = new ConcurrentHashMap<>(); @Override public TimeFormat getFormatFor(TimeUnit t) { - if (!formatMap.containsKey(t)) { - formatMap.putIfAbsent(t, new JaTimeFormat(this, t)); - } - return formatMap.get(t); + return formatMap.computeIfAbsent(t, unit -> new JaTimeFormat(this, unit)); } private static class JaTimeFormat implements TimeFormat diff --git a/jsf/src/main/java/org/ocpsoft/prettytime/jsf/PrettyTimeConverter.java b/jsf/src/main/java/org/ocpsoft/prettytime/jsf/PrettyTimeConverter.java index 53ad6447..96b44ee0 100644 --- a/jsf/src/main/java/org/ocpsoft/prettytime/jsf/PrettyTimeConverter.java +++ b/jsf/src/main/java/org/ocpsoft/prettytime/jsf/PrettyTimeConverter.java @@ -57,21 +57,14 @@ public String getAsString(final FacesContext context, final UIComponent comp, fi { if (value instanceof Date) { - PrettyTime prettyTime; - // Use locale of current viewer. Locale locale = context.getViewRoot().getLocale(); synchronized (PRETTY_TIME_LOCALE_MAP) { - prettyTime = PRETTY_TIME_LOCALE_MAP.get(locale); - if (prettyTime == null) - { - prettyTime = new PrettyTime(locale); - PRETTY_TIME_LOCALE_MAP.put(locale, prettyTime); - } + return PRETTY_TIME_LOCALE_MAP.computeIfAbsent(locale, PrettyTime::new) + .format((Date) value); } - return prettyTime.format((Date) value); } throw new ConverterException("May only be used to convert java.util.Date objects. Got: " + (value != null ? value.getClass() : "null")); } From d783292496c08ff20b292cd7dc24e38933b35777 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 17 Dec 2020 10:09:02 +0530 Subject: [PATCH 050/147] Use Objects.equals() and the static hashCode() methods. --- .../ocpsoft/prettytime/impl/DurationImpl.java | 16 ++++++---------- .../prettytime/impl/ResourcesTimeUnit.java | 8 +++----- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/impl/DurationImpl.java b/core/src/main/java/org/ocpsoft/prettytime/impl/DurationImpl.java index 1bbbf29a..9612adde 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/impl/DurationImpl.java +++ b/core/src/main/java/org/ocpsoft/prettytime/impl/DurationImpl.java @@ -18,6 +18,8 @@ import org.ocpsoft.prettytime.Duration; import org.ocpsoft.prettytime.TimeUnit; +import java.util.Objects; + public class DurationImpl implements Duration { @@ -98,9 +100,9 @@ public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + (int) (delta ^ (delta >>> 32)); - result = prime * result + (int) (quantity ^ (quantity >>> 32)); - result = prime * result + ((unit == null) ? 0 : unit.hashCode()); + result = prime * result + Long.hashCode(delta); + result = prime * result + Long.hashCode(quantity); + result = prime * result + Objects.hashCode(unit); return result; } @@ -118,12 +120,6 @@ public boolean equals(Object obj) return false; if (quantity != other.quantity) return false; - if (unit == null) { - if (other.unit != null) - return false; - } - else if (!unit.equals(other.unit)) - return false; - return true; + return Objects.equals(unit, other.unit); } } diff --git a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeUnit.java b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeUnit.java index 69f71efd..6cb1b77a 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeUnit.java +++ b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeUnit.java @@ -74,8 +74,8 @@ public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + (int) (maxQuantity ^ (maxQuantity >>> 32)); - result = prime * result + (int) (millisPerUnit ^ (millisPerUnit >>> 32)); + result = prime * result + Long.hashCode(maxQuantity); + result = prime * result + Long.hashCode(millisPerUnit); return result; } @@ -91,8 +91,6 @@ public boolean equals(Object obj) ResourcesTimeUnit other = (ResourcesTimeUnit) obj; if (maxQuantity != other.maxQuantity) return false; - if (millisPerUnit != other.millisPerUnit) - return false; - return true; + return millisPerUnit == other.millisPerUnit; } } From ea3aeecf5973f3fb7814426cd48665a800855d05 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 17 Dec 2020 08:38:34 +0530 Subject: [PATCH 051/147] Add methods that accept the Java 8 Date/Time types as parameters. Also add tests for the methods. --- .../org/ocpsoft/prettytime/PrettyTime.java | 447 +++++++++++++++++- .../PrettyTimeAPIManipulationTest.java | 105 +++- .../ocpsoft/prettytime/PrettyTimeTest.java | 26 +- .../prettytime/SimpleTimeFormatTest.java | 12 + 4 files changed, 578 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index d35bc53f..2d81de98 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -19,7 +19,10 @@ import org.ocpsoft.prettytime.impl.ResourcesTimeFormat; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; import org.ocpsoft.prettytime.units.*; +import org.ocpsoft.prettytime.units.Month; +import org.ocpsoft.prettytime.units.Year; +import java.time.*; import java.util.*; /** @@ -46,7 +49,7 @@ public class PrettyTime { private volatile Date reference; private volatile Locale locale = Locale.getDefault(); - private volatile Map units = new LinkedHashMap(); + private volatile Map units = new LinkedHashMap<>(); private volatile List cachedUnits; private String overrideResourceBundle; @@ -167,8 +170,8 @@ public PrettyTime(final Date reference, final Locale locale, String overrideReso /** * Calculate the approximate {@link Duration} between the reference {@link Date} and given {@link Date}. If the given * {@link Date} is null, the current value of {@link System#currentTimeMillis()} will be used instead. - *

- * See {@code PrettyTime#getReference()}. + * + * @see #getReference() */ public Duration approximateDuration(Date then) { @@ -183,6 +186,18 @@ public Duration approximateDuration(Date then) return calculateDuration(difference); } + /** + * Calculate the approximate {@link Duration} between the reference {@link Date} and given {@link Instant}. + * If the given {@link Instant} is null, the current value of {@link System#currentTimeMillis()} will be + * used instead. + * + * @see #getReference() + */ + public Duration approximateDuration(Instant then) + { + return approximateDuration(then != null ? Date.from(then) : null); + } + /** * Calculate to the precision of the smallest provided {@link TimeUnit}, the exact {@link Duration} represented by * the difference between the reference {@link Date}, and the given {@link Date}. If the given {@link Date} is @@ -207,14 +222,14 @@ public List calculatePreciseDuration(Date then) if (null == reference) reference = now(); - List result = new ArrayList(); + List result = new ArrayList<>(); long difference = then.getTime() - reference.getTime(); Duration duration = calculateDuration(difference); result.add(duration); while (0 != duration.getDelta()) { duration = calculateDuration(duration.getDelta()); - if (result.size() > 0) + if (!result.isEmpty()) { Duration last = result.get(result.size() - 1); if (last.getUnit().equals(duration.getUnit())) @@ -229,6 +244,26 @@ public List calculatePreciseDuration(Date then) return result; } + /** + * Calculate to the precision of the smallest provided {@link TimeUnit}, the exact {@link Duration} represented by + * the difference between the reference {@link Date} and the given {@link Instant}. If the given {@link Instant} is + * null, the current value of {@link System#currentTimeMillis()} will be used instead. + *

+ * Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder + * of time (in milliseconds). + * + * @param then The {@link Instant} to be compared against the reference timestamp, or now if no reference + * timestamp was provided + * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list + * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous + * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference + * between compared dates. + */ + public List calculatePreciseDuration(Instant then) + { + return calculatePreciseDuration(then != null ? Date.from(then) : null); + } + /** * Format the given {@link Date} object. If the given {@link Date} is null, the current value of * {@link System#currentTimeMillis()} will be used instead. @@ -311,6 +346,97 @@ public String format(final List durations) return format.decorateUnrounded(duration, result.toString()); } + /** + * Format the given {@link Instant} object. If the given {@link Instant} is null, the current value of + * {@link System#currentTimeMillis()} will be used instead. + * + * @param then the {@link Instant} to be formatted + * @return A formatted string representing {@code then} + */ + public String format(final Instant then) + { + return format(approximateDuration(then)); + } + + /** + * Format the given {@link ZonedDateTime} object. If the given {@link ZonedDateTime} is null, the + * current value of {@link System#currentTimeMillis()} will be used instead. + * + * @param then the {@link ZonedDateTime} to be formatted + * @return A formatted string representing {@code then} + */ + public String format(final ZonedDateTime then) + { + return format(then != null ? then.toInstant() : null); + } + + /** + * Format the given {@link OffsetDateTime} object. If the given {@link OffsetDateTime} is null, the + * current value of {@link System#currentTimeMillis()} will be used instead. + * + * @param then the {@link OffsetDateTime} to be formatted + * @return A formatted string representing {@code then} + */ + public String format(final OffsetDateTime then) + { + return format(then != null ? then.toInstant() : null); + } + + /** + * Format the given {@link LocalDateTime} object using the given {@link ZoneId}. If the given {@link LocalDateTime} + * is null, the current value of {@link System#currentTimeMillis()} will be used instead. + * + * @param then the {@link LocalDateTime} to be formatted + * @param zoneId the {@link ZoneId} to be used, not null + * @return A formatted string representing {@code then} + */ + public String format(final LocalDateTime then, final ZoneId zoneId) + { + return format(then != null ? then.atZone(zoneId) : null); + } + + /** + * Format the given {@link LocalDateTime} object using the system default {@link ZoneId}. If the given + * {@link LocalDateTime} is null, the current value of {@link System#currentTimeMillis()} will be used + * instead. + * + * @param then the {@link LocalDateTime} to be formatted + * @return A formatted string representing {@code then} + */ + public String format(final LocalDateTime then) + { + return format(then, ZoneId.systemDefault()); + } + + /** + * Format the given {@link LocalDate} object using the given {@link ZoneId}. If the given {@link LocalDate} is + * null, the current value of {@link System#currentTimeMillis()} will be used instead. + * + *

This assumes that the time of the given date is midnight.

+ * + * @param then the {@link LocalDate} to be formatted + * @param zoneId the {@link ZoneId} to be used, not null + * @return A formatted string representing {@code then} + */ + public String format(final LocalDate then, final ZoneId zoneId) + { + return format(then != null ? then.atStartOfDay(zoneId) : null); + } + + /** + * Format the given {@link LocalDate} object using the system default {@link ZoneId}. If the given {@link LocalDate} + * is null, the current value of {@link System#currentTimeMillis()} will be used instead. + * + *

This assumes that the time of the given date is midnight.

+ * + * @param then the {@link LocalDate} to be formatted + * @return A formatted string representing {@code then} + */ + public String format(final LocalDate then) + { + return format(then != null ? then.atStartOfDay() : null); + } + /** * Format the given {@link Date} object. Rounding rules are ignored. If the given {@link Date} is null, * the current value of {@link System#currentTimeMillis()} will be used instead. @@ -389,6 +515,100 @@ public String formatUnrounded(List durations) return format.decorateUnrounded(duration, result.toString()); } + /** + * Format the given {@link Instant} object. Rounding rules are ignored. If the given {@link Instant} is + * null, the current value of {@link System#currentTimeMillis()} will be used instead. + * + * @param then the {@link Instant} to be formatted + * @return A formatted string representing {@code then} + */ + public String formatUnrounded(final Instant then) + { + return formatUnrounded(approximateDuration(then)); + } + + /** + * Format the given {@link ZonedDateTime} object. Rounding rules are ignored. If the given {@link ZonedDateTime} is + * null, the current value of {@link System#currentTimeMillis()} will be used instead. + * + * @param then the {@link ZonedDateTime} to be formatted + * @return A formatted string representing {@code then} + */ + public String formatUnrounded(final ZonedDateTime then) + { + return formatUnrounded(then != null ? then.toInstant() : null); + } + + /** + * Format the given {@link OffsetDateTime} object. Rounding rules are ignored. If the given {@link OffsetDateTime} is + * null, the current value of {@link System#currentTimeMillis()} will be used instead. + * + * @param then the {@link OffsetDateTime} to be formatted + * @return A formatted string representing {@code then} + */ + public String formatUnrounded(final OffsetDateTime then) + { + return formatUnrounded(then != null ? then.toInstant() : null); + } + + /** + * Format the given {@link LocalDateTime} object using the given {@link ZoneId}. Rounding rules are ignored. If the + * given {@link LocalDateTime} is null, the current value of {@link System#currentTimeMillis()} will be + * used instead. + * + * @param then the {@link LocalDateTime} to be formatted + * @param zoneId the {@link ZoneId} to be used, not null + * @return A formatted string representing {@code then} + */ + public String formatUnrounded(final LocalDateTime then, final ZoneId zoneId) + { + return formatUnrounded(then != null ? then.atZone(zoneId) : null); + } + + /** + * Format the given {@link LocalDateTime} object using the system default {@link ZoneId}. Rounding rules are ignored. + * If the given {@link LocalDateTime} is null, the current value of {@link System#currentTimeMillis()} + * will be used instead. + * + * @param then the {@link LocalDateTime} to be formatted + * @return A formatted string representing {@code then} + */ + public String formatUnrounded(final LocalDateTime then) + { + return formatUnrounded(then, ZoneId.systemDefault()); + } + + /** + * Format the given {@link LocalDate} object using the given {@link ZoneId}. Rounding rules are ignored. If the + * given {@link LocalDate} is null, the current value of {@link System#currentTimeMillis()} will be + * used instead. + * + *

This assumes that the time of the given date is midnight.

+ * + * @param then the {@link LocalDate} to be formatted + * @param zoneId the {@link ZoneId} to be used, not null + * @return A formatted string representing {@code then} + */ + public String formatUnrounded(final LocalDate then, final ZoneId zoneId) + { + return formatUnrounded(then != null ? then.atStartOfDay(zoneId) : null); + } + + /** + * Format the given {@link LocalDate} object using the system default {@link ZoneId}. Rounding rules are ignored. + * If the given {@link LocalDate} is null, the current value of {@link System#currentTimeMillis()} + * will be used instead. + * + *

This assumes that the time of the given date is midnight.

+ * + * @param then the {@link LocalDate} to be formatted + * @return A formatted string representing {@code then} + */ + public String formatUnrounded(final LocalDate then) + { + return formatUnrounded(then != null ? then.atStartOfDay() : null); + } + /** * Format the given {@link Date} and return a non-relative (not decorated with past or future tense) {@link String} * for the approximate duration of its difference between the reference {@link Date}. If the given {@link Date} is @@ -447,7 +667,7 @@ public String formatDuration(Duration duration) * {@link Duration} is null, the current value of {@link System#currentTimeMillis()} will be used * instead. * - * @param duration the duration to be formatted + * @param durations the durations to be formatted * @return A formatted string of the given {@link Duration} */ public String formatDuration(final List durations) @@ -475,6 +695,112 @@ public String formatDuration(final List durations) return result.toString(); } + /** + * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) {@link String} + * for the approximate duration of its difference between the reference {@link Date}. If the given {@link Instant} is + * null, the current value of {@link System#currentTimeMillis()} will be used instead. + *

+ * + * @param then the {@link Instant} to be formatted + * @return A formatted string of the given {@link Instant} + */ + public String formatDuration(final Instant then) + { + return formatDuration(approximateDuration(then)); + } + + /** + * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) {@link String} + * for the approximate duration of its difference between the reference {@link Date}. If the given {@link Instant} is + * null, the current value of {@link System#currentTimeMillis()} will be used instead. + *

+ * + * @param then the {@link ZonedDateTime} to be formatted + * @return A formatted string of the given {@link Instant} + */ + public String formatDuration(final ZonedDateTime then) + { + return formatDuration(then != null ? then.toInstant() : null); + } + + /** + * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) {@link String} + * for the approximate duration of its difference between the reference {@link Date}. If the given {@link Instant} is + * null, the current value of {@link System#currentTimeMillis()} will be used instead. + *

+ * + * @param then the {@link OffsetDateTime} to be formatted + * @return A formatted string of the given {@link Instant} + */ + public String formatDuration(final OffsetDateTime then) + { + return formatDuration(then != null ? then.toInstant() : null); + } + + /** + * Format the given {@link LocalDateTime} using the given {@link ZoneId} and return a non-relative (not decorated + * with past or future tense) {@link String} for the approximate duration of its difference between the reference + * {@link Date}. If the given {@link Instant} is null, the current value of + * {@link System#currentTimeMillis()} will be used instead. + *

+ * + * @param then the {@link LocalDateTime} to be formatted + * @param zoneId the {@link ZoneId} to be used, not null + * @return A formatted string of the given {@link LocalDateTime} + */ + public String formatDuration(final LocalDateTime then, final ZoneId zoneId) + { + return formatDuration(then != null ? then.atZone(zoneId) : null); + } + + /** + * Format the given {@link LocalDateTime} using the system default {@link ZoneId} and return a non-relative (not + * decorated with past or future tense) {@link String} for the approximate duration of its difference between the + * reference {@link Date}. If the given {@link Instant} is null, the current value of + * {@link System#currentTimeMillis()} will be used instead. + *

+ * + * @param then the {@link LocalDateTime} to be formatted + * @return A formatted string of the given {@link LocalDateTime} + */ + public String formatDuration(final LocalDateTime then) + { + return formatDuration(then, ZoneId.systemDefault()); + } + + /** + * Format the given {@link LocalDate} using the given {@link ZoneId} and return a non-relative (not decorated with + * past or future tense) {@link String} for the approximate duration of its difference between the reference + * {@link Date}. If the given {@link LocalDate} is null, the current value of + * {@link System#currentTimeMillis()} will be used instead. + * + *

This assumes that the time of the given date is midnight.

+ * + * @param then the {@link LocalDate} to be formatted + * @param zoneId the {@link ZoneId} to be used, not null + * @return A formatted string of the given {@link LocalDate} + */ + public String formatDuration(final LocalDate then, final ZoneId zoneId) + { + return formatDuration(then != null ? then.atStartOfDay(zoneId) : null); + } + + /** + * Format the given {@link LocalDate} using the system default {@link ZoneId} and return a non-relative (not + * decorated with past or future tense) {@link String} for the approximate duration of its difference between the + * reference {@link Date}. If the given {@link LocalDate} is null, the current value of + * {@link System#currentTimeMillis()} will be used instead. + * + *

This assumes that the time of the given date is midnight.

+ * + * @param then the {@link LocalDate} to be formatted + * @return A formatted string of the given {@link LocalDate} + */ + public String formatDuration(final LocalDate then) + { + return formatDuration(then != null ? then.atStartOfDay() : null); + } + /** * Format the given {@link Date} and return a non-relative (not decorated with past or future tense) {@link String} * for the approximate duration of its difference between the reference {@link Date}. Rounding rules are ignored. If @@ -534,7 +860,7 @@ public String formatDurationUnrounded(Duration duration) * are ignored. If the given {@link Duration} is null, the current value of * {@link System#currentTimeMillis()} will be used instead. * - * @param duration the duration to be formatted + * @param durations the durations to be formatted * @return A formatted string of the given {@link Duration} */ public String formatDurationUnrounded(final List durations) @@ -557,6 +883,113 @@ public String formatDurationUnrounded(final List durations) return result.toString(); } + /** + * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) {@link String} + * for the approximate duration of its difference between the reference {@link Date}. Rounding rules are ignored. If + * the given {@link Instant} is null, the current value of {@link System#currentTimeMillis()} will be + * used instead. + *

+ * + * @param then the {@link Instant} to be formatted + * @return A formatted string of the given {@link Instant} + */ + public String formatDurationUnrounded(final Instant then) + { + return formatDurationUnrounded(approximateDuration(then)); + } + + /** + * Format the given {@link ZonedDateTime} and return a non-relative (not decorated with past or future tense) + * {@link String} for the approximate duration of its difference between the reference {@link Date}. Rounding rules + * are ignored. If the given {@link Date} is null, the current value of + * {@link System#currentTimeMillis()} will be used instead. + *

+ * + * @param then the {@link ZonedDateTime} to be formatted + * @return A formatted string of the given {@link ZonedDateTime} + */ + public String formatDurationUnrounded(final ZonedDateTime then) + { + return formatDurationUnrounded(then != null ? then.toInstant() : null); + } + + /** + * Format the given {@link OffsetDateTime} and return a non-relative (not decorated with past or future tense) + * {@link String} for the approximate duration of its difference between the reference {@link Date}. Rounding rules + * are ignored. If the given {@link OffsetDateTime} is null, the current value of + * {@link System#currentTimeMillis()} will be used instead. + *

+ * + * @param then the {@link OffsetDateTime} to be formatted + * @return A formatted string of the given {@link OffsetDateTime} + */ + public String formatDurationUnrounded(final OffsetDateTime then) + { + return formatDurationUnrounded(then != null ? then.toInstant() : null); + } + + /** + * Format the given {@link LocalDateTime} using the given {@link ZoneId} and return a non-relative (not decorated + * with past or future tense) {@link String} for the approximate duration of its difference between the reference + * {@link Date}. Rounding rules are ignored. If the given {@link LocalDateTime} is null, the current + * value of {@link System#currentTimeMillis()} will be used instead. + *

+ * + * @param then the {@link LocalDateTime} to be formatted + * @return A formatted string of the given {@link LocalDateTime} + */ + public String formatDurationUnrounded(final LocalDateTime then, final ZoneId zoneId) + { + return formatDurationUnrounded(then != null ? then.atZone(zoneId) : null); + } + + /** + * Format the given {@link LocalDateTime} using the system default {@link ZoneId} and return a non-relative (not + * decorated with past or future tense) {@link String} for the approximate duration of its difference between the + * reference {@link Date}. Rounding rules are ignored. If the given {@link LocalDateTime} is null, the + * current value of {@link System#currentTimeMillis()} will be used instead. + *

+ * + * @param then the {@link LocalDateTime} to be formatted + * @return A formatted string of the given {@link LocalDateTime} + */ + public String formatDurationUnrounded(final LocalDateTime then) + { + return formatDurationUnrounded(then, ZoneId.systemDefault()); + } + + /** + * Format the given {@link LocalDate} using the given {@link ZoneId} and return a non-relative (not decorated with + * past or future tense) {@link String} for the approximate duration of its difference between the reference + * {@link Date}. Rounding rules are ignored. If the given {@link LocalDate} is null, the current value + * of {@link System#currentTimeMillis()} will be used instead. + * + *

This assumes that the time of the given date is midnight.

+ * + * @param then the {@link LocalDate} to be formatted + * @return A formatted string of the given {@link LocalDate} + */ + public String formatDurationUnrounded(final LocalDate then, final ZoneId zoneId) + { + return formatDurationUnrounded(then != null ? then.atStartOfDay(zoneId) : null); + } + + /** + * Format the given {@link LocalDate} using the system default {@link ZoneId} and return a non-relative (not decorated + * with past or future tense) {@link String} for the approximate duration of its difference between the reference + * {@link Date}. Rounding rules are ignored. If the given {@link LocalDate} is null, the current value + * of {@link System#currentTimeMillis()} will be used instead. + * + *

This assumes that the time of the given date is midnight.

+ * + * @param then the {@link LocalDate} to be formatted + * @return A formatted string of the given {@link LocalDate} + */ + public String formatDurationUnrounded(final LocalDate then) + { + return formatDurationUnrounded(then != null ? then.atStartOfDay() : null); + } + /** * Get the registered {@link TimeFormat} for the given {@link TimeUnit} or null if none exists. */ diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java index 68430272..414815a6 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java @@ -18,6 +18,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.LocalDate; +import java.time.OffsetDateTime; +import java.time.ZonedDateTime; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -33,13 +38,13 @@ public class PrettyTimeAPIManipulationTest @Test public void testApiMisuse1() throws Exception { - Assert.assertEquals(t.approximateDuration(new Date()), t.approximateDuration(null)); + Assert.assertEquals(t.approximateDuration(new Date()), t.approximateDuration((Date) null)); } @Test public void testApiMisuse2() throws Exception { - Assert.assertEquals(t.calculatePreciseDuration(new Date()), t.calculatePreciseDuration(null)); + Assert.assertEquals(t.calculatePreciseDuration(new Date()), t.calculatePreciseDuration((Date) null)); } @Test @@ -72,6 +77,54 @@ public void testApiMisuse4_3() throws Exception Assert.assertEquals(t.format(new Date()), t.format((List) null)); } + @Test + public void testApiMisuse4_4() throws Exception + { + Assert.assertEquals(t.format(new Date()), t.format((Instant) null)); + } + + @Test + public void testApiMisuse4_5() throws Exception + { + Assert.assertEquals(t.format(new Date()), t.format((ZonedDateTime) null)); + } + + @Test + public void testApiMisuse4_6() throws Exception + { + Assert.assertEquals(t.format(new Date()), t.format((OffsetDateTime) null)); + } + + @Test + public void testApiMisuse4_7_1() throws Exception + { + Assert.assertEquals(t.format(new Date()), t.format((LocalDateTime) null, null)); + } + + @Test(expected = NullPointerException.class) + public void testApiMisuse4_7_2() + { + t.format(LocalDateTime.now(), null); + } + + @Test + public void testApiMisuse4_8() + { + Assert.assertEquals(t.format(new Date()), t.format((LocalDateTime) null)); + } + + @Test + public void testApiMisuse4_9_1() throws Exception + { + Assert.assertEquals(t.format(new Date()), t.format((LocalDate) null, null)); + } + + @Test(expected = NullPointerException.class) + public void testApiMisuse4_9_2() + { + t.format(LocalDate.now(), null); + } + @Test public void testApiMisuse5() throws Exception { @@ -96,6 +149,54 @@ public void testApiMisuse5_3() throws Exception Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((List) null)); } + @Test + public void testApiMisuse5_4() throws Exception + { + Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((Instant) null)); + } + + @Test + public void testApiMisuse5_5() throws Exception + { + Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((ZonedDateTime) null)); + } + + @Test + public void testApiMisuse5_6() throws Exception + { + Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((OffsetDateTime) null)); + } + + @Test + public void testApiMisuse5_7_1() throws Exception + { + Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((LocalDateTime) null, null)); + } + + @Test(expected = NullPointerException.class) + public void testApiMisuse5_7_2() + { + t.formatUnrounded(LocalDateTime.now(), null); + } + + @Test + public void testApiMisuse5_8() + { + Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((LocalDateTime) null)); + } + + @Test + public void testApiMisuse5_9_1() throws Exception + { + Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((LocalDate) null, null)); + } + + @Test(expected = NullPointerException.class) + public void testApiMisuse5_9_2() + { + t.formatUnrounded(LocalDate.now(), null); + } + @Test public void testApiMisuse9() throws Exception { diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java index 7a60f2ef..702eaaea 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java @@ -16,6 +16,8 @@ package org.ocpsoft.prettytime; import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -76,6 +78,12 @@ public void testCalculatePreciceDuration() throws Exception Assert.assertEquals("2 hours 2 minutes ago", t.format(preciseDuration)); Assert.assertEquals("2 hours 2 minutes", t.formatDuration(preciseDuration)); Assert.assertEquals("moments from now", t.format(t.calculatePreciseDuration(new Date()))); + + preciseDuration = t.calculatePreciseDuration(Instant.now().minus(2, ChronoUnit.HOURS) + .minus(2, ChronoUnit.MINUTES)); + Assert.assertEquals("2 hours 2 minutes ago", t.format(preciseDuration)); + Assert.assertEquals("2 hours 2 minutes", t.formatDuration(preciseDuration)); + Assert.assertEquals("moments from now", t.format(t.calculatePreciseDuration(Instant.now()))); } @Test @@ -367,7 +375,11 @@ public void testFormatDuration() throws Exception Date tenMinAgo = new Date(System.currentTimeMillis() - tenMinMillis); PrettyTime t = new PrettyTime(); String result = t.formatDuration(tenMinAgo); - Assert.assertTrue(result.equals("10 minutes")); + Assert.assertEquals("10 minutes", result); + + Instant tenMinutesAgo = Instant.now().minus(10, ChronoUnit.MINUTES); + result = t.formatDuration(tenMinutesAgo); + Assert.assertEquals("10 minutes", result); } @Test @@ -377,7 +389,11 @@ public void testFormatDurationWithRounding() throws Exception Date tenMinAgo = new Date(System.currentTimeMillis() - tenMinMillis); PrettyTime t = new PrettyTime(); String result = t.formatDuration(tenMinAgo); - Assert.assertTrue(result.equals("11 minutes")); + Assert.assertEquals("11 minutes", result); + + Instant tenMinutesAgo = Instant.now().minus(10, ChronoUnit.MINUTES).minusSeconds(40); + result = t.formatDuration(tenMinutesAgo); + Assert.assertEquals("11 minutes", result); } @Test @@ -387,7 +403,11 @@ public void testFormatDurationUnrounded() throws Exception Date tenMinAgo = new Date(System.currentTimeMillis() - tenMinMillis); PrettyTime t = new PrettyTime(); String result = t.formatDurationUnrounded(tenMinAgo); - Assert.assertTrue(result.equals("10 minutes")); + Assert.assertEquals("10 minutes", result); + + Instant tenMinutesAgo = Instant.now().minus(10, ChronoUnit.MINUTES).minusSeconds(40); + result = t.formatDurationUnrounded(tenMinutesAgo); + Assert.assertEquals("10 minutes", result); } @Test diff --git a/core/src/test/java/org/ocpsoft/prettytime/SimpleTimeFormatTest.java b/core/src/test/java/org/ocpsoft/prettytime/SimpleTimeFormatTest.java index b3ca6477..d0a374ff 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/SimpleTimeFormatTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/SimpleTimeFormatTest.java @@ -17,6 +17,7 @@ import static org.junit.Assert.assertEquals; +import java.time.*; import java.util.Date; import java.util.Locale; @@ -49,6 +50,11 @@ public void testRounding() throws Exception assertEquals("4 hours ago", t.format(duration)); assertEquals("3 hours ago", t.formatUnrounded(duration)); + + duration = t.approximateDuration(Instant.ofEpochMilli(0)); + + assertEquals("4 hours ago", t.format(duration)); + assertEquals("3 hours ago", t.formatUnrounded(duration)); } @Test @@ -62,6 +68,12 @@ public void testDecorating() throws Exception duration = t.approximateDuration(new Date(System.currentTimeMillis() - 10000)); assertEquals("some time ago", format.decorate(duration, "some time")); + + duration = t.approximateDuration(Instant.now().plusSeconds(1)); + assertEquals("some time from now", format.decorate(duration, "some time")); + + duration = t.approximateDuration(Instant.now().minusSeconds(10)); + assertEquals("some time ago", format.decorate(duration, "some time")); } // Method tearDown() is called automatically after every test method From 23e5d922f7265625d392a5def0bc8b3adbdb138f Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 17 Dec 2020 08:37:05 +0530 Subject: [PATCH 052/147] Update README.md. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 38dbf0b7..42225eea 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ ProGuard rules are automatically configured for you if you use the R8 shrinker ( Be sure to check maven central for the latest version: https://repo1.maven.org/maven2/org/ocpsoft/prettytime/prettytime/ +**Note**: To use prettytime in projects with a `minSdkVersion` below 26, [API desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) is required. + DEVELOPMENT =========== force-release: mvn release:prepare release:perform -DskipTests=true -DdevelopmentVersion=4.0.2-SNAPSHOT -DreleaseVersion=4.0.1.Final -Dtag=4.0.1.Final -Darguments="-DskipTests=true -Dmaven.test.skip=true" From fd92041311326d0f228ab4e1d583b59cd244f9bf Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Fri, 18 Dec 2020 07:34:35 +0530 Subject: [PATCH 053/147] Add constructors that accept the Java 8 Date/Time classes. Also change the reference type from Date to Instant. --- .../org/ocpsoft/prettytime/PrettyTime.java | 422 +++++++++++++++--- .../PrettyTimeAPIManipulationTest.java | 8 +- .../ocpsoft/prettytime/PrettyTimeTest.java | 174 ++++---- 3 files changed, 449 insertions(+), 155 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index 2d81de98..1da97bb5 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -47,11 +47,11 @@ */ public class PrettyTime { - private volatile Date reference; + private volatile Instant reference; private volatile Locale locale = Locale.getDefault(); - private volatile Map units = new LinkedHashMap<>(); + private final Map units = new LinkedHashMap<>(); private volatile List cachedUnits; - private String overrideResourceBundle; + private final String overrideResourceBundle; /** * Create a new {@link PrettyTime} instance that will always use the current value of @@ -60,6 +60,7 @@ public class PrettyTime */ public PrettyTime() { + this((String) null); initTimeUnits(); } @@ -69,7 +70,7 @@ public PrettyTime() * {@link Locale#getDefault()} as the selected {@link Locale} for language and dialect formatting. * Will use {@link String} as an optional override to the default resource bundles. */ - public PrettyTime(String overrideResourceBundle) + public PrettyTime(final String overrideResourceBundle) { this.overrideResourceBundle = overrideResourceBundle; initTimeUnits(); @@ -80,10 +81,6 @@ public PrettyTime(String overrideResourceBundle) * point for {@link Date} comparison, and will use {@link Locale#getDefault()} as the selected {@link Locale} for * language and dialect formatting. If the given {@link Date} is null, this instance will always use the * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Date} comparison. - *

- * - *

- * See {@code PrettyTime#setReference(Date timestamp)}. */ public PrettyTime(final Date reference) { @@ -97,17 +94,149 @@ public PrettyTime(final Date reference) * language and dialect formatting. If the given {@link Date} is null, this instance will always use the * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Date} comparison. * Will use {@link String} as an optional override to the default resource bundles. - *

* - *

- * See {@code PrettyTime#setReference(Date timestamp)}. + * @see #PrettyTime(Date). + */ + public PrettyTime(final Date reference, final String overrideResourceBundle) + { + this(overrideResourceBundle); + setReference(reference); + } + + /** + * Create a new {@link PrettyTime} instance that will use the given {@link Instant} timestamp to represent the reference + * point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected {@link Locale} for + * language and dialect formatting. If the given {@link Instant} is null, this instance will always use the + * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. + */ + public PrettyTime(final Instant reference) + { + this(); + setReference(reference); + } + + /** + * Create a new {@link PrettyTime} instance that will use the given {@link Instant} timestamp to represent the reference + * point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected {@link Locale} for + * language and dialect formatting. If the given {@link Instant} is null, this instance will always use the + * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. + * Will use {@link String} as an optional override to the default resource bundles. + * + * @see #PrettyTime(Instant) */ - public PrettyTime(final Date reference, String overrideResourceBundle) + public PrettyTime(final Instant reference, final String overrideResourceBundle) { this(overrideResourceBundle); setReference(reference); } + /** + * Create a new {@link PrettyTime} instance that will use the given {@link LocalDateTime} and the system default + * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use + * {@link Locale#getDefault()} as the selected {@link Locale} for language and dialect formatting. If the given + * {@link LocalDateTime} is null, this instance will always use the current value of + * {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. + */ + public PrettyTime(final LocalDateTime reference) + { + this(reference, ZoneId.systemDefault()); + } + + /** + * Create a new {@link PrettyTime} instance that will use the given {@link LocalDateTime} and the system default + * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use + * {@link Locale#getDefault()} as the selected {@link Locale} for language and dialect formatting. If the given + * {@link LocalDateTime} is null, this instance will always use the current value of + * {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. + * Will use {@link String} as an optional override to the default resource bundles. + * + * @see #PrettyTime(Instant) + */ + public PrettyTime(final LocalDateTime reference, final String overrideResourceBundle) + { + this(reference, ZoneId.systemDefault(), overrideResourceBundle); + } + + /** + * Create a new {@link PrettyTime} instance that will use the given {@link LocalDateTime} and {@link ZoneId} to + * represent the reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the + * selected {@link Locale} for language and dialect formatting. If the given {@link LocalDateTime} is + * null, this instance will always use the current value of {@link System#currentTimeMillis()} to + * represent the reference point for {@link Instant} comparison. + */ + public PrettyTime(final LocalDateTime reference, final ZoneId zoneId) + { + this(reference, zoneId, null); + } + + /** + * Create a new {@link PrettyTime} instance that will use the given {@link LocalDateTime} and {@link ZoneId} to + * represent the reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the + * selected {@link Locale} for language and dialect formatting. If the given {@link LocalDateTime} is null, + * this instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference + * point for {@link Instant} comparison. Will use {@link String} as an optional override to the default resource + * bundles. + * + * @see #PrettyTime(Instant) + */ + public PrettyTime(final LocalDateTime reference, final ZoneId zoneId, final String overrideResourceBundle) + { + this(reference != null ? reference.atZone(zoneId).toInstant() : null, overrideResourceBundle); + } + + /** + * Create a new {@link PrettyTime} instance that will use the given {@link LocalDate} and the system default + * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use + * {@link Locale#getDefault()} as the selected {@link Locale} for language and dialect formatting. If the given + * {@link LocalDate} is null, this instance will always use the current value of + * {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. + */ + public PrettyTime(final LocalDate reference) + { + this(reference, ZoneId.systemDefault(), null); + } + + /** + * Create a new {@link PrettyTime} instance that will use the given {@link LocalDate} and the system default + * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use + * {@link Locale#getDefault()} as the selected {@link Locale} for language and dialect formatting. If the given + * {@link LocalDate} is null, this instance will always use the current value of + * {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. + * Will use {@link String} as an optional override to the default resource bundles. + * + * @see #PrettyTime(Instant) + */ + public PrettyTime(final LocalDate reference, final String overrideResourceBundle) + { + this(reference, ZoneId.systemDefault(), overrideResourceBundle); + } + + /** + * Create a new {@link PrettyTime} instance that will use the given {@link LocalDate} and {@link ZoneId} to + * represent the reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the + * selected {@link Locale} for language and dialect formatting. If the given {@link LocalDate} is null, + * this instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference + * point for {@link Instant} comparison. + */ + public PrettyTime(final LocalDate reference, final ZoneId zoneId) + { + this(reference, zoneId, null); + } + + /** + * Create a new {@link PrettyTime} instance that will use the given {@link Instant} timestamp to represent the reference + * point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected {@link Locale} for + * language and dialect formatting. If the given {@link Instant} is null, this instance will always use the + * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. + * Will use {@link String} as an optional override to the default resource bundles. + * + * @see #PrettyTime(Instant) + */ + public PrettyTime(final LocalDate reference, final ZoneId zoneId, final String overrideResourceBundle) + { + this(reference != null ? reference.atStartOfDay(zoneId).toInstant() : null, overrideResourceBundle); + } + /** * Construct a new {@link PrettyTime} instance that will always use the current value of * {@link System#currentTimeMillis()} to represent the reference point for {@link Date} comparison. This instance @@ -116,6 +245,7 @@ public PrettyTime(final Date reference, String overrideResourceBundle) */ public PrettyTime(final Locale locale) { + this.overrideResourceBundle = null; setLocale(locale); initTimeUnits(); } @@ -178,16 +308,14 @@ public Duration approximateDuration(Date then) if (then == null) then = now(); - Date ref = reference; - if (null == ref) - ref = now(); + final Instant ref = reference != null ? reference : Instant.now(); - long difference = then.getTime() - ref.getTime(); + long difference = then.getTime() - ref.toEpochMilli(); return calculateDuration(difference); } /** - * Calculate the approximate {@link Duration} between the reference {@link Date} and given {@link Instant}. + * Calculate the approximate {@link Duration} between the reference {@link Instant} and given {@link Instant}. * If the given {@link Instant} is null, the current value of {@link System#currentTimeMillis()} will be * used instead. * @@ -200,7 +328,7 @@ public Duration approximateDuration(Instant then) /** * Calculate to the precision of the smallest provided {@link TimeUnit}, the exact {@link Duration} represented by - * the difference between the reference {@link Date}, and the given {@link Date}. If the given {@link Date} is + * the difference between the reference {@link Instant} and the given {@link Date}. If the given {@link Date} is * null, the current value of {@link System#currentTimeMillis()} will be used instead. *

* Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder @@ -218,12 +346,10 @@ public List calculatePreciseDuration(Date then) if (then == null) then = now(); - Date reference = this.reference; - if (null == reference) - reference = now(); + final Instant reference = this.reference != null ? this.reference : Instant.now(); List result = new ArrayList<>(); - long difference = then.getTime() - reference.getTime(); + long difference = then.getTime() - reference.toEpochMilli(); Duration duration = calculateDuration(difference); result.add(duration); while (0 != duration.getDelta()) @@ -246,7 +372,7 @@ public List calculatePreciseDuration(Date then) /** * Calculate to the precision of the smallest provided {@link TimeUnit}, the exact {@link Duration} represented by - * the difference between the reference {@link Date} and the given {@link Instant}. If the given {@link Instant} is + * the difference between the reference {@link Instant} and the given {@link Instant}. If the given {@link Instant} is * null, the current value of {@link System#currentTimeMillis()} will be used instead. *

* Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder @@ -259,11 +385,97 @@ public List calculatePreciseDuration(Date then) * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference * between compared dates. */ - public List calculatePreciseDuration(Instant then) + public List calculatePreciseDuration(final Instant then) { return calculatePreciseDuration(then != null ? Date.from(then) : null); } + /** + * Calculate to the precision of the smallest provided {@link TimeUnit}, the exact {@link Duration} represented by + * the difference between the reference {@link Instant} and the given {@link LocalDateTime} using the system default + * {@link ZoneId}. If the given {@link Instant} is null, the current value of + * {@link System#currentTimeMillis()} will be used instead. + *

+ * Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder + * of time (in milliseconds). + * + * @param then The {@link LocalDateTime} to be compared against the reference timestamp, or now if no reference + * timestamp was provided + * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list + * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous + * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference + * between compared dates. + */ + public List calculatePreciseDuration(final LocalDateTime then) + { + return calculatePreciseDuration(then, ZoneId.systemDefault()); + } + + /** + * Calculate to the precision of the smallest provided {@link TimeUnit}, the exact {@link Duration} represented by + * the difference between the reference {@link Instant} and the given {@link LocalDateTime} using the given + * {@link ZoneId}. If the given {@link Instant} is null, the current value of + * {@link System#currentTimeMillis()} will be used instead. + *

+ * Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder + * of time (in milliseconds). + * + * @param then The {@link LocalDateTime} to be compared against the reference timestamp, or now if no reference + * timestamp was provided + * @param zoneId The {@link ZoneId} to be used, not null + * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list + * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous + * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference + * between compared dates. + */ + public List calculatePreciseDuration(final LocalDateTime then, final ZoneId zoneId) + { + return calculatePreciseDuration(then != null ? then.atZone(zoneId).toInstant() : null); + } + + /** + * Calculate to the precision of the smallest provided {@link TimeUnit}, the exact {@link Duration} represented by + * the difference between the reference {@link Instant} and the given {@link LocalDate} using the system default + * {@link ZoneId}. If the given {@link Instant} is null, the current value of + * {@link System#currentTimeMillis()} will be used instead. + *

+ * Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder + * of time (in milliseconds). + * + * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference + * timestamp was provided + * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list + * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous + * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference + * between compared dates. + */ + public List calculatePreciseDuration(final LocalDate then) + { + return calculatePreciseDuration(then != null ? then.atStartOfDay() : null); + } + + /** + * Calculate to the precision of the smallest provided {@link TimeUnit}, the exact {@link Duration} represented by + * the difference between the reference {@link Instant} and the given {@link LocalDate} using the given {@link ZoneId}. + * If the given {@link Instant} is null, the current value of {@link System#currentTimeMillis()} will be + * used instead. + *

+ * Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder + * of time (in milliseconds). + * + * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference + * timestamp was provided + * @param zoneId The {@link ZoneId} to be used, not null + * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list + * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous + * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference + * between compared dates. + */ + public List calculatePreciseDuration(final LocalDate then, final ZoneId zoneId) + { + return calculatePreciseDuration(then != null ? then.atStartOfDay(zoneId).toInstant() : null); + } + /** * Format the given {@link Date} object. If the given {@link Date} is null, the current value of * {@link System#currentTimeMillis()} will be used instead. @@ -611,7 +823,7 @@ public String formatUnrounded(final LocalDate then) /** * Format the given {@link Date} and return a non-relative (not decorated with past or future tense) {@link String} - * for the approximate duration of its difference between the reference {@link Date}. If the given {@link Date} is + * for the approximate duration of its difference between the reference {@link Instant}. If the given {@link Date} is * null, the current value of {@link System#currentTimeMillis()} will be used instead. *

* @@ -626,7 +838,7 @@ public String formatDuration(Date then) /** * Format the given {@link Calendar} and return a non-relative (not decorated with past or future tense) - * {@link String} for the approximate duration of its difference between the reference {@link Date}. If the given + * {@link String} for the approximate duration of its difference between the reference {@link Instant}. If the given * {@link Calendar} is null, the current value of {@link System#currentTimeMillis()} will be used * instead. *

@@ -645,7 +857,7 @@ public String formatDuration(Calendar then) /** * Format the given {@link Duration} and return a non-relative (not decorated with past or future tense) - * {@link String} for the approximate duration of the difference between the reference {@link Date} and the given + * {@link String} for the approximate duration of the difference between the reference {@link Instant} and the given * {@link Duration}. If the given {@link Duration} is null, the current value of * {@link System#currentTimeMillis()} will be used instead. * @@ -663,7 +875,7 @@ public String formatDuration(Duration duration) /** * Format the given {@link Duration} {@link List} and return a non-relative (not decorated with past or future tense) - * {@link String} for the approximate duration of its difference between the reference {@link Date}. If the given + * {@link String} for the approximate duration of its difference between the reference {@link Instant}. If the given * {@link Duration} is null, the current value of {@link System#currentTimeMillis()} will be used * instead. * @@ -697,7 +909,7 @@ public String formatDuration(final List durations) /** * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) {@link String} - * for the approximate duration of its difference between the reference {@link Date}. If the given {@link Instant} is + * for the approximate duration of its difference between the reference {@link Instant}. If the given {@link Instant} is * null, the current value of {@link System#currentTimeMillis()} will be used instead. *

* @@ -711,7 +923,7 @@ public String formatDuration(final Instant then) /** * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) {@link String} - * for the approximate duration of its difference between the reference {@link Date}. If the given {@link Instant} is + * for the approximate duration of its difference between the reference {@link Instant}. If the given {@link Instant} is * null, the current value of {@link System#currentTimeMillis()} will be used instead. *

* @@ -725,7 +937,7 @@ public String formatDuration(final ZonedDateTime then) /** * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) {@link String} - * for the approximate duration of its difference between the reference {@link Date}. If the given {@link Instant} is + * for the approximate duration of its difference between the reference {@link Instant}. If the given {@link Instant} is * null, the current value of {@link System#currentTimeMillis()} will be used instead. *

* @@ -756,7 +968,7 @@ public String formatDuration(final LocalDateTime then, final ZoneId zoneId) /** * Format the given {@link LocalDateTime} using the system default {@link ZoneId} and return a non-relative (not * decorated with past or future tense) {@link String} for the approximate duration of its difference between the - * reference {@link Date}. If the given {@link Instant} is null, the current value of + * reference {@link Instant}. If the given {@link LocalDateTime} is null, the current value of * {@link System#currentTimeMillis()} will be used instead. *

* @@ -788,7 +1000,7 @@ public String formatDuration(final LocalDate then, final ZoneId zoneId) /** * Format the given {@link LocalDate} using the system default {@link ZoneId} and return a non-relative (not * decorated with past or future tense) {@link String} for the approximate duration of its difference between the - * reference {@link Date}. If the given {@link LocalDate} is null, the current value of + * reference {@link Instant}. If the given {@link LocalDate} is null, the current value of * {@link System#currentTimeMillis()} will be used instead. * *

This assumes that the time of the given date is midnight.

@@ -803,9 +1015,9 @@ public String formatDuration(final LocalDate then) /** * Format the given {@link Date} and return a non-relative (not decorated with past or future tense) {@link String} - * for the approximate duration of its difference between the reference {@link Date}. Rounding rules are ignored. If - * the given {@link Date} is null, the current value of {@link System#currentTimeMillis()} will be used - * instead. + * for the approximate duration of its difference between the reference {@link Instant}. Rounding rules are ignored. + * If the given {@link Date} is null, the current value of {@link System#currentTimeMillis()} will be + * used instead. *

* * @param then the date to be formatted @@ -819,8 +1031,8 @@ public String formatDurationUnrounded(Date then) /** * Format the given {@link Calendar} and return a non-relative (not decorated with past or future tense) - * {@link String} for the approximate duration of its difference between the reference {@link Date}. Rounding rules - * are ignored. If the given {@link Calendar} is null, the current value of + * {@link String} for the approximate duration of its difference between the reference {@link Instant}. Rounding + * rules are ignored. If the given {@link Calendar} is null, the current value of * {@link System#currentTimeMillis()} will be used instead. *

* @@ -838,8 +1050,8 @@ public String formatDurationUnrounded(Calendar then) /** * Format the given {@link Duration} and return a non-relative (not decorated with past or future tense) - * {@link String} for the approximate duration of its difference between the reference {@link Date}. Rounding rules - * are ignored. If the given {@link Duration} is null, the current value of + * {@link String} for the approximate duration of its difference between the reference {@link Instant}. Rounding + * rules are ignored. If the given {@link Duration} is null, the current value of * {@link System#currentTimeMillis()} will be used instead. * * @param duration the duration to be formatted @@ -856,8 +1068,8 @@ public String formatDurationUnrounded(Duration duration) /** * Format the given {@link Duration} {@link List} and return a non-relative (not decorated with past or future tense) - * {@link String} for the approximate duration of its difference between the reference {@link Date}. Rounding rules - * are ignored. If the given {@link Duration} is null, the current value of + * {@link String} for the approximate duration of its difference between the reference {@link Instant}. Rounding + * rules are ignored. If the given {@link Duration} is null, the current value of * {@link System#currentTimeMillis()} will be used instead. * * @param durations the durations to be formatted @@ -885,8 +1097,8 @@ public String formatDurationUnrounded(final List durations) /** * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) {@link String} - * for the approximate duration of its difference between the reference {@link Date}. Rounding rules are ignored. If - * the given {@link Instant} is null, the current value of {@link System#currentTimeMillis()} will be + * for the approximate duration of its difference between the reference {@link Instant}. Rounding rules are ignored. + * If the given {@link Instant} is null, the current value of {@link System#currentTimeMillis()} will be * used instead. *

* @@ -900,8 +1112,8 @@ public String formatDurationUnrounded(final Instant then) /** * Format the given {@link ZonedDateTime} and return a non-relative (not decorated with past or future tense) - * {@link String} for the approximate duration of its difference between the reference {@link Date}. Rounding rules - * are ignored. If the given {@link Date} is null, the current value of + * {@link String} for the approximate duration of its difference between the reference {@link Instant}. Rounding + * rules are ignored. If the given {@link Date} is null, the current value of * {@link System#currentTimeMillis()} will be used instead. *

* @@ -915,8 +1127,8 @@ public String formatDurationUnrounded(final ZonedDateTime then) /** * Format the given {@link OffsetDateTime} and return a non-relative (not decorated with past or future tense) - * {@link String} for the approximate duration of its difference between the reference {@link Date}. Rounding rules - * are ignored. If the given {@link OffsetDateTime} is null, the current value of + * {@link String} for the approximate duration of its difference between the reference {@link Instant}. Rounding + * rules are ignored. If the given {@link OffsetDateTime} is null, the current value of * {@link System#currentTimeMillis()} will be used instead. *

* @@ -946,8 +1158,8 @@ public String formatDurationUnrounded(final LocalDateTime then, final ZoneId zon /** * Format the given {@link LocalDateTime} using the system default {@link ZoneId} and return a non-relative (not * decorated with past or future tense) {@link String} for the approximate duration of its difference between the - * reference {@link Date}. Rounding rules are ignored. If the given {@link LocalDateTime} is null, the - * current value of {@link System#currentTimeMillis()} will be used instead. + * reference {@link Instant}. Rounding rules are ignored. If the given {@link LocalDateTime} is null, + * the current value of {@link System#currentTimeMillis()} will be used instead. *

* * @param then the {@link LocalDateTime} to be formatted @@ -1003,29 +1215,121 @@ public TimeFormat getFormat(TimeUnit unit) } /** - * Get the current reference {@link Date}, or null if no reference {@link Date} is set. - *

+ * Get the current reference {@link Instant}, or null if no reference {@link Instant} is set. + * * See {@code PrettyTime.setReference(Date timestamp)} + * @see #setReference(Instant) */ - public Date getReference() + public Instant getReference() { return reference; } /** - * Set the reference {@link Date}. If null, {@link PrettyTime} will always use the current value of - * {@link System#currentTimeMillis()} as the reference {@link Date}. + * Get the current reference {@link Instant} as a {@link Date}, or null if no reference {@link Instant} + * is set. + * + * @see #getReference() + * @see #setReference(Date) + */ + public Date getReferenceAsLegacyDate() + { + return reference != null ? Date.from(reference) : null; + } + + /** + * Converts the given {@link Date} to the reference {@link Instant}. If null, {@link PrettyTime} will + * always use the current value of {@link System#currentTimeMillis()} as the reference {@link Instant}. *

- * If the {@link Date} formatted is before the reference {@link Date}, the format command will produce a - * {@link String} that is in the past tense. If the {@link Date} formatted is after the reference {@link Date}, the - * format command will produce a {@link String} that is in the future tense. + * If the {@link Date} formatted is before the reference {@link Instant}, the format command will produce a + * {@link String} that is in the past tense. If the {@link Instant} formatted is after the reference {@link Instant}, + * the format command will produce a {@link String} that is in the future tense. + * + * @see #setReference(Instant) */ public PrettyTime setReference(final Date timestamp) + { + return setReference(timestamp != null ? timestamp.toInstant() : null); + } + + /** + * Set the reference {@link Instant}. If null, {@link PrettyTime} will always use the current value of + * {@link System#currentTimeMillis()} as the reference {@link Instant}. + *

+ * If the {@link Instant} formatted is before the reference {@link Instant}, the format command will produce a + * {@link String} that is in the past tense. If the {@link Instant} formatted is after the reference {@link Instant}, + * the format command will produce a {@link String} that is in the future tense. + */ + public PrettyTime setReference(final Instant timestamp) { reference = timestamp; return this; } + /** + * Converts the given {@link LocalDateTime} to the reference {@link Instant} using the system default {@link ZoneId}. + * If null, {@link PrettyTime} will always use the current value of {@link System#currentTimeMillis()} + * as the reference {@link Instant}. + *

+ * If the {@link Instant} formatted is before the reference {@link Instant}, the format command will produce a + * {@link String} that is in the past tense. If the {@link Instant} formatted is after the reference {@link Instant}, + * the format command will produce a {@link String} that is in the future tense. + * + * @see #setReference(Instant) + */ + public PrettyTime setReference(final LocalDateTime localDateTime) + { + return setReference(localDateTime, ZoneId.systemDefault()); + } + + /** + * Converts the given {@link LocalDateTime} to the reference {@link Instant} using the given {@link ZoneId}. + * If null, {@link PrettyTime} will always use the current value of {@link System#currentTimeMillis()} + * as the reference {@link Instant}. + *

+ * If the {@link Instant} formatted is before the reference {@link Instant}, the format command will produce a + * {@link String} that is in the past tense. If the {@link Instant} formatted is after the reference {@link Instant}, + * the format command will produce a {@link String} that is in the future tense. + * + * @see #setReference(Instant) + */ + public PrettyTime setReference(final LocalDateTime localDateTime, final ZoneId zoneId) + { + return setReference(localDateTime != null ? localDateTime.atZone(zoneId).toInstant() : null); + } + + /** + * Converts the given {@link LocalDate} to the reference {@link Instant} using the given {@link ZoneId}. + * If null, {@link PrettyTime} will always use the current value of {@link System#currentTimeMillis()} + * as the reference {@link Instant}. + *

+ * If the {@link Instant} formatted is before the reference {@link Instant}, the format command will produce a + * {@link String} that is in the past tense. If the {@link Instant} formatted is after the reference {@link Instant}, + * the format command will produce a {@link String} that is in the future tense. + * + * @see #setReference(Instant) + */ + public PrettyTime setReference(final LocalDate localDate) + { + return setReference(localDate != null ? localDate.atStartOfDay() : null); + } + + /** + * Converts the given {@link LocalDate} to the reference {@link Instant} using the given {@link ZoneId}. + * If null, {@link PrettyTime} will always use the current value of {@link System#currentTimeMillis()} + * as the reference {@link Instant}. + *

+ * If the {@link Instant} formatted is before the reference {@link Instant}, the format command will produce a + * {@link String} that is in the past tense. If the {@link Instant} formatted is after the reference {@link Instant}, + * the format command will produce a {@link String} that is in the future tense. + * + * @see #setReference(Instant) + */ + public PrettyTime setReference(final LocalDate localDate, final ZoneId zoneId) + { + return setReference(localDate != null ? localDate.atStartOfDay(zoneId).toInstant() : null); + } + /** * Get the unmodifiable {@link List} of the current configured {@link TimeUnit} instances in calculations. */ @@ -1126,7 +1430,7 @@ public Locale getLocale() /** * Set the the {@link Locale} for this {@link PrettyTime} object. This may be an expensive operation, since this - * operation calls {@link TimeUnit#setLocale(Locale)} for each {@link TimeUnit} in {@link #getUnits()}. + * operation calls {@link LocaleAware#setLocale(Locale)} for each {@link TimeUnit} in {@link #getUnits()}. */ public PrettyTime setLocale(Locale locale) { diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java index 414815a6..86f607df 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java @@ -217,12 +217,18 @@ public void testApiMisuse11() throws Exception @Test public void testApiMisuse12() throws Exception + { + t.getReferenceAsLegacyDate(); + } + + @Test + public void testApiMisuse13() throws Exception { t.getUnits(); } @Test(expected = IllegalArgumentException.class) - public void testApiMisuse13() throws Exception + public void testApiMisuse14() throws Exception { t.registerUnit(null, null); } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java index 702eaaea..c85c2300 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java @@ -15,43 +15,37 @@ */ package org.ocpsoft.prettytime; -import java.text.SimpleDateFormat; -import java.time.Instant; +import org.junit.*; +import org.ocpsoft.prettytime.format.SimpleTimeFormat; +import org.ocpsoft.prettytime.impl.ResourcesTimeFormat; +import org.ocpsoft.prettytime.units.Minute; + +import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.Calendar; import java.util.Date; 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 PrettyTimeTest { - SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); - private Locale locale; + private LocalDateTime now; @Before public void setUp() throws Exception { locale = Locale.getDefault(); Locale.setDefault(Locale.ROOT); + now = LocalDateTime.now(); } @Test public void testCeilingInterval() throws Exception { - Date then = format.parse("5/20/2009"); - Date ref = format.parse("6/17/2009"); - PrettyTime t = new PrettyTime(ref); - Assert.assertEquals("1 month ago", t.format(then)); + PrettyTime prettyTime = new PrettyTime(LocalDate.of(2009, 6, 17)); + Assert.assertEquals("1 month ago", prettyTime.format(LocalDate.of(2009, 5, 20))); } @Test @@ -79,11 +73,10 @@ public void testCalculatePreciceDuration() throws Exception Assert.assertEquals("2 hours 2 minutes", t.formatDuration(preciseDuration)); Assert.assertEquals("moments from now", t.format(t.calculatePreciseDuration(new Date()))); - preciseDuration = t.calculatePreciseDuration(Instant.now().minus(2, ChronoUnit.HOURS) - .minus(2, ChronoUnit.MINUTES)); + preciseDuration = t.calculatePreciseDuration(now.minusHours(2).minusMinutes(2)); Assert.assertEquals("2 hours 2 minutes ago", t.format(preciseDuration)); Assert.assertEquals("2 hours 2 minutes", t.formatDuration(preciseDuration)); - Assert.assertEquals("moments from now", t.format(t.calculatePreciseDuration(Instant.now()))); + Assert.assertEquals("moments from now", t.format(t.calculatePreciseDuration(LocalDateTime.now()))); } @Test @@ -105,71 +98,71 @@ public void testCalculatePreciseDuration2() prettyTime.clearUnits(); Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); - Assert.assertEquals("40 minutes ago", prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + Assert.assertEquals("40 minutes ago", prettyTime.formatUnrounded(prettyTime + .calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); } @Test public void testRightNowVariance() throws Exception { - PrettyTime t = new PrettyTime(new Date(0)); - Assert.assertEquals("moments from now", t.format(new Date(600))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("moments from now", t.format(now.plus(600, ChronoUnit.MILLIS))); } @Test public void testMinutesFromNow() throws Exception { - PrettyTime t = new PrettyTime(new Date(0)); - Assert.assertEquals("12 minutes from now", t.format(new Date(1000 * 60 * 12))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("12 minutes from now", t.format(now.plusMinutes(12))); } @Test public void testHoursFromNow() throws Exception { - PrettyTime t = new PrettyTime(new Date(0)); - Assert.assertEquals("3 hours from now", t.format(new Date(1000 * 60 * 60 * 3))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 hours from now", t.format(now.plusHours(3))); } @Test public void testDaysFromNow() throws Exception { - PrettyTime t = new PrettyTime(new Date(0)); - Assert.assertEquals("3 days from now", t.format(new Date(1000 * 60 * 60 * 24 * 3))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 days from now", t.format(now.plusDays(3))); } @Test public void testWeeksFromNow() throws Exception { - PrettyTime t = new PrettyTime(new Date(0)); - Assert.assertEquals("3 weeks from now", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 weeks from now", t.format(now.plusWeeks(3))); } @Test public void testMonthsFromNow() throws Exception { - PrettyTime t = new PrettyTime(new Date(0)); - Assert.assertEquals("3 months from now", t.format(new Date(2629743830L * 3L))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 months from now", t.format(now.plusMonths(3))); } @Test public void testYearsFromNow() throws Exception { - PrettyTime t = new PrettyTime(new Date(0)); - Assert.assertEquals("3 years from now", t.format(new Date(2629743830L * 12L * 3L))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 years from now", t.format(now.plusYears(3))); } @Test public void testDecadesFromNow() throws Exception { - PrettyTime t = new PrettyTime(new Date(0)); - Assert.assertEquals("3 decades from now", t.format(new Date(315569259747L * 3L))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 decades from now", t.format(now.plus(3, ChronoUnit.DECADES))); } @Test public void testCenturiesFromNow() throws Exception { - PrettyTime t = new PrettyTime(new Date(0)); - Assert.assertEquals("3 centuries from now", t.format(new Date(3155692597470L * 3L))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 centuries from now", t.format(now.plus(3, ChronoUnit.CENTURIES))); } /* @@ -178,63 +171,63 @@ public void testCenturiesFromNow() throws Exception @Test public void testMomentsAgo() throws Exception { - PrettyTime t = new PrettyTime(new Date(6000)); - Assert.assertEquals("moments ago", t.format(new Date(0))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("moments ago", t.format(now.minusSeconds(6))); } @Test public void testMinutesAgo() throws Exception { - PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12)); - Assert.assertEquals("12 minutes ago", t.format(new Date(0))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("12 minutes ago", t.format(now.minusMinutes(12))); } @Test public void testMinutesFromNowDefaultReference() throws Exception { PrettyTime t = new PrettyTime(); - Assert.assertEquals("12 minutes from now", t.format(new Date(System.currentTimeMillis() + 1000 * 60 * 12))); + Assert.assertEquals("12 minutes from now", t.format(now.plusMinutes(12))); } @Test public void testHoursAgo() throws Exception { - PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3)); - Assert.assertEquals("3 hours ago", t.format(new Date(0))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 hours ago", t.format(now.minusHours(3))); } @Test public void testHoursAgoDefaultReference() throws Exception { PrettyTime t = new PrettyTime(); - Assert.assertEquals("3 hours ago", t.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 3))); + Assert.assertEquals("3 hours ago", t.format(now.minusHours(3))); } @Test public void testDaysAgo() throws Exception { - PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3)); - Assert.assertEquals("3 days ago", t.format(new Date(0))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 days ago", t.format(now.minusDays(3))); } @Test public void testWeeksAgo() throws Exception { - PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3)); - Assert.assertEquals("3 weeks ago", t.format(new Date(0))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 weeks ago", t.format(now.minusWeeks(3))); } @Test public void testMonthsAgo() throws Exception { - PrettyTime t = new PrettyTime(new Date(2629743830L * 3L)); - Assert.assertEquals("3 months ago", t.format(new Date(0))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 months ago", t.format(now.minusMonths(3))); } @Test public void testCustomFormat() throws Exception { - PrettyTime t = new PrettyTime(new Date(0)); + PrettyTime t = new PrettyTime(now); TimeUnit unit = new TimeUnit() { @Override @@ -263,45 +256,45 @@ public boolean isPrecise() .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)); - Assert.assertEquals("self destruct was: 5 ticks ago...", t.format(new Date(0))); + final LocalDateTime fiveTicks = now.plusSeconds(25); + Assert.assertEquals("self destruct in: 5 ticks ... RUN!", t.format(fiveTicks)); + t.setReference(fiveTicks); + Assert.assertEquals("self destruct was: 5 ticks ago...", t.format(now)); } @Test public void testYearsAgo() throws Exception { - PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L)); - Assert.assertEquals("3 years ago", t.format(new Date(0))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 years ago", t.format(now.minusYears(3))); } @Test public void testDecadesAgo() throws Exception { - PrettyTime t = new PrettyTime(new Date(315569259747L * 3L)); - Assert.assertEquals("3 decades ago", t.format(new Date(0))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 decades ago", t.format(now.minus(3, ChronoUnit.DECADES))); } @Test public void testCenturiesAgo() throws Exception { - PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L)); - Assert.assertEquals("3 centuries ago", t.format(new Date(0))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 centuries ago", t.format(now.minus(3, ChronoUnit.CENTURIES))); } @Test public void testWithinTwoHoursRounding() throws Exception { - PrettyTime t = new PrettyTime(); - Assert.assertEquals("2 hours ago", t.format(new Date(new Date().getTime() - 6543990))); + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("2 hours ago", t.format(now.minusHours(1).minusMinutes(45))); } @Test public void testPreciseInTheFuture() throws Exception { PrettyTime t = new PrettyTime(); - List durations = t.calculatePreciseDuration(new Date(new Date().getTime() + 1000 - * (10 * 60 + 5 * 60 * 60))); + List durations = t.calculatePreciseDuration(now.plusHours(5).plusMinutes(10)); Assert.assertTrue(durations.size() >= 2); Assert.assertEquals(5, durations.get(0).getQuantity()); Assert.assertEquals(10, durations.get(1).getQuantity()); @@ -311,8 +304,7 @@ public void testPreciseInTheFuture() throws Exception public void testPreciseInThePast() throws Exception { PrettyTime t = new PrettyTime(); - List durations = t.calculatePreciseDuration(new Date(new Date().getTime() - 1000 - * (10 * 60 + 5 * 60 * 60))); + List durations = t.calculatePreciseDuration(now.minusHours(5).minusMinutes(10)); Assert.assertTrue(durations.size() >= 2); Assert.assertEquals(-5, durations.get(0).getQuantity()); Assert.assertEquals(-10, durations.get(1).getQuantity()); @@ -321,27 +313,27 @@ public void testPreciseInThePast() throws Exception @Test public void testFormattingDurationListInThePast() throws Exception { - PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3 + 1000 * 60 * 60 * 15 + 1000 * 60 * 38)); - List durations = t.calculatePreciseDuration(new Date(0)); + PrettyTime t = new PrettyTime(now); + List durations = t.calculatePreciseDuration(now.minusDays(3).minusHours(15).minusMinutes(38)); Assert.assertEquals("3 days 15 hours 38 minutes ago", t.format(durations)); } @Test 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)); + PrettyTime t = new PrettyTime(now); + List durations = t.calculatePreciseDuration(now.plusDays(3).plusHours(15).plusMinutes(38)); Assert.assertEquals("3 days 15 hours 38 minutes from now", t.format(durations)); } @Test public void testSetLocale() throws Exception { - PrettyTime t = new PrettyTime(new Date(315569259747L * 3L)); - Assert.assertEquals("3 decades ago", t.format(new Date(0))); + PrettyTime t = new PrettyTime(now); + final LocalDateTime threeDecadesAgo = now.minus(3, ChronoUnit.DECADES); + Assert.assertEquals("3 decades ago", t.format(threeDecadesAgo)); t.setLocale(Locale.GERMAN); - Assert.assertEquals("vor 3 Jahrzehnten", t.format(new Date(0))); + Assert.assertEquals("vor 3 Jahrzehnten", t.format(threeDecadesAgo)); } /** @@ -377,8 +369,7 @@ public void testFormatDuration() throws Exception String result = t.formatDuration(tenMinAgo); Assert.assertEquals("10 minutes", result); - Instant tenMinutesAgo = Instant.now().minus(10, ChronoUnit.MINUTES); - result = t.formatDuration(tenMinutesAgo); + result = t.formatDuration(now.minusMinutes(10)); Assert.assertEquals("10 minutes", result); } @@ -391,8 +382,7 @@ public void testFormatDurationWithRounding() throws Exception String result = t.formatDuration(tenMinAgo); Assert.assertEquals("11 minutes", result); - Instant tenMinutesAgo = Instant.now().minus(10, ChronoUnit.MINUTES).minusSeconds(40); - result = t.formatDuration(tenMinutesAgo); + result = t.formatDuration(now.minusMinutes(10).minusSeconds(40)); Assert.assertEquals("11 minutes", result); } @@ -405,8 +395,7 @@ public void testFormatDurationUnrounded() throws Exception String result = t.formatDurationUnrounded(tenMinAgo); Assert.assertEquals("10 minutes", result); - Instant tenMinutesAgo = Instant.now().minus(10, ChronoUnit.MINUTES).minusSeconds(40); - result = t.formatDurationUnrounded(tenMinutesAgo); + result = t.formatDurationUnrounded(now.minusMinutes(10).minusSeconds(40)); Assert.assertEquals("10 minutes", result); } @@ -418,8 +407,7 @@ public void testFormatList() throws Exception Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("41 minutes ago", - prettyTime.format(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.format(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); } @Test @@ -430,8 +418,7 @@ public void testFormatListUnrounded() throws Exception Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("40 minutes ago", - prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); } @Test @@ -442,8 +429,7 @@ public void testFormatDurationList() throws Exception Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("41 minutes", - prettyTime.formatDuration(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.formatDuration(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); } @Test @@ -455,7 +441,7 @@ public void testFormatDurationListUnrounded() throws Exception prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("40 minutes", prettyTime.formatDurationUnrounded(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + now.minusMinutes(40).minusSeconds(40)))); } @Test @@ -466,8 +452,7 @@ public void testCalculatePreciseDuration() Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("41 minutes ago", - prettyTime.format(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.format(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); } @Test @@ -478,8 +463,7 @@ public void testCalculatePreciseDurationUnrounded() Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("40 minutes ago", - prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( - new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); + prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); } @After From aa50cd929fef32eb79c0689c0abfb4046774f730 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sat, 19 Dec 2020 12:59:07 -0500 Subject: [PATCH 054/147] Code cleanup, fix unstable tests (using J8 time API to fix past tense) --- .gitignore | 1 + .../org/ocpsoft/prettytime/PrettyTime.java | 288 ++++----- .../ocpsoft/prettytime/i18n/Resources_cs.java | 14 +- .../ocpsoft/prettytime/i18n/Resources_et.java | 12 - .../ocpsoft/prettytime/i18n/Resources_hr.java | 545 +++++++++--------- .../ocpsoft/prettytime/i18n/Resources_ja.java | 49 +- .../ocpsoft/prettytime/i18n/Resources_sk.java | 14 +- .../prettytime/impl/ResourcesTimeFormat.java | 35 +- .../org/ocpsoft/prettytime/units/Century.java | 3 +- .../org/ocpsoft/prettytime/units/Day.java | 3 +- .../org/ocpsoft/prettytime/units/Decade.java | 3 +- .../org/ocpsoft/prettytime/units/Hour.java | 3 +- .../org/ocpsoft/prettytime/units/JustNow.java | 3 +- .../ocpsoft/prettytime/units/Millennium.java | 3 +- .../ocpsoft/prettytime/units/Millisecond.java | 3 +- .../org/ocpsoft/prettytime/units/Minute.java | 3 +- .../org/ocpsoft/prettytime/units/Month.java | 3 +- .../org/ocpsoft/prettytime/units/Second.java | 3 +- .../org/ocpsoft/prettytime/units/Week.java | 3 +- .../org/ocpsoft/prettytime/units/Year.java | 3 +- .../prettytime/PrettyTimeI18n_DA_Test.java | 5 +- .../prettytime/PrettyTimeI18n_EO_Test.java | 200 ++++--- .../prettytime/PrettyTimeI18n_ET_Test.java | 29 +- .../prettytime/PrettyTimeI18n_FI_Test.java | 33 +- .../prettytime/PrettyTimeI18n_FR_Test.java | 4 +- .../prettytime/PrettyTimeI18n_IT_Test.java | 30 +- .../prettytime/PrettyTimeI18n_TH_Test.java | 15 +- .../prettytime/PrettyTimeI18n_Test.java | 10 +- .../prettytime/PrettyTimeI18n_sq_Test.java | 4 +- .../PrettyTimeLocaleFallbackTest.java | 1 - .../ocpsoft/prettytime/PrettyTimeTest.java | 25 +- .../PrettyTimeUnitConfigurationTest.java | 6 - .../prettytime/PrettyTimel18n_MM_Test.java | 53 +- .../prettytime/SimpleTimeFormatTest.java | 5 +- pom.xml | 125 ++-- .../prettytime/samples/jstl/IndexServlet.java | 13 +- 36 files changed, 820 insertions(+), 732 deletions(-) diff --git a/.gitignore b/.gitignore index 88e3e434..bfa079b8 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ target/ *.ipr *.swp bin/ +nlp/dependency-reduced-pom.xml /*/src/main/java/META-INF docs/reference/src/main/docbook/en-US/version_info.xml .idea diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index 1da97bb5..aaa18d0d 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -15,19 +15,41 @@ */ package org.ocpsoft.prettytime; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + import org.ocpsoft.prettytime.impl.DurationImpl; import org.ocpsoft.prettytime.impl.ResourcesTimeFormat; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; -import org.ocpsoft.prettytime.units.*; +import org.ocpsoft.prettytime.units.Century; +import org.ocpsoft.prettytime.units.Day; +import org.ocpsoft.prettytime.units.Decade; +import org.ocpsoft.prettytime.units.Hour; +import org.ocpsoft.prettytime.units.JustNow; +import org.ocpsoft.prettytime.units.Millennium; +import org.ocpsoft.prettytime.units.Millisecond; +import org.ocpsoft.prettytime.units.Minute; import org.ocpsoft.prettytime.units.Month; +import org.ocpsoft.prettytime.units.Second; +import org.ocpsoft.prettytime.units.Week; import org.ocpsoft.prettytime.units.Year; -import java.time.*; -import java.util.*; - /** - * A utility for creating social-networking style timestamps. (e.g. "just now", "moments ago", "3 days ago", - * "within 2 months") + * A utility for creating social-networking style timestamps. (e.g. "just now", "moments ago", "3 days ago", "within 2 + * months") *

* Usage: *

@@ -67,8 +89,8 @@ public PrettyTime() /** * Create a new {@link PrettyTime} instance that will always use the current value of * {@link System#currentTimeMillis()} to represent the reference point for {@link Date} comparison, and will use - * {@link Locale#getDefault()} as the selected {@link Locale} for language and dialect formatting. - * Will use {@link String} as an optional override to the default resource bundles. + * {@link Locale#getDefault()} as the selected {@link Locale} for language and dialect formatting. Will use + * {@link String} as an optional override to the default resource bundles. */ public PrettyTime(final String overrideResourceBundle) { @@ -104,10 +126,11 @@ public PrettyTime(final Date reference, final String overrideResourceBundle) } /** - * Create a new {@link PrettyTime} instance that will use the given {@link Instant} timestamp to represent the reference - * point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected {@link Locale} for - * language and dialect formatting. If the given {@link Instant} is null, this instance will always use the - * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. + * Create a new {@link PrettyTime} instance that will use the given {@link Instant} timestamp to represent the + * reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected + * {@link Locale} for language and dialect formatting. If the given {@link Instant} is null, this + * instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference point + * for {@link Instant} comparison. */ public PrettyTime(final Instant reference) { @@ -116,11 +139,11 @@ public PrettyTime(final Instant reference) } /** - * Create a new {@link PrettyTime} instance that will use the given {@link Instant} timestamp to represent the reference - * point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected {@link Locale} for - * language and dialect formatting. If the given {@link Instant} is null, this instance will always use the - * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. - * Will use {@link String} as an optional override to the default resource bundles. + * Create a new {@link PrettyTime} instance that will use the given {@link Instant} timestamp to represent the + * reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected + * {@link Locale} for language and dialect formatting. If the given {@link Instant} is null, this + * instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference point + * for {@link Instant} comparison. Will use {@link String} as an optional override to the default resource bundles. * * @see #PrettyTime(Instant) */ @@ -145,10 +168,10 @@ public PrettyTime(final LocalDateTime reference) /** * Create a new {@link PrettyTime} instance that will use the given {@link LocalDateTime} and the system default * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use - * {@link Locale#getDefault()} as the selected {@link Locale} for language and dialect formatting. If the given + * {@link Locale#getDefault()} as the selected {@link Locale} for language and dialect formatting. If the given * {@link LocalDateTime} is null, this instance will always use the current value of - * {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. - * Will use {@link String} as an optional override to the default resource bundles. + * {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. Will use + * {@link String} as an optional override to the default resource bundles. * * @see #PrettyTime(Instant) */ @@ -172,10 +195,10 @@ public PrettyTime(final LocalDateTime reference, final ZoneId zoneId) /** * Create a new {@link PrettyTime} instance that will use the given {@link LocalDateTime} and {@link ZoneId} to * represent the reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the - * selected {@link Locale} for language and dialect formatting. If the given {@link LocalDateTime} is null, - * this instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference - * point for {@link Instant} comparison. Will use {@link String} as an optional override to the default resource - * bundles. + * selected {@link Locale} for language and dialect formatting. If the given {@link LocalDateTime} is + * null, this instance will always use the current value of {@link System#currentTimeMillis()} to + * represent the reference point for {@link Instant} comparison. Will use {@link String} as an optional override to + * the default resource bundles. * * @see #PrettyTime(Instant) */ @@ -201,8 +224,8 @@ public PrettyTime(final LocalDate reference) * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use * {@link Locale#getDefault()} as the selected {@link Locale} for language and dialect formatting. If the given * {@link LocalDate} is null, this instance will always use the current value of - * {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. - * Will use {@link String} as an optional override to the default resource bundles. + * {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. Will use + * {@link String} as an optional override to the default resource bundles. * * @see #PrettyTime(Instant) */ @@ -212,11 +235,11 @@ public PrettyTime(final LocalDate reference, final String overrideResourceBundle } /** - * Create a new {@link PrettyTime} instance that will use the given {@link LocalDate} and {@link ZoneId} to - * represent the reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the - * selected {@link Locale} for language and dialect formatting. If the given {@link LocalDate} is null, - * this instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference - * point for {@link Instant} comparison. + * Create a new {@link PrettyTime} instance that will use the given {@link LocalDate} and {@link ZoneId} to represent + * the reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected + * {@link Locale} for language and dialect formatting. If the given {@link LocalDate} is null, this + * instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference point + * for {@link Instant} comparison. */ public PrettyTime(final LocalDate reference, final ZoneId zoneId) { @@ -224,11 +247,11 @@ public PrettyTime(final LocalDate reference, final ZoneId zoneId) } /** - * Create a new {@link PrettyTime} instance that will use the given {@link Instant} timestamp to represent the reference - * point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected {@link Locale} for - * language and dialect formatting. If the given {@link Instant} is null, this instance will always use the - * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. - * Will use {@link String} as an optional override to the default resource bundles. + * Create a new {@link PrettyTime} instance that will use the given {@link Instant} timestamp to represent the + * reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected + * {@link Locale} for language and dialect formatting. If the given {@link Instant} is null, this + * instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference point + * for {@link Instant} comparison. Will use {@link String} as an optional override to the default resource bundles. * * @see #PrettyTime(Instant) */ @@ -254,8 +277,8 @@ public PrettyTime(final Locale locale) * Construct a new {@link PrettyTime} instance that will always use the current value of * {@link System#currentTimeMillis()} to represent the reference point for {@link Date} comparison. This instance * will use the given {@link Locale} instead of the system default. If the provided {@link Locale} is - * null, {@link Locale#getDefault()} will be used. - * Will use {@link String} as an optional override to the default resource bundles. + * null, {@link Locale#getDefault()} will be used. Will use {@link String} as an optional override to + * the default resource bundles. */ public PrettyTime(final Locale locale, String overrideResourceBundle) { @@ -286,8 +309,8 @@ public PrettyTime(final Date reference, final Locale locale) *

* If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
* If the given {@link Date} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Date} comparison. - * Will use {@link String} as an optional override to the default resource bundles. + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Date} comparison. Will + * use {@link String} as an optional override to the default resource bundles. *

* See {@code PrettyTime#setReference(Date timestamp)}. */ @@ -315,9 +338,9 @@ public Duration approximateDuration(Date then) } /** - * Calculate the approximate {@link Duration} between the reference {@link Instant} and given {@link Instant}. - * If the given {@link Instant} is null, the current value of {@link System#currentTimeMillis()} will be - * used instead. + * Calculate the approximate {@link Duration} between the reference {@link Instant} and given {@link Instant}. If the + * given {@link Instant} is null, the current value of {@link System#currentTimeMillis()} will be used + * instead. * * @see #getReference() */ @@ -335,7 +358,7 @@ public Duration approximateDuration(Instant then) * of time (in milliseconds). * * @param then The {@link Date} to be compared against the reference timestamp, or now if no reference - * timestamp was provided + * timestamp was provided * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference @@ -352,14 +375,11 @@ public List calculatePreciseDuration(Date then) long difference = then.getTime() - reference.toEpochMilli(); Duration duration = calculateDuration(difference); result.add(duration); - while (0 != duration.getDelta()) - { + while (0 != duration.getDelta()) { duration = calculateDuration(duration.getDelta()); - if (!result.isEmpty()) - { + if (!result.isEmpty()) { Duration last = result.get(result.size() - 1); - if (last.getUnit().equals(duration.getUnit())) - { + if (last.getUnit().equals(duration.getUnit())) { break; } } @@ -372,14 +392,14 @@ public List calculatePreciseDuration(Date then) /** * Calculate to the precision of the smallest provided {@link TimeUnit}, the exact {@link Duration} represented by - * the difference between the reference {@link Instant} and the given {@link Instant}. If the given {@link Instant} is - * null, the current value of {@link System#currentTimeMillis()} will be used instead. + * the difference between the reference {@link Instant} and the given {@link Instant}. If the given {@link Instant} + * is null, the current value of {@link System#currentTimeMillis()} will be used instead. *

* Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder * of time (in milliseconds). * * @param then The {@link Instant} to be compared against the reference timestamp, or now if no reference - * timestamp was provided + * timestamp was provided * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference @@ -399,8 +419,8 @@ public List calculatePreciseDuration(final Instant then) * Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder * of time (in milliseconds). * - * @param then The {@link LocalDateTime} to be compared against the reference timestamp, or now if no reference - * timestamp was provided + * @param then The {@link LocalDateTime} to be compared against the reference timestamp, or now if no + * reference timestamp was provided * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference @@ -420,8 +440,8 @@ public List calculatePreciseDuration(final LocalDateTime then) * Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder * of time (in milliseconds). * - * @param then The {@link LocalDateTime} to be compared against the reference timestamp, or now if no reference - * timestamp was provided + * @param then The {@link LocalDateTime} to be compared against the reference timestamp, or now if no + * reference timestamp was provided * @param zoneId The {@link ZoneId} to be used, not null * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous @@ -443,7 +463,7 @@ public List calculatePreciseDuration(final LocalDateTime then, final Z * of time (in milliseconds). * * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference - * timestamp was provided + * timestamp was provided * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference @@ -456,15 +476,15 @@ public List calculatePreciseDuration(final LocalDate then) /** * Calculate to the precision of the smallest provided {@link TimeUnit}, the exact {@link Duration} represented by - * the difference between the reference {@link Instant} and the given {@link LocalDate} using the given {@link ZoneId}. - * If the given {@link Instant} is null, the current value of {@link System#currentTimeMillis()} will be - * used instead. + * the difference between the reference {@link Instant} and the given {@link LocalDate} using the given + * {@link ZoneId}. If the given {@link Instant} is null, the current value of + * {@link System#currentTimeMillis()} will be used instead. *

* Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder * of time (in milliseconds). * - * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference - * timestamp was provided + * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference + * timestamp was provided * @param zoneId The {@link ZoneId} to be used, not null * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous @@ -598,7 +618,7 @@ public String format(final OffsetDateTime then) * Format the given {@link LocalDateTime} object using the given {@link ZoneId}. If the given {@link LocalDateTime} * is null, the current value of {@link System#currentTimeMillis()} will be used instead. * - * @param then the {@link LocalDateTime} to be formatted + * @param then the {@link LocalDateTime} to be formatted * @param zoneId the {@link ZoneId} to be used, not null * @return A formatted string representing {@code then} */ @@ -624,9 +644,11 @@ public String format(final LocalDateTime then) * Format the given {@link LocalDate} object using the given {@link ZoneId}. If the given {@link LocalDate} is * null, the current value of {@link System#currentTimeMillis()} will be used instead. * - *

This assumes that the time of the given date is midnight.

+ *

+ * This assumes that the time of the given date is midnight. + *

* - * @param then the {@link LocalDate} to be formatted + * @param then the {@link LocalDate} to be formatted * @param zoneId the {@link ZoneId} to be used, not null * @return A formatted string representing {@code then} */ @@ -639,7 +661,9 @@ public String format(final LocalDate then, final ZoneId zoneId) * Format the given {@link LocalDate} object using the system default {@link ZoneId}. If the given {@link LocalDate} * is null, the current value of {@link System#currentTimeMillis()} will be used instead. * - *

This assumes that the time of the given date is midnight.

+ *

+ * This assumes that the time of the given date is midnight. + *

* * @param then the {@link LocalDate} to be formatted * @return A formatted string representing {@code then} @@ -768,7 +792,7 @@ public String formatUnrounded(final OffsetDateTime then) * given {@link LocalDateTime} is null, the current value of {@link System#currentTimeMillis()} will be * used instead. * - * @param then the {@link LocalDateTime} to be formatted + * @param then the {@link LocalDateTime} to be formatted * @param zoneId the {@link ZoneId} to be used, not null * @return A formatted string representing {@code then} */ @@ -791,13 +815,15 @@ public String formatUnrounded(final LocalDateTime then) } /** - * Format the given {@link LocalDate} object using the given {@link ZoneId}. Rounding rules are ignored. If the - * given {@link LocalDate} is null, the current value of {@link System#currentTimeMillis()} will be - * used instead. + * Format the given {@link LocalDate} object using the given {@link ZoneId}. Rounding rules are ignored. If the given + * {@link LocalDate} is null, the current value of {@link System#currentTimeMillis()} will be used + * instead. * - *

This assumes that the time of the given date is midnight.

+ *

+ * This assumes that the time of the given date is midnight. + *

* - * @param then the {@link LocalDate} to be formatted + * @param then the {@link LocalDate} to be formatted * @param zoneId the {@link ZoneId} to be used, not null * @return A formatted string representing {@code then} */ @@ -807,11 +833,13 @@ public String formatUnrounded(final LocalDate then, final ZoneId zoneId) } /** - * Format the given {@link LocalDate} object using the system default {@link ZoneId}. Rounding rules are ignored. - * If the given {@link LocalDate} is null, the current value of {@link System#currentTimeMillis()} - * will be used instead. + * Format the given {@link LocalDate} object using the system default {@link ZoneId}. Rounding rules are ignored. If + * the given {@link LocalDate} is null, the current value of {@link System#currentTimeMillis()} will be + * used instead. * - *

This assumes that the time of the given date is midnight.

+ *

+ * This assumes that the time of the given date is midnight. + *

* * @param then the {@link LocalDate} to be formatted * @return A formatted string representing {@code then} @@ -908,9 +936,10 @@ public String formatDuration(final List durations) } /** - * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) {@link String} - * for the approximate duration of its difference between the reference {@link Instant}. If the given {@link Instant} is - * null, the current value of {@link System#currentTimeMillis()} will be used instead. + * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) + * {@link String} for the approximate duration of its difference between the reference {@link Instant}. If the given + * {@link Instant} is null, the current value of {@link System#currentTimeMillis()} will be used + * instead. *

* * @param then the {@link Instant} to be formatted @@ -922,9 +951,10 @@ public String formatDuration(final Instant then) } /** - * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) {@link String} - * for the approximate duration of its difference between the reference {@link Instant}. If the given {@link Instant} is - * null, the current value of {@link System#currentTimeMillis()} will be used instead. + * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) + * {@link String} for the approximate duration of its difference between the reference {@link Instant}. If the given + * {@link Instant} is null, the current value of {@link System#currentTimeMillis()} will be used + * instead. *

* * @param then the {@link ZonedDateTime} to be formatted @@ -936,9 +966,10 @@ public String formatDuration(final ZonedDateTime then) } /** - * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) {@link String} - * for the approximate duration of its difference between the reference {@link Instant}. If the given {@link Instant} is - * null, the current value of {@link System#currentTimeMillis()} will be used instead. + * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) + * {@link String} for the approximate duration of its difference between the reference {@link Instant}. If the given + * {@link Instant} is null, the current value of {@link System#currentTimeMillis()} will be used + * instead. *

* * @param then the {@link OffsetDateTime} to be formatted @@ -956,7 +987,7 @@ public String formatDuration(final OffsetDateTime then) * {@link System#currentTimeMillis()} will be used instead. *

* - * @param then the {@link LocalDateTime} to be formatted + * @param then the {@link LocalDateTime} to be formatted * @param zoneId the {@link ZoneId} to be used, not null * @return A formatted string of the given {@link LocalDateTime} */ @@ -986,9 +1017,11 @@ public String formatDuration(final LocalDateTime then) * {@link Date}. If the given {@link LocalDate} is null, the current value of * {@link System#currentTimeMillis()} will be used instead. * - *

This assumes that the time of the given date is midnight.

+ *

+ * This assumes that the time of the given date is midnight. + *

* - * @param then the {@link LocalDate} to be formatted + * @param then the {@link LocalDate} to be formatted * @param zoneId the {@link ZoneId} to be used, not null * @return A formatted string of the given {@link LocalDate} */ @@ -1003,7 +1036,9 @@ public String formatDuration(final LocalDate then, final ZoneId zoneId) * reference {@link Instant}. If the given {@link LocalDate} is null, the current value of * {@link System#currentTimeMillis()} will be used instead. * - *

This assumes that the time of the given date is midnight.

+ *

+ * This assumes that the time of the given date is midnight. + *

* * @param then the {@link LocalDate} to be formatted * @return A formatted string of the given {@link LocalDate} @@ -1096,10 +1131,10 @@ public String formatDurationUnrounded(final List durations) } /** - * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) {@link String} - * for the approximate duration of its difference between the reference {@link Instant}. Rounding rules are ignored. - * If the given {@link Instant} is null, the current value of {@link System#currentTimeMillis()} will be - * used instead. + * Format the given {@link Instant} and return a non-relative (not decorated with past or future tense) + * {@link String} for the approximate duration of its difference between the reference {@link Instant}. Rounding + * rules are ignored. If the given {@link Instant} is null, the current value of + * {@link System#currentTimeMillis()} will be used instead. *

* * @param then the {@link Instant} to be formatted @@ -1176,7 +1211,9 @@ public String formatDurationUnrounded(final LocalDateTime then) * {@link Date}. Rounding rules are ignored. If the given {@link LocalDate} is null, the current value * of {@link System#currentTimeMillis()} will be used instead. * - *

This assumes that the time of the given date is midnight.

+ *

+ * This assumes that the time of the given date is midnight. + *

* * @param then the {@link LocalDate} to be formatted * @return A formatted string of the given {@link LocalDate} @@ -1187,12 +1224,14 @@ public String formatDurationUnrounded(final LocalDate then, final ZoneId zoneId) } /** - * Format the given {@link LocalDate} using the system default {@link ZoneId} and return a non-relative (not decorated - * with past or future tense) {@link String} for the approximate duration of its difference between the reference - * {@link Date}. Rounding rules are ignored. If the given {@link LocalDate} is null, the current value - * of {@link System#currentTimeMillis()} will be used instead. + * Format the given {@link LocalDate} using the system default {@link ZoneId} and return a non-relative (not + * decorated with past or future tense) {@link String} for the approximate duration of its difference between the + * reference {@link Date}. Rounding rules are ignored. If the given {@link LocalDate} is null, the + * current value of {@link System#currentTimeMillis()} will be used instead. * - *

This assumes that the time of the given date is midnight.

+ *

+ * This assumes that the time of the given date is midnight. + *

* * @param then the {@link LocalDate} to be formatted * @return A formatted string of the given {@link LocalDate} @@ -1207,8 +1246,7 @@ public String formatDurationUnrounded(final LocalDate then) */ public TimeFormat getFormat(TimeUnit unit) { - if (unit != null && units.get(unit) != null) - { + if (unit != null && units.get(unit) != null) { return units.get(unit); } return null; @@ -1218,6 +1256,7 @@ public TimeFormat getFormat(TimeUnit unit) * Get the current reference {@link Instant}, or null if no reference {@link Instant} is set. * * See {@code PrettyTime.setReference(Date timestamp)} + * * @see #setReference(Instant) */ public Instant getReference() @@ -1283,9 +1322,9 @@ public PrettyTime setReference(final LocalDateTime localDateTime) } /** - * Converts the given {@link LocalDateTime} to the reference {@link Instant} using the given {@link ZoneId}. - * If null, {@link PrettyTime} will always use the current value of {@link System#currentTimeMillis()} - * as the reference {@link Instant}. + * Converts the given {@link LocalDateTime} to the reference {@link Instant} using the given {@link ZoneId}. If + * null, {@link PrettyTime} will always use the current value of {@link System#currentTimeMillis()} as + * the reference {@link Instant}. *

* If the {@link Instant} formatted is before the reference {@link Instant}, the format command will produce a * {@link String} that is in the past tense. If the {@link Instant} formatted is after the reference {@link Instant}, @@ -1299,9 +1338,9 @@ public PrettyTime setReference(final LocalDateTime localDateTime, final ZoneId z } /** - * Converts the given {@link LocalDate} to the reference {@link Instant} using the given {@link ZoneId}. - * If null, {@link PrettyTime} will always use the current value of {@link System#currentTimeMillis()} - * as the reference {@link Instant}. + * Converts the given {@link LocalDate} to the reference {@link Instant} using the given {@link ZoneId}. If + * null, {@link PrettyTime} will always use the current value of {@link System#currentTimeMillis()} as + * the reference {@link Instant}. *

* If the {@link Instant} formatted is before the reference {@link Instant}, the format command will produce a * {@link String} that is in the past tense. If the {@link Instant} formatted is after the reference {@link Instant}, @@ -1315,9 +1354,9 @@ public PrettyTime setReference(final LocalDate localDate) } /** - * Converts the given {@link LocalDate} to the reference {@link Instant} using the given {@link ZoneId}. - * If null, {@link PrettyTime} will always use the current value of {@link System#currentTimeMillis()} - * as the reference {@link Instant}. + * Converts the given {@link LocalDate} to the reference {@link Instant} using the given {@link ZoneId}. If + * null, {@link PrettyTime} will always use the current value of {@link System#currentTimeMillis()} as + * the reference {@link Instant}. *

* If the {@link Instant} formatted is before the reference {@link Instant}, the format command will produce a * {@link String} that is in the past tense. If the {@link Instant} formatted is after the reference {@link Instant}, @@ -1354,8 +1393,7 @@ public UNIT getUnit(final Class unitType) return null; for (TimeUnit unit : units.keySet()) { - if (unitType.isAssignableFrom(unit.getClass())) - { + if (unitType.isAssignableFrom(unit.getClass())) { return (UNIT) unit; } } @@ -1395,8 +1433,7 @@ public TimeFormat removeUnit(final Class unitType) return null; for (TimeUnit unit : units.keySet()) { - if (unitType.isAssignableFrom(unit.getClass())) - { + if (unitType.isAssignableFrom(unit.getClass())) { cachedUnits = null; return units.remove(unit); @@ -1507,32 +1544,27 @@ private Duration calculateDuration(final long difference) DurationImpl result = new DurationImpl(); - for (int i = 0; i < localUnits.size(); i++) - { + for (int i = 0; i < localUnits.size(); i++) { TimeUnit unit = localUnits.get(i); long millisPerUnit = Math.abs(unit.getMillisPerUnit()); long quantity = Math.abs(unit.getMaxQuantity()); boolean isLastUnit = (i == localUnits.size() - 1); - if ((0 == quantity) && !isLastUnit) - { + if ((0 == quantity) && !isLastUnit) { quantity = localUnits.get(i + 1).getMillisPerUnit() / unit.getMillisPerUnit(); } /* * Does our unit encompass the time duration? */ - if ((millisPerUnit * quantity > absoluteDifference) || isLastUnit) - { + if ((millisPerUnit * quantity > absoluteDifference) || isLastUnit) { result.setUnit(unit); - if (millisPerUnit > absoluteDifference) - { + if (millisPerUnit > absoluteDifference) { result.setQuantity(getSign(difference)); result.setDelta(0); } - else - { + else { result.setQuantity(difference / millisPerUnit); result.setDelta(difference - result.getQuantity() * millisPerUnit); } @@ -1545,12 +1577,10 @@ private Duration calculateDuration(final long difference) private long getSign(final long difference) { - if (0 > difference) - { + if (0 > difference) { return -1; } - else - { + else { return 1; } } diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_cs.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_cs.java index 4f06e92f..27d4ddc8 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_cs.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_cs.java @@ -263,7 +263,7 @@ CsTimeFormat build(final ResourceBundle bundle) } - private static class CsTimeFormat extends SimpleTimeFormat implements TimeFormat + private static class CsTimeFormat extends SimpleTimeFormat { private final List futureNames = new ArrayList(); @@ -283,19 +283,23 @@ public CsTimeFormat(String resourceKeyPrefix, ResourceBundle bundle, Collection< try { setFuturePluralName(bundle.getString(resourceKeyPrefix + "FuturePluralName")); } - catch (Exception e) {} + catch (Exception e) { + } try { setFutureSingularName((bundle.getString(resourceKeyPrefix + "FutureSingularName"))); } - catch (Exception e) {} + catch (Exception e) { + } try { setPastPluralName((bundle.getString(resourceKeyPrefix + "PastPluralName"))); } - catch (Exception e) {} + catch (Exception e) { + } try { setPastSingularName((bundle.getString(resourceKeyPrefix + "PastSingularName"))); } - catch (Exception e) {} + catch (Exception e) { + } for (CsName name : names) { if (name.isFuture()) { diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_et.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_et.java index 64b851f5..4905b199 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_et.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_et.java @@ -15,18 +15,6 @@ */ package org.ocpsoft.prettytime.i18n; -import java.util.ListResourceBundle; -import java.util.ResourceBundle; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import org.ocpsoft.prettytime.Duration; -import org.ocpsoft.prettytime.TimeFormat; -import org.ocpsoft.prettytime.TimeUnit; -import org.ocpsoft.prettytime.format.SimpleTimeFormat; -import org.ocpsoft.prettytime.impl.TimeFormatProvider; -import org.ocpsoft.prettytime.units.Day; - public class Resources_et extends Resources_fi { private static final Object[][] OBJECTS = new Object[][] { diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_hr.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_hr.java index f3741f56..1e9108ac 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_hr.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_hr.java @@ -37,263 +37,288 @@ public class Resources_hr extends ListResourceBundle implements TimeFormatProvider { - private static final Object[][] OBJECTS = new Object[][] { - { "CenturyPattern", "%n %u" }, - { "CenturyFuturePrefix", "za " }, - { "CenturyFutureSuffix", "" }, - { "CenturyPastPrefix", "" }, - { "CenturyPastSuffix", " unatrag" }, - { "CenturySingularName", "stoljeće" }, - { "CenturyPluralName", "stoljeća" }, - { "DayPattern", "%n %u" }, - { "DayFuturePrefix", "za " }, - { "DayFutureSuffix", "" }, - { "DayPastPrefix", "prije " }, - { "DayPastSuffix", "" }, - { "DaySingularName", "dan" }, - { "DayPluralName", "dana" }, - { "DecadePattern", "%n %u" }, - { "DecadeFuturePrefix", "za " }, - { "DecadeFutureSuffix", "" }, - { "DecadePastPrefix", "prije " }, - { "DecadePastSuffix", "" }, - { "DecadeSingularName", "desetljeće" }, - { "DecadePluralName", "desetljeća" }, - { "HourPattern", "%n %u" }, - { "HourFuturePrefix", "za " }, - { "HourFutureSuffix", "" }, - { "HourPastPrefix", "prije " }, - { "HourPastSuffix", "" }, - { "HourSingularName", "sat" }, - { "HourPluralName", "sati" }, - { "JustNowPattern", "%u" }, - { "JustNowFuturePrefix", "za nekoliko trenutaka" }, - { "JustNowFutureSuffix", "" }, - { "JustNowPastPrefix", "prije nekoliko trenutaka" }, - { "JustNowPastSuffix", "" }, - { "JustNowSingularName", "" }, - { "JustNowPluralName", "" }, - { "MillenniumPattern", "%n %u" }, - { "MillenniumFuturePrefix", "za " }, - { "MillenniumFutureSuffix", "" }, - { "MillenniumPastPrefix", "prije " }, - { "MillenniumPastSuffix", "" }, - { "MillenniumSingularName", "tisućljeće" }, - { "MillenniumPluralName", "tisućljeća" }, - { "MillisecondPattern", "%n %u" }, - { "MillisecondFuturePrefix", "za " }, - { "MillisecondFutureSuffix", "" }, - { "MillisecondPastPrefix", "prije " }, - { "MillisecondPastSuffix", "" }, - { "MillisecondSingularName", "milisekunda" }, - { "MillisecondPluralName", "milisekunda" }, - { "MinutePattern", "%n %u" }, - { "MinuteFuturePrefix", "za " }, - { "MinuteFutureSuffix", "" }, - { "MinutePastPrefix", "prije " }, - { "MinutePastSuffix", "" }, - { "MinuteSingularName", "minuta" }, - { "MinutePluralName", "minuta" }, - { "MonthPattern", "%n %u" }, - { "MonthFuturePrefix", "za " }, - { "MonthFutureSuffix", "" }, - { "MonthPastPrefix", "prije " }, - { "MonthPastSuffix", "" }, - { "MonthSingularName", "mjesec" }, - { "MonthPluralName", "mjeseca" }, - { "SecondPattern", "%n %u" }, - { "SecondFuturePrefix", "za " }, - { "SecondFutureSuffix", "" }, - { "SecondPastPrefix", "prije " }, - { "SecondPastSuffix", "" }, - { "SecondSingularName", "sekunda" }, - { "SecondPluralName", "sekundi" }, - { "WeekPattern", "%n %u" }, - { "WeekFuturePrefix", "za " }, - { "WeekFutureSuffix", "" }, - { "WeekPastPrefix", "prije " }, - { "WeekPastSuffix", "" }, - { "WeekSingularName", "tjedan" }, - { "WeekPluralName", "tjedna" }, - { "YearPattern", "%n %u" }, - { "YearFuturePrefix", "za " }, - { "YearFutureSuffix", "" }, - { "YearPastPrefix", "prije " }, - { "YearPastSuffix", "" }, - { "YearSingularName", "godina" }, - { "YearPluralName", "godina" }, - { "AbstractTimeUnitPattern", "" }, - { "AbstractTimeUnitFuturePrefix", "" }, - { "AbstractTimeUnitFutureSuffix", "" }, - { "AbstractTimeUnitPastPrefix", "" }, - { "AbstractTimeUnitPastSuffix", "" }, - { "AbstractTimeUnitSingularName", "" }, - { "AbstractTimeUnitPluralName", "" } }; - - @Override - public Object[][] getContents() - { - return OBJECTS; - } - - @Override - public TimeFormat getFormatFor(final TimeUnit t) { - if (t instanceof Minute) { - return new HrTimeFormatBuilder("Minute").addNames("minutu", 1) - .addNames("minute", 4).addNames("minuta", Long.MAX_VALUE) - .build(this); - } else if (t instanceof Hour) { - return new HrTimeFormatBuilder("Hour").addNames("sat", 1) - .addNames("sata", 4).addNames("sati", Long.MAX_VALUE) - .build(this); - } else if (t instanceof Day) { - return new HrTimeFormatBuilder("Day").addNames("dan", 1) - .addNames("dana", 4).addNames("dana", Long.MAX_VALUE) - .build(this); - } else if (t instanceof Week) { - return new HrTimeFormatBuilder("Week").addNames("tjedan", 1) - .addNames("tjedna", 4).addNames("tjedana", Long.MAX_VALUE) - .build(this); - } else if (t instanceof Month) { - return new HrTimeFormatBuilder("Month").addNames("mjesec", 1) - .addNames("mjeseca", 4).addNames("mjeseci", Long.MAX_VALUE) - .build(this); - } else if (t instanceof Year) { - return new HrTimeFormatBuilder("Year").addNames("godinu", 1) - .addNames("godine", 4).addNames("godina", Long.MAX_VALUE) - .build(this); - } else if (t instanceof Millennium) { - return new HrTimeFormatBuilder("Millennium") - .addNames("tisućljeće", 1).addNames("tisućljeća", Long.MAX_VALUE) - .build(this); - } - // Don't override format for other time units - return null; - } - - private static class HrName implements Comparable { - - private final boolean isFuture; - - private final Long threshold; - - private final String value; - - public HrName(final boolean isFuture, final String value, final Long threshold) { - this.isFuture = isFuture; - this.value = value; - this.threshold = threshold; - } - - @Override - public int compareTo(final HrName o) { - return threshold.compareTo(o.getThreshold()); - } - - public String get() { - return value; - } - - public long getThreshold() { - return threshold; - } - - public boolean isFuture() { - return isFuture; - } - } - - private static class HrTimeFormat extends SimpleTimeFormat implements TimeFormat { - - private final List futureNames = new ArrayList(); - - private final List pastNames = new ArrayList(); - - public HrTimeFormat(final String resourceKeyPrefix, final ResourceBundle bundle, final Collection names) { - setPattern(bundle.getString(resourceKeyPrefix + "Pattern")); - setFuturePrefix(bundle.getString(resourceKeyPrefix + "FuturePrefix")); - setFutureSuffix(bundle.getString(resourceKeyPrefix + "FutureSuffix")); - setPastPrefix(bundle.getString(resourceKeyPrefix + "PastPrefix")); - setPastSuffix(bundle.getString(resourceKeyPrefix + "PastSuffix")); - setSingularName(bundle.getString(resourceKeyPrefix + "SingularName")); - setPluralName(bundle.getString(resourceKeyPrefix + "PluralName")); - - try { - setFuturePluralName(bundle.getString(resourceKeyPrefix + "FuturePluralName")); - } catch (final Exception e) { - } - try { - setFutureSingularName(bundle.getString(resourceKeyPrefix + "FutureSingularName")); - } catch (final Exception e) { - } - try { - setPastPluralName(bundle.getString(resourceKeyPrefix + "PastPluralName")); - } catch (final Exception e) { - } - try { - setPastSingularName(bundle.getString(resourceKeyPrefix + "PastSingularName")); - } catch (final Exception e) { - } - - for (final HrName name : names) { - if (name.isFuture()) { - futureNames.add(name); - } - else { - pastNames.add(name); - } - } - Collections.sort(futureNames); - Collections.sort(pastNames); - } - - private String getGramaticallyCorrectName(final long quantity, final List names) { - for (final HrName name : names) { - if (name.getThreshold() >= quantity) { - return name.get(); - } - } - throw new IllegalStateException("Invalid resource bundle configuration"); - } - - @Override - protected String getGramaticallyCorrectName(final Duration d, final boolean round) { - final long quantity = Math.abs(getQuantity(d, round)); - if (d.isInFuture()) { - return getGramaticallyCorrectName(quantity, futureNames); - } - return getGramaticallyCorrectName(quantity, pastNames); - } - - } - - private static class HrTimeFormatBuilder { - - private final List names = new ArrayList(); - - private final String resourceKeyPrefix; - - HrTimeFormatBuilder(final String resourceKeyPrefix) { - this.resourceKeyPrefix = resourceKeyPrefix; - } - - private HrTimeFormatBuilder addName(final boolean isFuture, final String name, final long limit) { - if (name == null) { - throw new IllegalArgumentException(); - } - names.add(new HrName(isFuture, name, limit)); - return this; - } - - HrTimeFormatBuilder addNames(final String name, final long limit) { - return addName(true, name, limit).addName(false, name, limit); - } - - HrTimeFormat build(final ResourceBundle bundle) { - return new HrTimeFormat(resourceKeyPrefix, bundle, names); - } - - } - - -} \ No newline at end of file + private static final Object[][] OBJECTS = new Object[][] { + { "CenturyPattern", "%n %u" }, + { "CenturyFuturePrefix", "za " }, + { "CenturyFutureSuffix", "" }, + { "CenturyPastPrefix", "" }, + { "CenturyPastSuffix", " unatrag" }, + { "CenturySingularName", "stoljeće" }, + { "CenturyPluralName", "stoljeća" }, + { "DayPattern", "%n %u" }, + { "DayFuturePrefix", "za " }, + { "DayFutureSuffix", "" }, + { "DayPastPrefix", "prije " }, + { "DayPastSuffix", "" }, + { "DaySingularName", "dan" }, + { "DayPluralName", "dana" }, + { "DecadePattern", "%n %u" }, + { "DecadeFuturePrefix", "za " }, + { "DecadeFutureSuffix", "" }, + { "DecadePastPrefix", "prije " }, + { "DecadePastSuffix", "" }, + { "DecadeSingularName", "desetljeće" }, + { "DecadePluralName", "desetljeća" }, + { "HourPattern", "%n %u" }, + { "HourFuturePrefix", "za " }, + { "HourFutureSuffix", "" }, + { "HourPastPrefix", "prije " }, + { "HourPastSuffix", "" }, + { "HourSingularName", "sat" }, + { "HourPluralName", "sati" }, + { "JustNowPattern", "%u" }, + { "JustNowFuturePrefix", "za nekoliko trenutaka" }, + { "JustNowFutureSuffix", "" }, + { "JustNowPastPrefix", "prije nekoliko trenutaka" }, + { "JustNowPastSuffix", "" }, + { "JustNowSingularName", "" }, + { "JustNowPluralName", "" }, + { "MillenniumPattern", "%n %u" }, + { "MillenniumFuturePrefix", "za " }, + { "MillenniumFutureSuffix", "" }, + { "MillenniumPastPrefix", "prije " }, + { "MillenniumPastSuffix", "" }, + { "MillenniumSingularName", "tisućljeće" }, + { "MillenniumPluralName", "tisućljeća" }, + { "MillisecondPattern", "%n %u" }, + { "MillisecondFuturePrefix", "za " }, + { "MillisecondFutureSuffix", "" }, + { "MillisecondPastPrefix", "prije " }, + { "MillisecondPastSuffix", "" }, + { "MillisecondSingularName", "milisekunda" }, + { "MillisecondPluralName", "milisekunda" }, + { "MinutePattern", "%n %u" }, + { "MinuteFuturePrefix", "za " }, + { "MinuteFutureSuffix", "" }, + { "MinutePastPrefix", "prije " }, + { "MinutePastSuffix", "" }, + { "MinuteSingularName", "minuta" }, + { "MinutePluralName", "minuta" }, + { "MonthPattern", "%n %u" }, + { "MonthFuturePrefix", "za " }, + { "MonthFutureSuffix", "" }, + { "MonthPastPrefix", "prije " }, + { "MonthPastSuffix", "" }, + { "MonthSingularName", "mjesec" }, + { "MonthPluralName", "mjeseca" }, + { "SecondPattern", "%n %u" }, + { "SecondFuturePrefix", "za " }, + { "SecondFutureSuffix", "" }, + { "SecondPastPrefix", "prije " }, + { "SecondPastSuffix", "" }, + { "SecondSingularName", "sekunda" }, + { "SecondPluralName", "sekundi" }, + { "WeekPattern", "%n %u" }, + { "WeekFuturePrefix", "za " }, + { "WeekFutureSuffix", "" }, + { "WeekPastPrefix", "prije " }, + { "WeekPastSuffix", "" }, + { "WeekSingularName", "tjedan" }, + { "WeekPluralName", "tjedna" }, + { "YearPattern", "%n %u" }, + { "YearFuturePrefix", "za " }, + { "YearFutureSuffix", "" }, + { "YearPastPrefix", "prije " }, + { "YearPastSuffix", "" }, + { "YearSingularName", "godina" }, + { "YearPluralName", "godina" }, + { "AbstractTimeUnitPattern", "" }, + { "AbstractTimeUnitFuturePrefix", "" }, + { "AbstractTimeUnitFutureSuffix", "" }, + { "AbstractTimeUnitPastPrefix", "" }, + { "AbstractTimeUnitPastSuffix", "" }, + { "AbstractTimeUnitSingularName", "" }, + { "AbstractTimeUnitPluralName", "" } }; + + @Override + public Object[][] getContents() + { + return OBJECTS; + } + + @Override + public TimeFormat getFormatFor(final TimeUnit t) + { + if (t instanceof Minute) { + return new HrTimeFormatBuilder("Minute").addNames("minutu", 1) + .addNames("minute", 4).addNames("minuta", Long.MAX_VALUE) + .build(this); + } + else if (t instanceof Hour) { + return new HrTimeFormatBuilder("Hour").addNames("sat", 1) + .addNames("sata", 4).addNames("sati", Long.MAX_VALUE) + .build(this); + } + else if (t instanceof Day) { + return new HrTimeFormatBuilder("Day").addNames("dan", 1) + .addNames("dana", 4).addNames("dana", Long.MAX_VALUE) + .build(this); + } + else if (t instanceof Week) { + return new HrTimeFormatBuilder("Week").addNames("tjedan", 1) + .addNames("tjedna", 4).addNames("tjedana", Long.MAX_VALUE) + .build(this); + } + else if (t instanceof Month) { + return new HrTimeFormatBuilder("Month").addNames("mjesec", 1) + .addNames("mjeseca", 4).addNames("mjeseci", Long.MAX_VALUE) + .build(this); + } + else if (t instanceof Year) { + return new HrTimeFormatBuilder("Year").addNames("godinu", 1) + .addNames("godine", 4).addNames("godina", Long.MAX_VALUE) + .build(this); + } + else if (t instanceof Millennium) { + return new HrTimeFormatBuilder("Millennium") + .addNames("tisućljeće", 1).addNames("tisućljeća", Long.MAX_VALUE) + .build(this); + } + // Don't override format for other time units + return null; + } + + private static class HrName implements Comparable + { + + private final boolean isFuture; + + private final Long threshold; + + private final String value; + + public HrName(final boolean isFuture, final String value, final Long threshold) + { + this.isFuture = isFuture; + this.value = value; + this.threshold = threshold; + } + + @Override + public int compareTo(final HrName o) + { + return threshold.compareTo(o.getThreshold()); + } + + public String get() + { + return value; + } + + public long getThreshold() + { + return threshold; + } + + public boolean isFuture() + { + return isFuture; + } + } + + private static class HrTimeFormat extends SimpleTimeFormat + { + + private final List futureNames = new ArrayList(); + + private final List pastNames = new ArrayList(); + + public HrTimeFormat(final String resourceKeyPrefix, final ResourceBundle bundle, final Collection names) + { + setPattern(bundle.getString(resourceKeyPrefix + "Pattern")); + setFuturePrefix(bundle.getString(resourceKeyPrefix + "FuturePrefix")); + setFutureSuffix(bundle.getString(resourceKeyPrefix + "FutureSuffix")); + setPastPrefix(bundle.getString(resourceKeyPrefix + "PastPrefix")); + setPastSuffix(bundle.getString(resourceKeyPrefix + "PastSuffix")); + setSingularName(bundle.getString(resourceKeyPrefix + "SingularName")); + setPluralName(bundle.getString(resourceKeyPrefix + "PluralName")); + + try { + setFuturePluralName(bundle.getString(resourceKeyPrefix + "FuturePluralName")); + } + catch (final Exception e) { + } + try { + setFutureSingularName(bundle.getString(resourceKeyPrefix + "FutureSingularName")); + } + catch (final Exception e) { + } + try { + setPastPluralName(bundle.getString(resourceKeyPrefix + "PastPluralName")); + } + catch (final Exception e) { + } + try { + setPastSingularName(bundle.getString(resourceKeyPrefix + "PastSingularName")); + } + catch (final Exception e) { + } + + for (final HrName name : names) { + if (name.isFuture()) { + futureNames.add(name); + } + else { + pastNames.add(name); + } + } + Collections.sort(futureNames); + Collections.sort(pastNames); + } + + private String getGramaticallyCorrectName(final long quantity, final List names) + { + for (final HrName name : names) { + if (name.getThreshold() >= quantity) { + return name.get(); + } + } + throw new IllegalStateException("Invalid resource bundle configuration"); + } + + @Override + protected String getGramaticallyCorrectName(final Duration d, final boolean round) + { + final long quantity = Math.abs(getQuantity(d, round)); + if (d.isInFuture()) { + return getGramaticallyCorrectName(quantity, futureNames); + } + return getGramaticallyCorrectName(quantity, pastNames); + } + + } + + private static class HrTimeFormatBuilder + { + + private final List names = new ArrayList(); + + private final String resourceKeyPrefix; + + HrTimeFormatBuilder(final String resourceKeyPrefix) + { + this.resourceKeyPrefix = resourceKeyPrefix; + } + + private HrTimeFormatBuilder addName(final boolean isFuture, final String name, final long limit) + { + if (name == null) { + throw new IllegalArgumentException(); + } + names.add(new HrName(isFuture, name, limit)); + return this; + } + + HrTimeFormatBuilder addNames(final String name, final long limit) + { + return addName(true, name, limit).addName(false, name, limit); + } + + HrTimeFormat build(final ResourceBundle bundle) + { + return new HrTimeFormat(resourceKeyPrefix, bundle, names); + } + + } + +} diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ja.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ja.java index fdff6df1..06fa641d 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ja.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ja.java @@ -1,5 +1,10 @@ package org.ocpsoft.prettytime.i18n; +import java.util.ListResourceBundle; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.concurrent.ConcurrentHashMap; + import org.ocpsoft.prettytime.Duration; import org.ocpsoft.prettytime.TimeFormat; import org.ocpsoft.prettytime.TimeUnit; @@ -7,11 +12,6 @@ import org.ocpsoft.prettytime.units.Decade; import org.ocpsoft.prettytime.units.Millennium; -import java.util.ListResourceBundle; -import java.util.Map; -import java.util.ResourceBundle; -import java.util.concurrent.ConcurrentHashMap; - public class Resources_ja extends ListResourceBundle implements TimeFormatProvider { private static final Object[][] OBJECTS = new Object[][] { @@ -129,7 +129,6 @@ private static class JaTimeFormat implements TimeFormat public static final String QUANTITY = "%n"; public static final String UNIT = "%u"; - private final ResourceBundle bundle; private String singularName = ""; private String pluralName = ""; private String futureSingularName = ""; @@ -147,8 +146,6 @@ private static class JaTimeFormat implements TimeFormat public JaTimeFormat(final ResourceBundle bundle, final TimeUnit unit) { - this.bundle = bundle; - setPattern(bundle.getString(getUnitName(unit) + "Pattern")); setFuturePrefix(bundle.getString(getUnitName(unit) + "FuturePrefix")); setFutureSuffix(bundle.getString(getUnitName(unit) + "FutureSuffix")); @@ -161,19 +158,23 @@ public JaTimeFormat(final ResourceBundle bundle, final TimeUnit unit) try { setFuturePluralName(bundle.getString(getUnitName(unit) + "FuturePluralName")); } - catch (Exception e) {} + catch (Exception e) { + } try { setFutureSingularName((bundle.getString(getUnitName(unit) + "FutureSingularName"))); } - catch (Exception e) {} + catch (Exception e) { + } try { setPastPluralName((bundle.getString(getUnitName(unit) + "PastPluralName"))); } - catch (Exception e) {} + catch (Exception e) { + } try { setPastSingularName((bundle.getString(getUnitName(unit) + "PastSingularName"))); } - catch (Exception e) {} + catch (Exception e) { + } } private String getUnitName(TimeUnit unit) @@ -198,8 +199,10 @@ private String format(final Duration duration, final boolean round) String sign = getSign(duration); String unit = getGramaticallyCorrectName(duration, round); long quantity = getQuantity(duration, round); - if (duration.getUnit() instanceof Decade) quantity *= 10; - if (duration.getUnit() instanceof Millennium) quantity *= 1000; + if (duration.getUnit() instanceof Decade) + quantity *= 10; + if (duration.getUnit() instanceof Millennium) + quantity *= 1000; return applyPattern(sign, unit, quantity); } @@ -218,11 +221,6 @@ protected String getPattern(final long quantity) return pattern; } - public String getPattern() - { - return pattern; - } - protected long getQuantity(Duration duration, boolean round) { return Math.abs(round ? duration.getQuantityRounded(roundingTolerance) : duration.getQuantity()); @@ -323,19 +321,6 @@ public JaTimeFormat setPastSuffix(final String pastSuffix) return this; } - /** - * The percentage of the current {@link TimeUnit}.getMillisPerUnit() for which the quantity may be rounded up by - * one. - * - * @param roundingTolerance - * @return - */ - public JaTimeFormat setRoundingTolerance(final int roundingTolerance) - { - this.roundingTolerance = roundingTolerance; - return this; - } - public JaTimeFormat setSingularName(String name) { this.singularName = name; diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sk.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sk.java index 134cfe5a..a9c5cb7f 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sk.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sk.java @@ -263,7 +263,7 @@ CsTimeFormat build(final ResourceBundle bundle) } - private static class CsTimeFormat extends SimpleTimeFormat implements TimeFormat + private static class CsTimeFormat extends SimpleTimeFormat { private final List futureNames = new ArrayList(); @@ -283,19 +283,23 @@ public CsTimeFormat(String resourceKeyPrefix, ResourceBundle bundle, Collection< try { setFuturePluralName(bundle.getString(resourceKeyPrefix + "FuturePluralName")); } - catch (Exception e) {} + catch (Exception e) { + } try { setFutureSingularName((bundle.getString(resourceKeyPrefix + "FutureSingularName"))); } - catch (Exception e) {} + catch (Exception e) { + } try { setPastPluralName((bundle.getString(resourceKeyPrefix + "PastPluralName"))); } - catch (Exception e) {} + catch (Exception e) { + } try { setPastSingularName((bundle.getString(resourceKeyPrefix + "PastSingularName"))); } - catch (Exception e) {} + catch (Exception e) { + } for (CsName name : names) { if (name.isFuture()) { diff --git a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java index 6dafa2c3..fb9faad3 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java +++ b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java @@ -1,19 +1,19 @@ package org.ocpsoft.prettytime.impl; +import java.util.Locale; +import java.util.ResourceBundle; + import org.ocpsoft.prettytime.Duration; import org.ocpsoft.prettytime.LocaleAware; import org.ocpsoft.prettytime.TimeFormat; import org.ocpsoft.prettytime.format.SimpleTimeFormat; -import java.util.Locale; -import java.util.ResourceBundle; - /** * Represents a simple method of formatting a specific {@link Duration} of time * * @author lb3 */ -public class ResourcesTimeFormat extends SimpleTimeFormat implements TimeFormat, LocaleAware +public class ResourcesTimeFormat extends SimpleTimeFormat implements LocaleAware { private final ResourcesTimeUnit unit; private TimeFormat override; @@ -38,7 +38,8 @@ public ResourcesTimeFormat setLocale(Locale locale) try { // Attempt to load the bundle that the user passed in, maybe it exists, maybe not bundle = ResourceBundle.getBundle(overrideResourceBundle, locale); - } catch (Exception e) { + } + catch (Exception e) { // Throw away if the bundle doesn't contain this local } } @@ -48,21 +49,17 @@ public ResourcesTimeFormat setLocale(Locale locale) bundle = ResourceBundle.getBundle(unit.getResourceBundleName(), locale); } - if (bundle instanceof TimeFormatProvider) - { + if (bundle instanceof TimeFormatProvider) { TimeFormat format = ((TimeFormatProvider) bundle).getFormatFor(unit); - if (format != null) - { + if (format != null) { this.override = format; } } - else - { + else { override = null; } - if (override == null) - { + if (override == null) { setPattern(bundle.getString(unit.getResourceKeyPrefix() + "Pattern")); setFuturePrefix(bundle.getString(unit.getResourceKeyPrefix() + "FuturePrefix")); setFutureSuffix(bundle.getString(unit.getResourceKeyPrefix() + "FutureSuffix")); @@ -75,19 +72,23 @@ public ResourcesTimeFormat setLocale(Locale locale) try { setFuturePluralName(bundle.getString(unit.getResourceKeyPrefix() + "FuturePluralName")); } - catch (Exception e) {} + catch (Exception e) { + } try { setFutureSingularName((bundle.getString(unit.getResourceKeyPrefix() + "FutureSingularName"))); } - catch (Exception e) {} + catch (Exception e) { + } try { setPastPluralName((bundle.getString(unit.getResourceKeyPrefix() + "PastPluralName"))); } - catch (Exception e) {} + catch (Exception e) { + } try { setPastSingularName((bundle.getString(unit.getResourceKeyPrefix() + "PastSingularName"))); } - catch (Exception e) {} + catch (Exception e) { + } } diff --git a/core/src/main/java/org/ocpsoft/prettytime/units/Century.java b/core/src/main/java/org/ocpsoft/prettytime/units/Century.java index e25945e1..da95bac6 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/units/Century.java +++ b/core/src/main/java/org/ocpsoft/prettytime/units/Century.java @@ -15,10 +15,9 @@ */ package org.ocpsoft.prettytime.units; -import org.ocpsoft.prettytime.TimeUnit; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; -public class Century extends ResourcesTimeUnit implements TimeUnit +public class Century extends ResourcesTimeUnit { public Century() { diff --git a/core/src/main/java/org/ocpsoft/prettytime/units/Day.java b/core/src/main/java/org/ocpsoft/prettytime/units/Day.java index dc9bf55d..e6b88d18 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/units/Day.java +++ b/core/src/main/java/org/ocpsoft/prettytime/units/Day.java @@ -15,10 +15,9 @@ */ package org.ocpsoft.prettytime.units; -import org.ocpsoft.prettytime.TimeUnit; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; -public class Day extends ResourcesTimeUnit implements TimeUnit +public class Day extends ResourcesTimeUnit { public Day() diff --git a/core/src/main/java/org/ocpsoft/prettytime/units/Decade.java b/core/src/main/java/org/ocpsoft/prettytime/units/Decade.java index 55901428..d2c79fbd 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/units/Decade.java +++ b/core/src/main/java/org/ocpsoft/prettytime/units/Decade.java @@ -15,10 +15,9 @@ */ package org.ocpsoft.prettytime.units; -import org.ocpsoft.prettytime.TimeUnit; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; -public class Decade extends ResourcesTimeUnit implements TimeUnit +public class Decade extends ResourcesTimeUnit { public Decade() diff --git a/core/src/main/java/org/ocpsoft/prettytime/units/Hour.java b/core/src/main/java/org/ocpsoft/prettytime/units/Hour.java index bc32843b..01ad54fc 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/units/Hour.java +++ b/core/src/main/java/org/ocpsoft/prettytime/units/Hour.java @@ -15,10 +15,9 @@ */ package org.ocpsoft.prettytime.units; -import org.ocpsoft.prettytime.TimeUnit; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; -public class Hour extends ResourcesTimeUnit implements TimeUnit +public class Hour extends ResourcesTimeUnit { public Hour() diff --git a/core/src/main/java/org/ocpsoft/prettytime/units/JustNow.java b/core/src/main/java/org/ocpsoft/prettytime/units/JustNow.java index 86f5563d..912ffa78 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/units/JustNow.java +++ b/core/src/main/java/org/ocpsoft/prettytime/units/JustNow.java @@ -15,10 +15,9 @@ */ package org.ocpsoft.prettytime.units; -import org.ocpsoft.prettytime.TimeUnit; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; -public class JustNow extends ResourcesTimeUnit implements TimeUnit +public class JustNow extends ResourcesTimeUnit { public JustNow() diff --git a/core/src/main/java/org/ocpsoft/prettytime/units/Millennium.java b/core/src/main/java/org/ocpsoft/prettytime/units/Millennium.java index 88e5c44b..695e69a5 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/units/Millennium.java +++ b/core/src/main/java/org/ocpsoft/prettytime/units/Millennium.java @@ -15,10 +15,9 @@ */ package org.ocpsoft.prettytime.units; -import org.ocpsoft.prettytime.TimeUnit; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; -public class Millennium extends ResourcesTimeUnit implements TimeUnit +public class Millennium extends ResourcesTimeUnit { public Millennium() diff --git a/core/src/main/java/org/ocpsoft/prettytime/units/Millisecond.java b/core/src/main/java/org/ocpsoft/prettytime/units/Millisecond.java index 3b0c3716..31138b81 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/units/Millisecond.java +++ b/core/src/main/java/org/ocpsoft/prettytime/units/Millisecond.java @@ -15,10 +15,9 @@ */ package org.ocpsoft.prettytime.units; -import org.ocpsoft.prettytime.TimeUnit; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; -public class Millisecond extends ResourcesTimeUnit implements TimeUnit +public class Millisecond extends ResourcesTimeUnit { public Millisecond() diff --git a/core/src/main/java/org/ocpsoft/prettytime/units/Minute.java b/core/src/main/java/org/ocpsoft/prettytime/units/Minute.java index bf30e307..f499bdba 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/units/Minute.java +++ b/core/src/main/java/org/ocpsoft/prettytime/units/Minute.java @@ -15,10 +15,9 @@ */ package org.ocpsoft.prettytime.units; -import org.ocpsoft.prettytime.TimeUnit; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; -public class Minute extends ResourcesTimeUnit implements TimeUnit +public class Minute extends ResourcesTimeUnit { public Minute() diff --git a/core/src/main/java/org/ocpsoft/prettytime/units/Month.java b/core/src/main/java/org/ocpsoft/prettytime/units/Month.java index c9ea6fa0..3d1b79cc 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/units/Month.java +++ b/core/src/main/java/org/ocpsoft/prettytime/units/Month.java @@ -15,10 +15,9 @@ */ package org.ocpsoft.prettytime.units; -import org.ocpsoft.prettytime.TimeUnit; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; -public class Month extends ResourcesTimeUnit implements TimeUnit +public class Month extends ResourcesTimeUnit { public Month() diff --git a/core/src/main/java/org/ocpsoft/prettytime/units/Second.java b/core/src/main/java/org/ocpsoft/prettytime/units/Second.java index 3649b972..ece6bbc7 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/units/Second.java +++ b/core/src/main/java/org/ocpsoft/prettytime/units/Second.java @@ -15,10 +15,9 @@ */ package org.ocpsoft.prettytime.units; -import org.ocpsoft.prettytime.TimeUnit; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; -public class Second extends ResourcesTimeUnit implements TimeUnit +public class Second extends ResourcesTimeUnit { public Second() diff --git a/core/src/main/java/org/ocpsoft/prettytime/units/Week.java b/core/src/main/java/org/ocpsoft/prettytime/units/Week.java index 29c07b97..e8558bd3 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/units/Week.java +++ b/core/src/main/java/org/ocpsoft/prettytime/units/Week.java @@ -15,10 +15,9 @@ */ package org.ocpsoft.prettytime.units; -import org.ocpsoft.prettytime.TimeUnit; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; -public class Week extends ResourcesTimeUnit implements TimeUnit +public class Week extends ResourcesTimeUnit { public Week() diff --git a/core/src/main/java/org/ocpsoft/prettytime/units/Year.java b/core/src/main/java/org/ocpsoft/prettytime/units/Year.java index f12a0ac3..be9ada5d 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/units/Year.java +++ b/core/src/main/java/org/ocpsoft/prettytime/units/Year.java @@ -15,10 +15,9 @@ */ package org.ocpsoft.prettytime.units; -import org.ocpsoft.prettytime.TimeUnit; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; -public class Year extends ResourcesTimeUnit implements TimeUnit +public class Year extends ResourcesTimeUnit { public Year() 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 50f2723e..8fae8d26 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 @@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals; import java.text.SimpleDateFormat; +import java.time.LocalDateTime; import java.util.Date; import java.util.Locale; @@ -42,7 +43,7 @@ public void setUp() throws Exception public void testPrettyTime() { PrettyTime p = new PrettyTime(locale); - assertEquals("straks", p.format(new Date())); + assertEquals("et øjeblik siden", p.format(LocalDateTime.now().minusSeconds(1))); } @Test @@ -207,4 +208,4 @@ public void testCenturiesAgo() throws Exception PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale); assertEquals("3 århundreder siden", t.format(new Date(0))); } -} \ 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 eb446e45..ad834015 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 @@ -30,19 +30,22 @@ import org.ocpsoft.prettytime.impl.ResourcesTimeFormat; import org.ocpsoft.prettytime.units.Minute; -public class PrettyTimeI18n_EO_Test { +public class PrettyTimeI18n_EO_Test +{ SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); private Locale locale; @Before - public void setUp() throws Exception { + public void setUp() throws Exception + { locale = new Locale("eo"); Locale.setDefault(locale); } @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); @@ -50,23 +53,26 @@ public void testCeilingInterval() throws Exception { } @Test - public void testNullDate() throws Exception { + public void testNullDate() throws Exception + { PrettyTime t = new PrettyTime(); Date date = null; Assert.assertEquals("nun", t.format(date)); } @Test - public void testRightNow() throws Exception { + public void testRightNow() throws Exception + { PrettyTime t = new PrettyTime(); Assert.assertEquals("nun", t.format(new Date())); } @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))); + new Date(System.currentTimeMillis() - (2 * 60 * 60 * 1000) - (2 * 60 * 1000))); Assert.assertEquals("antaŭ 2 horoj 2 minutoj", t.format(preciseDuration)); Assert.assertEquals("2 horoj 2 minutoj", t.formatDuration(preciseDuration)); Assert.assertEquals("nun", t.format(t.calculatePreciseDuration(new Date()))); @@ -74,75 +80,87 @@ public void testCalculatePreciceDuration() throws Exception { @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("antaŭ 1 jarmilo 9 jarcentoj 4 jardekoj 4 jaroj 8 monatoj 1 semajno 6 tagoj 14 horoj 5 minutoj", - t.format(durations)); - Assert.assertEquals("1 jarmilo 9 jarcentoj 4 jardekoj 4 jaroj 8 monatoj 1 semajno 6 tagoj 14 horoj 5 minutoj", - t.formatDuration(durations)); + Assert.assertEquals( + "antaŭ 1 jarmilo 9 jarcentoj 4 jardekoj 4 jaroj 8 monatoj 1 semajno 6 tagoj 20 horoj 5 minutoj", + t.format(durations)); + Assert.assertEquals("1 jarmilo 9 jarcentoj 4 jardekoj 4 jaroj 8 monatoj 1 semajno 6 tagoj 20 horoj 5 minutoj", + t.formatDuration(durations)); } @Test - public void testCalculatePreciseDuration2() { + public void testCalculatePreciseDuration2() + { PrettyTime prettyTime = new PrettyTime(); prettyTime.clearUnits(); Minute minutoj = new Minute(); prettyTime.registerUnit(minutoj, new ResourcesTimeFormat(minutoj)); Assert.assertEquals("antaŭ 40 minutoj", 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("nun", 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("post 12 minutoj", 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("post 3 horoj", 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("post 3 tagoj", 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("post 3 semajnoj", 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("post 3 monatoj", 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("post 3 jaroj", 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("post 3 jardekoj", 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("post 3 jarcentoj", t.format(new Date(3155692597470L * 3L))); } @@ -151,79 +169,91 @@ 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("nun", 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("antaŭ 12 minutoj", t.format(new Date(0))); } @Test - public void testMinutesFromNowDefaultReference() throws Exception { + public void testMinutesFromNowDefaultReference() throws Exception + { PrettyTime t = new PrettyTime(); Assert.assertEquals("post 12 minutoj", 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("antaŭ 3 horoj", t.format(new Date(0))); } @Test - public void testHoursAgoDefaultReference() throws Exception { + public void testHoursAgoDefaultReference() throws Exception + { PrettyTime t = new PrettyTime(); Assert.assertEquals("antaŭ 3 horoj", 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("antaŭ 3 tagoj", 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("antaŭ 3 semajnoj", 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("antaŭ 3 monatoj", t.format(new Date(0))); } @Test - public void testCustomFormat() throws Exception { + public void testCustomFormat() throws Exception + { PrettyTime t = new PrettyTime(new Date(0)); 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("ticks") - .setPattern("%n %u").setRoundingTolerance(20) - .setFutureSuffix("... RUN!") - .setFuturePrefix("self destruct in: ").setPastPrefix("self destruct was: ").setPastSuffix( - "...")); + .setSingularName("tick").setPluralName("ticks") + .setPattern("%n %u").setRoundingTolerance(20) + .setFutureSuffix("... RUN!") + .setFuturePrefix("self destruct in: ").setPastPrefix("self destruct was: ").setPastSuffix( + "...")); Assert.assertEquals("self destruct in: 5 ticks ... RUN!", t.format(new Date(25000))); t.setReference(new Date(25000)); @@ -231,66 +261,75 @@ public boolean isPrecise() { } @Test - public void testYearsAgo() throws Exception { + public void testYearsAgo() throws Exception + { PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L)); Assert.assertEquals("antaŭ 3 jaroj", 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("antaŭ 3 jardekoj", 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("antaŭ 3 jarcentoj", t.format(new Date(0))); } @Test - public void testWithinTwoHoursRounding() throws Exception { + public void testWithinTwoHoursRounding() throws Exception + { PrettyTime t = new PrettyTime(); Assert.assertEquals("antaŭ 2 horoj", t.format(new Date(new Date().getTime() - 6543990))); } @Test - public void testPreciseInTheFuture() throws Exception { + 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()); } @Test - public void testPreciseInThePast() throws Exception { + 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()); } @Test - public void testFormattingDurationListInThePast() throws Exception { + public void testFormattingDurationListInThePast() throws Exception + { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3 + 1000 * 60 * 60 * 15 + 1000 * 60 * 38)); List durations = t.calculatePreciseDuration(new Date(0)); Assert.assertEquals("antaŭ 3 tagoj 15 horoj 38 minutoj", t.format(durations)); } @Test - public void testFormattingDurationListInTheFuture() throws Exception { + 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("post 3 tagoj 15 horoj 38 minutoj", t.format(durations)); } @Test - public void testSetLocale() throws Exception { + public void testSetLocale() throws Exception + { PrettyTime t = new PrettyTime(new Date(315569259747L * 3L)); Assert.assertEquals("antaŭ 3 jardekoj", t.format(new Date(0))); t.setLocale(Locale.GERMAN); @@ -305,7 +344,8 @@ public void testSetLocale() 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(); @@ -321,7 +361,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(); @@ -330,7 +371,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(); @@ -339,7 +381,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(); @@ -348,73 +391,80 @@ public void testFormatDurationUnrounded() throws Exception { } @Test - public void testFormatList() throws Exception { + public void testFormatList() throws Exception + { PrettyTime prettyTime = new PrettyTime(); prettyTime.clearUnits(); Minute minutoj = new Minute(); prettyTime.registerUnit(minutoj, new ResourcesTimeFormat(minutoj)); Assert.assertEquals("antaŭ 41 minutoj", - 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 - public void testFormatListUnrounded() throws Exception { + public void testFormatListUnrounded() throws Exception + { PrettyTime prettyTime = new PrettyTime(); prettyTime.clearUnits(); Minute minutoj = new Minute(); prettyTime.registerUnit(minutoj, new ResourcesTimeFormat(minutoj)); Assert.assertEquals("antaŭ 40 minutoj", - 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 - public void testFormatDurationList() throws Exception { + public void testFormatDurationList() throws Exception + { PrettyTime prettyTime = new PrettyTime(); prettyTime.clearUnits(); Minute minutoj = new Minute(); prettyTime.registerUnit(minutoj, new ResourcesTimeFormat(minutoj)); Assert.assertEquals("41 minutoj", - 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 - public void testFormatDurationListUnrounded() throws Exception { + public void testFormatDurationListUnrounded() throws Exception + { PrettyTime prettyTime = new PrettyTime(); prettyTime.clearUnits(); Minute minutoj = new Minute(); prettyTime.registerUnit(minutoj, new ResourcesTimeFormat(minutoj)); Assert.assertEquals("40 minutoj", - 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 - public void testCalculatePreciseDuration() { + public void testCalculatePreciseDuration() + { PrettyTime prettyTime = new PrettyTime(); prettyTime.clearUnits(); Minute minutoj = new Minute(); prettyTime.registerUnit(minutoj, new ResourcesTimeFormat(minutoj)); Assert.assertEquals("antaŭ 41 minutoj", - 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 - public void testCalculatePreciseDurationUnrounded() { + public void testCalculatePreciseDurationUnrounded() + { PrettyTime prettyTime = new PrettyTime(); prettyTime.clearUnits(); Minute minutoj = new Minute(); prettyTime.registerUnit(minutoj, new ResourcesTimeFormat(minutoj)); Assert.assertEquals("antaŭ 40 minutoj", - 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 - public void tearDown() throws Exception { + public void tearDown() throws Exception + { Locale.setDefault(locale); } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_ET_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_ET_Test.java index 0e3a092d..730229c8 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_ET_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_ET_Test.java @@ -9,13 +9,10 @@ import org.junit.Before; import org.junit.Test; -import org.ocpsoft.prettytime.Duration; -import org.ocpsoft.prettytime.PrettyTime; -import org.ocpsoft.prettytime.TimeFormat; -import org.ocpsoft.prettytime.TimeUnit; import org.ocpsoft.prettytime.units.JustNow; -public class PrettyTimeI18n_ET_Test { +public class PrettyTimeI18n_ET_Test +{ private Locale locale; @Before @@ -23,21 +20,21 @@ public void setUp() throws Exception { locale = new Locale("et"); } - - private PrettyTime newPrettyTimeWOJustNow(Date ref, Locale locale) + + private PrettyTime newPrettyTimeWOJustNow(Date ref, Locale locale) { PrettyTime t = new PrettyTime(ref, locale); List units = t.getUnits(); List formats = new ArrayList(); for (TimeUnit timeUnit : units) { - if(!(timeUnit instanceof JustNow)) { + if (!(timeUnit instanceof JustNow)) { formats.add(t.getFormat(timeUnit)); } } int index = 0; t.clearUnits(); for (TimeUnit timeUnit : units) { - if(!(timeUnit instanceof JustNow)) { + if (!(timeUnit instanceof JustNow)) { t.registerUnit(timeUnit, formats.get(index)); index++; } @@ -45,7 +42,6 @@ private PrettyTime newPrettyTimeWOJustNow(Date ref, Locale locale) return t; } - @Test public void testRightNow() throws Exception { @@ -59,7 +55,7 @@ public void testMomentsAgo() throws Exception PrettyTime t = new PrettyTime(new Date(6000), locale); assertEquals("hetk tagasi", t.format(new Date(0))); } - + @Test public void testMilliSecondsFromNow() throws Exception { @@ -87,7 +83,7 @@ public void testMilliSecondAgo() throws Exception PrettyTime t = newPrettyTimeWOJustNow(new Date(1), locale); assertEquals("millisekund tagasi", t.format(new Date(0))); } - + @Test public void testSecondsFromNow() throws Exception { @@ -106,13 +102,13 @@ public void testSecondsAgo() throws Exception public void testSecondFromNow() throws Exception { PrettyTime t = newPrettyTimeWOJustNow(new Date(0), locale); - assertEquals("sekundi pärast", t.format(new Date(1000 * 1))); + assertEquals("sekundi pärast", t.format(new Date(1000 * 1))); } @Test public void testSecondAgo() throws Exception { - PrettyTime t = newPrettyTimeWOJustNow(new Date(1000 * 1), locale); + PrettyTime t = newPrettyTimeWOJustNow(new Date(1000 * 1), locale); assertEquals("sekund tagasi", t.format(new Date(0))); } @@ -120,7 +116,7 @@ public void testSecondAgo() throws Exception public void testMinutesFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("13 minuti pärast", t.format(new Date(1000 * 60 * 13))); + assertEquals("13 minuti pärast", t.format(new Date(1000 * 60 * 13))); } @Test @@ -381,9 +377,8 @@ public void testFormattingDurationListInTheFuture() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); List durations = t.calculatePreciseDuration(new Date(1000 * 60 * 60 * 24 * 3 + 1000 * 60 * 60 * 15 - + 1000 * 60 * 38)); + + 1000 * 60 * 38)); assertEquals("3 päeva 15 tunni 38 minuti pärast", t.format(durations)); } - } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_FI_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_FI_Test.java index a3395909..53fe3941 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_FI_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_FI_Test.java @@ -14,6 +14,7 @@ * limitations under the License. */ package org.ocpsoft.prettytime; + import static org.junit.Assert.assertEquals; import java.util.ArrayList; @@ -23,13 +24,10 @@ import org.junit.Before; import org.junit.Test; -import org.ocpsoft.prettytime.Duration; -import org.ocpsoft.prettytime.PrettyTime; -import org.ocpsoft.prettytime.TimeFormat; -import org.ocpsoft.prettytime.TimeUnit; import org.ocpsoft.prettytime.units.JustNow; -public class PrettyTimeI18n_FI_Test { +public class PrettyTimeI18n_FI_Test +{ private Locale locale; @Before @@ -37,21 +35,21 @@ public void setUp() throws Exception { locale = new Locale("fi"); } - - private PrettyTime newPrettyTimeWOJustNow(Date ref, Locale locale) + + private PrettyTime newPrettyTimeWOJustNow(Date ref, Locale locale) { PrettyTime t = new PrettyTime(ref, locale); List units = t.getUnits(); List formats = new ArrayList(); for (TimeUnit timeUnit : units) { - if(!(timeUnit instanceof JustNow)) { + if (!(timeUnit instanceof JustNow)) { formats.add(t.getFormat(timeUnit)); } } int index = 0; t.clearUnits(); for (TimeUnit timeUnit : units) { - if(!(timeUnit instanceof JustNow)) { + if (!(timeUnit instanceof JustNow)) { t.registerUnit(timeUnit, formats.get(index)); index++; } @@ -72,7 +70,7 @@ public void testMomentsAgo() throws Exception PrettyTime t = new PrettyTime(new Date(6000), locale); assertEquals("hetki sitten", t.format(new Date(0))); } - + @Test public void testMilliSecondsFromNow() throws Exception { @@ -100,7 +98,7 @@ public void testMilliSecondAgo() throws Exception PrettyTime t = newPrettyTimeWOJustNow(new Date(1), locale); assertEquals("millisekunti sitten", t.format(new Date(0))); } - + @Test public void testSecondsFromNow() throws Exception { @@ -119,13 +117,13 @@ public void testSecondsAgo() throws Exception public void testSecondFromNow() throws Exception { PrettyTime t = newPrettyTimeWOJustNow(new Date(0), locale); - assertEquals("sekunnin päästä", t.format(new Date(1000 * 1))); + assertEquals("sekunnin päästä", t.format(new Date(1000 * 1))); } @Test public void testSecondAgo() throws Exception { - PrettyTime t = newPrettyTimeWOJustNow(new Date(1000 * 1), locale); + PrettyTime t = newPrettyTimeWOJustNow(new Date(1000 * 1), locale); assertEquals("sekunti sitten", t.format(new Date(0))); } @@ -133,7 +131,7 @@ public void testSecondAgo() throws Exception public void testMinutesFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("13 minuutin päästä", t.format(new Date(1000 * 60 * 13))); + assertEquals("13 minuutin päästä", t.format(new Date(1000 * 60 * 13))); } @Test @@ -196,9 +194,9 @@ public void testDaysFromNow() throws Exception public void testNear2DaysAgo() throws Exception { int hour = 1000 * 60 * 60; - PrettyTime t = new PrettyTime(new Date(hour * 24 * 2 - 11*hour), locale); + PrettyTime t = new PrettyTime(new Date(hour * 24 * 2 - 11 * hour), locale); assertEquals("2 päivää sitten", t.format(new Date(0))); - t = new PrettyTime(new Date(hour * 24 * 2 - 13*hour), locale); + t = new PrettyTime(new Date(hour * 24 * 2 - 13 * hour), locale); assertEquals("eilen", t.format(new Date(0))); } @@ -404,9 +402,8 @@ public void testFormattingDurationListInTheFuture() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); List durations = t.calculatePreciseDuration(new Date(1000 * 60 * 60 * 24 * 3 + 1000 * 60 * 60 * 15 - + 1000 * 60 * 38)); + + 1000 * 60 * 38)); assertEquals("3 päivän 15 tunnin 38 minuutin päästä", t.format(durations)); } - } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_FR_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_FR_Test.java index 2fd3c403..be41fad0 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_FR_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_FR_Test.java @@ -24,7 +24,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.ocpsoft.prettytime.PrettyTime; /** * All the tests for PrettyTime. @@ -79,8 +78,7 @@ public void testPrettyTimeFRENCHLocale() { long t = 1L; PrettyTime p = new PrettyTime(new Date(0), Locale.FRENCH); - while (1000L * 60L * 60L * 24L * 365L * 1000000L > t) - { + while (1000L * 60L * 60L * 24L * 365L * 1000000L > t) { assertTrue(p.format(new Date(0)).startsWith("dans") || p.format(new Date(0)).startsWith("à l'instant")); t *= 2L; } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_IT_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_IT_Test.java index 03d4d8c3..3490d1f7 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_IT_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_IT_Test.java @@ -14,6 +14,7 @@ * limitations under the License. */ package org.ocpsoft.prettytime; + import static org.junit.Assert.assertEquals; import java.util.ArrayList; @@ -23,13 +24,10 @@ import org.junit.Before; import org.junit.Test; -import org.ocpsoft.prettytime.Duration; -import org.ocpsoft.prettytime.PrettyTime; -import org.ocpsoft.prettytime.TimeFormat; -import org.ocpsoft.prettytime.TimeUnit; import org.ocpsoft.prettytime.units.JustNow; -public class PrettyTimeI18n_IT_Test { +public class PrettyTimeI18n_IT_Test +{ private Locale locale; @Before @@ -37,21 +35,21 @@ public void setUp() throws Exception { locale = new Locale("it"); } - - private PrettyTime newPrettyTimeWOJustNow(Date ref, Locale locale) + + private PrettyTime newPrettyTimeWOJustNow(Date ref, Locale locale) { PrettyTime t = new PrettyTime(ref, locale); List units = t.getUnits(); List formats = new ArrayList(); for (TimeUnit timeUnit : units) { - if(!(timeUnit instanceof JustNow)) { + if (!(timeUnit instanceof JustNow)) { formats.add(t.getFormat(timeUnit)); } } int index = 0; t.clearUnits(); for (TimeUnit timeUnit : units) { - if(!(timeUnit instanceof JustNow)) { + if (!(timeUnit instanceof JustNow)) { t.registerUnit(timeUnit, formats.get(index)); index++; } @@ -59,7 +57,6 @@ private PrettyTime newPrettyTimeWOJustNow(Date ref, Locale locale) return t; } - @Test public void testRightNow() throws Exception { @@ -73,7 +70,7 @@ public void testMomentsAgo() throws Exception PrettyTime t = new PrettyTime(new Date(6000), locale); assertEquals("poco fa", t.format(new Date(0))); } - + @Test public void testMilliSecondsFromNow() throws Exception { @@ -101,7 +98,7 @@ public void testMilliSecondAgo() throws Exception PrettyTime t = newPrettyTimeWOJustNow(new Date(1), locale); assertEquals("1 millisecondo fa", t.format(new Date(0))); } - + @Test public void testSecondsFromNow() throws Exception { @@ -120,13 +117,13 @@ public void testSecondsAgo() throws Exception public void testSecondFromNow() throws Exception { PrettyTime t = newPrettyTimeWOJustNow(new Date(0), locale); - assertEquals("fra 1 secondo", t.format(new Date(1000 * 1))); + assertEquals("fra 1 secondo", t.format(new Date(1000 * 1))); } @Test public void testSecondAgo() throws Exception { - PrettyTime t = newPrettyTimeWOJustNow(new Date(1000 * 1), locale); + PrettyTime t = newPrettyTimeWOJustNow(new Date(1000 * 1), locale); assertEquals("1 secondo fa", t.format(new Date(0))); } @@ -134,7 +131,7 @@ public void testSecondAgo() throws Exception public void testMinutesFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); - assertEquals("fra 13 minuti", t.format(new Date(1000 * 60 * 13))); + assertEquals("fra 13 minuti", t.format(new Date(1000 * 60 * 13))); } @Test @@ -395,9 +392,8 @@ public void testFormattingDurationListInTheFuture() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); List durations = t.calculatePreciseDuration(new Date(1000 * 60 * 60 * 24 * 3 + 1000 * 60 * 60 * 15 - + 1000 * 60 * 38)); + + 1000 * 60 * 38)); assertEquals("fra 3 giorni 15 ore 38 minuti", t.format(durations)); } - } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_TH_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_TH_Test.java index 387ee9bf..68a85b2f 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_TH_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_TH_Test.java @@ -1,15 +1,14 @@ package org.ocpsoft.prettytime; -import org.junit.After; -import org.junit.Assert; -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_TH_Test { @@ -71,7 +70,7 @@ public void testDaysFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); assertEquals("3 วัน ต่อจากนี้ี้", - t.format(new Date(1000 * 60 * 60 * 24 * 3))); + t.format(new Date(1000 * 60 * 60 * 24 * 3))); } @Test @@ -79,7 +78,7 @@ public void testWeeksFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); assertEquals("3 อาทิตย์ ต่อจากนี้ี้", - t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); + t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); } @Test @@ -94,7 +93,7 @@ public void testCenturiesFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); assertEquals("3 ศตวรรษ ต่อจากนี้", - t.format(new Date(3155692597470L * 3L))); + t.format(new Date(3155692597470L * 3L))); } /* diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_Test.java index a7d9fcb8..301bda06 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_Test.java @@ -17,13 +17,13 @@ import static org.junit.Assert.assertEquals; +import java.time.LocalDateTime; import java.util.Date; import java.util.Locale; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.ocpsoft.prettytime.PrettyTime; /** * All the tests for PrettyTime. @@ -71,7 +71,7 @@ public void testPrettyTimeSpanish() { // The Spanish resource bundle should be used PrettyTime p = new PrettyTime(new Locale("es")); - assertEquals("hace un instante", p.format(new Date())); + assertEquals("hace instantes", p.format(LocalDateTime.now().minusSeconds(1))); } @Test @@ -131,8 +131,7 @@ public void testPrettyTimeRootLocale() { long t = 1L; PrettyTime p = new PrettyTime(new Date(0), Locale.ROOT); - while (1000L * 60L * 60L * 24L * 365L * 1000000L > t) - { + while (1000L * 60L * 60L * 24L * 365L * 1000000L > t) { assertEquals(p.format(new Date(0)).endsWith("now"), true); t *= 2L; } @@ -143,8 +142,7 @@ public void testPrettyTimeGermanLocale() { long t = 1L; PrettyTime p = new PrettyTime(new Date(0), Locale.GERMAN); - while (1000L * 60L * 60L * 24L * 365L * 1000000L > t) - { + while (1000L * 60L * 60L * 24L * 365L * 1000000L > t) { assertEquals(p.format(new Date(0)).startsWith("in") || p.format(new Date(0)).startsWith("Jetzt"), true); t *= 2L; } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_sq_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_sq_Test.java index d09e597a..f726ad58 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_sq_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_sq_Test.java @@ -41,7 +41,7 @@ public void setUp() throws Exception public void testPrettyTime() { PrettyTime p = new PrettyTime(locale); - assertEquals("tani", p.format(new Date())); + assertEquals("momente nga tani", p.format(new Date())); } @Test @@ -51,7 +51,7 @@ public void testPrettyTimeCenturies() assertEquals("3 shekuj më parë", p.format(new Date(0))); p = new PrettyTime(new Date(0), locale); - assertEquals("3 shekuj më vonë", p.format(new Date(3155692597470L * 3L))); + assertEquals("3 shekuj nga tani", p.format(new Date(3155692597470L * 3L))); } @Test diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeLocaleFallbackTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeLocaleFallbackTest.java index fb3f94e7..8ca210d5 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeLocaleFallbackTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeLocaleFallbackTest.java @@ -24,7 +24,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.ocpsoft.prettytime.PrettyTime; public class PrettyTimeLocaleFallbackTest { diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java index c85c2300..7b188147 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java @@ -15,11 +15,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.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; @@ -28,6 +23,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 PrettyTimeTest { private Locale locale; @@ -85,9 +89,9 @@ 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 millennium 9 centuries 4 decades 4 years 8 months 1 week 6 days 14 hours 5 minutes ago", + Assert.assertEquals("1 millennium 9 centuries 4 decades 4 years 8 months 1 week 6 days 20 hours 5 minutes ago", t.format(durations)); - Assert.assertEquals("1 millennium 9 centuries 4 decades 4 years 8 months 1 week 6 days 14 hours 5 minutes", + Assert.assertEquals("1 millennium 9 centuries 4 decades 4 years 8 months 1 week 6 days 20 hours 5 minutes", t.formatDuration(durations)); } @@ -99,7 +103,7 @@ public void testCalculatePreciseDuration2() Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("40 minutes ago", prettyTime.formatUnrounded(prettyTime - .calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); + .calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); } @Test @@ -228,8 +232,7 @@ public void testMonthsAgo() throws Exception public void testCustomFormat() throws Exception { PrettyTime t = new PrettyTime(now); - TimeUnit unit = new TimeUnit() - { + TimeUnit unit = new TimeUnit() { @Override public long getMaxQuantity() { @@ -441,7 +444,7 @@ public void testFormatDurationListUnrounded() throws Exception prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); Assert.assertEquals("40 minutes", prettyTime.formatDurationUnrounded(prettyTime.calculatePreciseDuration( - now.minusMinutes(40).minusSeconds(40)))); + now.minusMinutes(40).minusSeconds(40)))); } @Test diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java index 65df20c2..8f36c24e 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java @@ -16,21 +16,15 @@ package org.ocpsoft.prettytime; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; 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; import org.junit.Test; -import org.ocpsoft.prettytime.Duration; -import org.ocpsoft.prettytime.PrettyTime; -import org.ocpsoft.prettytime.TimeUnit; -import org.ocpsoft.prettytime.format.SimpleTimeFormat; import org.ocpsoft.prettytime.units.Hour; import org.ocpsoft.prettytime.units.JustNow; import org.ocpsoft.prettytime.units.Minute; diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimel18n_MM_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimel18n_MM_Test.java index 7bcdb3d6..189154ac 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimel18n_MM_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimel18n_MM_Test.java @@ -1,21 +1,21 @@ package org.ocpsoft.prettytime; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import static org.junit.Assert.assertEquals; import java.util.Date; import java.util.List; import java.util.Locale; -import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; /** * Created by vincentpaing on 5/17/17. */ -public class PrettyTimel18n_MM_Test { +public class PrettyTimel18n_MM_Test +{ - /* + /* * A note when you want to use the YourKit profiler: To use the YourKit * profiler (http://yourkit.com), run with VM argument for profiling: * -agentlib:yjpagent=onexit=snapshot,tracing @@ -26,26 +26,30 @@ public class PrettyTimel18n_MM_Test { // Method setUp() is called automatically before every test method @Before - public void setUp() throws Exception { + public void setUp() throws Exception + { locale = new Locale("MM"); Locale.setDefault(locale); } @Test - public void testNullDate() throws Exception { + public void testNullDate() throws Exception + { PrettyTime t = new PrettyTime(); Date date = null; assertEquals("ခေတ္တ မကြာမီ", t.format(date)); } @Test - public void testRightNow() throws Exception { + public void testRightNow() throws Exception + { PrettyTime t = new PrettyTime(); assertEquals("ခေတ္တ မကြာမီ", t.format(new Date())); } @Test - public void testMinutes() throws Exception { + public void testMinutes() throws Exception + { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale); assertEquals("12 မိနစ် အကြာက", t.format(new Date(0))); @@ -54,7 +58,8 @@ public void testMinutes() throws Exception { } @Test - public void testHours() throws Exception { + public void testHours() throws Exception + { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 5), locale); assertEquals("5 နာရီ အကြာက", t.format(new Date(0))); @@ -63,7 +68,8 @@ public void testHours() throws Exception { } @Test - public void testDays() throws Exception { + public void testDays() throws Exception + { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale); assertEquals("3 ရက် အကြာက", t.format(new Date(0))); @@ -72,7 +78,8 @@ public void testDays() throws Exception { } @Test - public void testWeeks() throws Exception { + public void testWeeks() throws Exception + { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 2), locale); assertEquals("2 ရက်သတ္တပတ် အကြာက", t.format(new Date(0))); @@ -81,7 +88,8 @@ public void testWeeks() throws Exception { } @Test - public void testMonths() throws Exception { + public void testMonths() throws Exception + { PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale); assertEquals("3 လ အကြာက", t.format(new Date(0))); @@ -90,7 +98,8 @@ public void testMonths() throws Exception { } @Test - public void testYears() throws Exception { + public void testYears() throws Exception + { PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale); assertEquals("3 နှစ် အကြာက", t.format(new Date(0))); @@ -99,7 +108,8 @@ public void testYears() throws Exception { } @Test - public void testDecades() throws Exception { + public void testDecades() throws Exception + { PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale); assertEquals("ဆယ်စုနှစ် 3 နှစ်အကြာက", t.format(new Date(0))); @@ -108,7 +118,8 @@ public void testDecades() throws Exception { } @Test - public void testCenturies() throws Exception { + public void testCenturies() throws Exception + { PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale); assertEquals("3 ရာစု အကြာက", t.format(new Date(0))); @@ -117,7 +128,8 @@ public void testCenturies() throws Exception { } @Test - public void testCentury() throws Exception { + public void testCentury() throws Exception + { PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale); assertEquals("3 ရာစု အကြာက", t.format(new Date(0))); @@ -126,14 +138,15 @@ public void testCentury() throws Exception { } @Test - public void testFormattingDurationList() throws Exception { + public void testFormattingDurationList() throws Exception + { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3 + 1000 * 60 * 60 * 15 + 1000 * 60 * 38)); List durations = t.calculatePreciseDuration(new Date(0)); assertEquals("3 ရက် 15 နာရီ 38 မိနစ် အကြာက", t.format(durations)); t = new PrettyTime(new Date(0)); durations = t.calculatePreciseDuration(new Date(1000 * 60 * 60 * 24 * 3 + 1000 * 60 * 60 * 15 - + 1000 * 60 * 38)); + + 1000 * 60 * 38)); assertEquals("ယခုမှ 3 ရက် 15 နာရီ 38 မိနစ် အကြာ", t.format(durations)); } } diff --git a/core/src/test/java/org/ocpsoft/prettytime/SimpleTimeFormatTest.java b/core/src/test/java/org/ocpsoft/prettytime/SimpleTimeFormatTest.java index d0a374ff..c80d7f0e 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/SimpleTimeFormatTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/SimpleTimeFormatTest.java @@ -17,16 +17,13 @@ import static org.junit.Assert.assertEquals; -import java.time.*; +import java.time.Instant; import java.util.Date; import java.util.Locale; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.ocpsoft.prettytime.Duration; -import org.ocpsoft.prettytime.PrettyTime; -import org.ocpsoft.prettytime.TimeFormat; import org.ocpsoft.prettytime.format.SimpleTimeFormat; public class SimpleTimeFormatTest diff --git a/pom.xml b/pom.xml index 90924f57..06c9a0b4 100644 --- a/pom.xml +++ b/pom.xml @@ -22,10 +22,12 @@ jsf jstl nlp - samples - + samples + + 1.8 + 1.8 UTF-8 @@ -46,8 +48,8 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD - + HEAD + GitHub @@ -66,62 +68,77 @@ Thomas Weitzel tweitzel@synformation.com + + Isira-Seneviratne + Isira Seneviratne + https://github.com/Isira-Seneviratne + +5 + - - - - org.ocpsoft.prettytime - prettytime - ${project.version} - - - org.ocpsoft.prettytime - prettytime-integration-jsf - ${project.version} - + + + + org.ocpsoft.prettytime + prettytime + ${project.version} + + + org.ocpsoft.prettytime + prettytime-integration-jsf + ${project.version} + - - javax.faces - jsf-api - 1.2_02 - provided - - - junit - junit - 4.5 - test - - + + javax.faces + jsf-api + 1.2_02 + provided + + + junit + junit + 4.5 + test + + org.apache.felix maven-bundle-plugin 2.5.3 - - + + - - - - org.apache.maven.plugins - maven-shade-plugin - 2.4.2 - - - org.apache.maven.plugins - maven-release-plugin - 2.5.3 - - true - true - @{project.version} - false - - dependency-reduced-pom.xml - - - - - + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-shade-plugin + 2.4.2 + + + org.apache.maven.plugins + maven-release-plugin + 2.5.3 + + true + true + @{project.version} + false + + dependency-reduced-pom.xml + + + + + diff --git a/samples/jstl/src/main/java/org/ocpsoft/prettytime/samples/jstl/IndexServlet.java b/samples/jstl/src/main/java/org/ocpsoft/prettytime/samples/jstl/IndexServlet.java index 528e0bb0..fa531a44 100644 --- a/samples/jstl/src/main/java/org/ocpsoft/prettytime/samples/jstl/IndexServlet.java +++ b/samples/jstl/src/main/java/org/ocpsoft/prettytime/samples/jstl/IndexServlet.java @@ -1,15 +1,20 @@ package org.ocpsoft.prettytime.samples.jstl; +import java.io.IOException; +import java.util.Date; + import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.Date; -public class IndexServlet extends HttpServlet { +public class IndexServlet extends HttpServlet +{ + + private static final long serialVersionUID = 3698098463023956514L; - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { request.setAttribute("myDate", new Date()); request.getRequestDispatcher("/WEB-INF/index.jsp").forward(request, response); } From 3ed6efe44374fa9b3e1203a948a72ab5ca6ed40a Mon Sep 17 00:00:00 2001 From: Michael <3533648+hertg@users.noreply.github.com> Date: Tue, 29 Sep 2020 23:43:43 +0200 Subject: [PATCH 055/147] fix grammatical case for duration in german, updated tests --- .../prettytime/format/SimpleTimeFormat.java | 23 +- .../ocpsoft/prettytime/i18n/Resources_de.java | 256 +++++++++++------- .../prettytime/PrettyTimeI18n_DE_Test.java | 169 ++++++++++++ 3 files changed, 335 insertions(+), 113 deletions(-) create mode 100644 core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_DE_Test.java diff --git a/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java b/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java index f8841373..3575d84b 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java +++ b/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java @@ -15,12 +15,12 @@ */ package org.ocpsoft.prettytime.format; +import java.util.regex.Pattern; + import org.ocpsoft.prettytime.Duration; import org.ocpsoft.prettytime.TimeFormat; import org.ocpsoft.prettytime.TimeUnit; -import java.util.regex.Pattern; - /** * Represents a simple method of formatting a specific {@link Duration} of time * @@ -32,7 +32,7 @@ public class SimpleTimeFormat implements TimeFormat public static final String SIGN = "%s"; public static final String QUANTITY = "%n"; public static final String UNIT = "%u"; - + private static final Pattern PATTERN_MULTIPLE_WHITESPACES = Pattern.compile("\\s{2,}"); private String singularName = ""; @@ -65,12 +65,10 @@ public String formatUnrounded(Duration duration) public String decorate(Duration duration, String time) { StringBuilder result = new StringBuilder(); - if (duration.isInPast()) - { + if (duration.isInPast()) { result.append(pastPrefix).append(" ").append(time).append(" ").append(pastSuffix); } - else - { + else { result.append(futurePrefix).append(" ").append(time).append(" ").append(futureSuffix); } return PATTERN_MULTIPLE_WHITESPACES.matcher(result).replaceAll(" ").trim(); @@ -118,17 +116,20 @@ protected long getQuantity(Duration duration, boolean round) protected String getGramaticallyCorrectName(final Duration d, boolean round) { String result = getSingularName(d); - if ((Math.abs(getQuantity(d, round)) == 0) || (Math.abs(getQuantity(d, round)) > 1)) - { + if (isPlural(d, round)) { result = getPluralName(d); } return result; } + protected boolean isPlural(final Duration d, boolean round) + { + return (Math.abs(getQuantity(d, round)) == 0) || (Math.abs(getQuantity(d, round)) > 1); + } + private String getSign(final Duration d) { - if (d.getQuantity() < 0) - { + if (d.getQuantity() < 0) { return NEGATIVE; } return ""; diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_de.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_de.java index 2ae2c7fb..d123c823 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_de.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_de.java @@ -1,12 +1,12 @@ /* * Copyright 2012 Lincoln Baxter, III - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,108 +16,160 @@ package org.ocpsoft.prettytime.i18n; import java.util.ListResourceBundle; +import java.util.ResourceBundle; -public class Resources_de extends ListResourceBundle +import org.ocpsoft.prettytime.Duration; +import org.ocpsoft.prettytime.TimeFormat; +import org.ocpsoft.prettytime.TimeUnit; +import org.ocpsoft.prettytime.format.SimpleTimeFormat; +import org.ocpsoft.prettytime.impl.TimeFormatProvider; + +public class Resources_de extends ListResourceBundle implements TimeFormatProvider { - private static final Object[][] OBJECTS = new Object[][] { - { "CenturyPattern", "%n %u" }, - { "CenturyFuturePrefix", "in " }, - { "CenturyFutureSuffix", "" }, - { "CenturyPastPrefix", "vor " }, - { "CenturyPastSuffix", "" }, - { "CenturySingularName", "Jahrhundert" }, - { "CenturyPluralName", "Jahrhunderten" }, - { "DayPattern", "%n %u" }, - { "DayFuturePrefix", "in " }, - { "DayFutureSuffix", "" }, - { "DayPastPrefix", "vor " }, - { "DayPastSuffix", "" }, - { "DaySingularName", "Tag" }, - { "DayPluralName", "Tagen" }, - { "DecadePattern", "%n %u" }, - { "DecadeFuturePrefix", "in " }, - { "DecadeFutureSuffix", "" }, - { "DecadePastPrefix", "vor " }, - { "DecadePastSuffix", "" }, - { "DecadeSingularName", "Jahrzehnt" }, - { "DecadePluralName", "Jahrzehnten" }, - { "HourPattern", "%n %u" }, - { "HourFuturePrefix", "in " }, - { "HourFutureSuffix", "" }, - { "HourPastPrefix", "vor " }, - { "HourPastSuffix", "" }, - { "HourSingularName", "Stunde" }, - { "HourPluralName", "Stunden" }, - { "JustNowPattern", "%u" }, - { "JustNowFuturePrefix", "Jetzt" }, - { "JustNowFutureSuffix", "" }, - { "JustNowPastPrefix", "gerade eben" }, - { "JustNowPastSuffix", "" }, - { "JustNowSingularName", "" }, - { "JustNowPluralName", "" }, - { "MillenniumPattern", "%n %u" }, - { "MillenniumFuturePrefix", "in " }, - { "MillenniumFutureSuffix", "" }, - { "MillenniumPastPrefix", "vor " }, - { "MillenniumPastSuffix", "" }, - { "MillenniumSingularName", "Jahrtausend" }, - { "MillenniumPluralName", "Jahrtausenden" }, - { "MillisecondPattern", "%n %u" }, - { "MillisecondFuturePrefix", "in " }, - { "MillisecondFutureSuffix", "" }, - { "MillisecondPastPrefix", "vor " }, - { "MillisecondPastSuffix", "" }, - { "MillisecondSingularName", "Millisekunde" }, - { "MillisecondPluralName", "Millisekunden" }, - { "MinutePattern", "%n %u" }, - { "MinuteFuturePrefix", "in " }, - { "MinuteFutureSuffix", "" }, - { "MinutePastPrefix", "vor " }, - { "MinutePastSuffix", "" }, - { "MinuteSingularName", "Minute" }, - { "MinutePluralName", "Minuten" }, - { "MonthPattern", "%n %u" }, - { "MonthFuturePrefix", "in " }, - { "MonthFutureSuffix", "" }, - { "MonthPastPrefix", "vor " }, - { "MonthPastSuffix", "" }, - { "MonthSingularName", "Monat" }, - { "MonthPluralName", "Monaten" }, - { "SecondPattern", "%n %u" }, - { "SecondFuturePrefix", "in " }, - { "SecondFutureSuffix", "" }, - { "SecondPastPrefix", "vor " }, - { "SecondPastSuffix", "" }, - { "SecondSingularName", "Sekunde" }, - { "SecondPluralName", "Sekunden" }, - { "WeekPattern", "%n %u" }, - { "WeekFuturePrefix", "in " }, - { "WeekFutureSuffix", "" }, - { "WeekPastPrefix", "vor " }, - { "WeekPastSuffix", "" }, - { "WeekSingularName", "Woche" }, - { "WeekPluralName", "Wochen" }, - { "YearPattern", "%n %u" }, - { "YearFuturePrefix", "in " }, - { "YearFutureSuffix", "" }, - { "YearPastPrefix", "vor " }, - { "YearPastSuffix", "" }, - { "YearSingularName", "Jahr" }, - { "YearPluralName", "Jahren" }, - { "AbstractTimeUnitPattern", "" }, - { "AbstractTimeUnitFuturePrefix", "" }, - { "AbstractTimeUnitFutureSuffix", "" }, - { "AbstractTimeUnitPastPrefix", "" }, - { "AbstractTimeUnitPastSuffix", "" }, - { "AbstractTimeUnitSingularName", "" }, - { "AbstractTimeUnitPluralName", "" } + private static final Object[][] OBJECTS = new Object[][] { + { "CenturyPattern", "%n %u" }, + { "CenturyFuturePrefix", "in " }, + { "CenturyFutureSuffix", "" }, + { "CenturyPastPrefix", "vor " }, + { "CenturyPastSuffix", "" }, + { "CenturySingularName", "Jahrhundert" }, + { "CenturyPluralName", "Jahrhunderte" }, + { "DayPattern", "%n %u" }, + { "DayFuturePrefix", "in " }, + { "DayFutureSuffix", "" }, + { "DayPastPrefix", "vor " }, + { "DayPastSuffix", "" }, + { "DaySingularName", "Tag" }, + { "DayPluralName", "Tage" }, + { "DecadePattern", "%n %u" }, + { "DecadeFuturePrefix", "in " }, + { "DecadeFutureSuffix", "" }, + { "DecadePastPrefix", "vor " }, + { "DecadePastSuffix", "" }, + { "DecadeSingularName", "Jahrzehnt" }, + { "DecadePluralName", "Jahrzehnte" }, + { "HourPattern", "%n %u" }, + { "HourFuturePrefix", "in " }, + { "HourFutureSuffix", "" }, + { "HourPastPrefix", "vor " }, + { "HourPastSuffix", "" }, + { "HourSingularName", "Stunde" }, + { "HourPluralName", "Stunden" }, + { "JustNowPattern", "%u" }, + { "JustNowFuturePrefix", "Jetzt" }, + { "JustNowFutureSuffix", "" }, + { "JustNowPastPrefix", "gerade eben" }, + { "JustNowPastSuffix", "" }, + { "JustNowSingularName", "" }, + { "JustNowPluralName", "" }, + { "MillenniumPattern", "%n %u" }, + { "MillenniumFuturePrefix", "in " }, + { "MillenniumFutureSuffix", "" }, + { "MillenniumPastPrefix", "vor " }, + { "MillenniumPastSuffix", "" }, + { "MillenniumSingularName", "Jahrtausend" }, + { "MillenniumPluralName", "Jahrtausende" }, + { "MillisecondPattern", "%n %u" }, + { "MillisecondFuturePrefix", "in " }, + { "MillisecondFutureSuffix", "" }, + { "MillisecondPastPrefix", "vor " }, + { "MillisecondPastSuffix", "" }, + { "MillisecondSingularName", "Millisekunde" }, + { "MillisecondPluralName", "Millisekunden" }, + { "MinutePattern", "%n %u" }, + { "MinuteFuturePrefix", "in " }, + { "MinuteFutureSuffix", "" }, + { "MinutePastPrefix", "vor " }, + { "MinutePastSuffix", "" }, + { "MinuteSingularName", "Minute" }, + { "MinutePluralName", "Minuten" }, + { "MonthPattern", "%n %u" }, + { "MonthFuturePrefix", "in " }, + { "MonthFutureSuffix", "" }, + { "MonthPastPrefix", "vor " }, + { "MonthPastSuffix", "" }, + { "MonthSingularName", "Monat" }, + { "MonthPluralName", "Monate" }, + { "SecondPattern", "%n %u" }, + { "SecondFuturePrefix", "in " }, + { "SecondFutureSuffix", "" }, + { "SecondPastPrefix", "vor " }, + { "SecondPastSuffix", "" }, + { "SecondSingularName", "Sekunde" }, + { "SecondPluralName", "Sekunden" }, + { "WeekPattern", "%n %u" }, + { "WeekFuturePrefix", "in " }, + { "WeekFutureSuffix", "" }, + { "WeekPastPrefix", "vor " }, + { "WeekPastSuffix", "" }, + { "WeekSingularName", "Woche" }, + { "WeekPluralName", "Wochen" }, + { "YearPattern", "%n %u" }, + { "YearFuturePrefix", "in " }, + { "YearFutureSuffix", "" }, + { "YearPastPrefix", "vor " }, + { "YearPastSuffix", "" }, + { "YearSingularName", "Jahr" }, + { "YearPluralName", "Jahre" }, + { "AbstractTimeUnitPattern", "" }, + { "AbstractTimeUnitFuturePrefix", "" }, + { "AbstractTimeUnitFutureSuffix", "" }, + { "AbstractTimeUnitPastPrefix", "" }, + { "AbstractTimeUnitPastSuffix", "" }, + { "AbstractTimeUnitSingularName", "" }, + { "AbstractTimeUnitPluralName", "" } + + }; + + @Override + protected Object[][] getContents() + { + return OBJECTS; + } + + @Override + public TimeFormat getFormatFor(TimeUnit t) + { + return new DeTimeFormat(this, t, t.getClass().getSimpleName()); + } + + private static class DeTimeFormat extends SimpleTimeFormat + { + + public DeTimeFormat(final ResourceBundle bundle, final TimeUnit unit, String prefix) + { + setPattern(bundle.getString(prefix + "Pattern")); + setFuturePrefix(bundle.getString(prefix + "FuturePrefix")); + setFutureSuffix(bundle.getString(prefix + "FutureSuffix")); + setPastPrefix(bundle.getString(prefix + "PastPrefix")); + setPastSuffix(bundle.getString(prefix + "PastSuffix")); + setSingularName(bundle.getString(prefix + "SingularName")); + setPluralName(bundle.getString(prefix + "PluralName")); + } - }; + @Override + public String decorate(Duration duration, String time) + { + // Change the nominative plural to dative by appending an "n" (Tage -> Tagen / Monate -> Monaten) + if (isPlural(duration, true)) { + if (time != null && time.trim().length() > 0 && !time.endsWith("n")) { + time += "n"; + } + } + return super.decorate(duration, time); + } - @Override - protected Object[][] getContents() - { - return OBJECTS; - } + @Override + public String decorateUnrounded(Duration duration, String time) + { + // Change the nominative plural to dative by appending an "n" (Tage -> Tagen / Monate -> Monaten) + if (isPlural(duration, false)) { + if (time != null && time.trim().length() > 0 && !time.endsWith("n")) { + time += "n"; + } + } + return super.decorateUnrounded(duration, time); + } + } } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_DE_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_DE_Test.java new file mode 100644 index 00000000..50a32633 --- /dev/null +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_DE_Test.java @@ -0,0 +1,169 @@ +/** + * @author hertg + */ +package org.ocpsoft.prettytime; + +import static org.junit.Assert.assertEquals; + +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class PrettyTimeI18n_DE_Test +{ + + private Locale locale; + private Date base; + private PrettyTime prettyTime; + + @Before + public void setUp() throws Exception + { + locale = new Locale("de"); + base = new Date(); + prettyTime = new PrettyTime(base, locale); + } + + @Test + public void testGrammaticalCaseMilliseconds() + { + assertEquals("gerade eben", prettyTime.format(addTime(-5, Calendar.MILLISECOND))); + assertEquals("gerade eben", prettyTime.format(addTime(-1, Calendar.MILLISECOND))); + assertEquals("Jetzt", prettyTime.format(addTime(5, Calendar.MILLISECOND))); + assertEquals("Jetzt", prettyTime.format(addTime(1, Calendar.MILLISECOND))); + + // the following tests are commented out, because the formatDuration() method + // only returns an empty string for durations in the milliseconds + // assertEquals("5 Millisekunden", prettyTime.formatDuration(addTime(-5, Calendar.MILLISECOND))); + // assertEquals("1 Millisekunde", prettyTime.formatDuration(addTime(-1, Calendar.MILLISECOND))); + } + + @Test + public void testGrammaticalCaseSeconds() + { + assertEquals("gerade eben", prettyTime.format(addTime(-5, Calendar.SECOND))); + assertEquals("gerade eben", prettyTime.format(addTime(-1, Calendar.SECOND))); + assertEquals("Jetzt", prettyTime.format(addTime(5, Calendar.SECOND))); + assertEquals("Jetzt", prettyTime.format(addTime(1, Calendar.SECOND))); + + // the following tests are commented out, because the formatDuration() method + // only returns an empty string for durations in the seconds + // assertEquals("5 Sekunden", prettyTime.formatDuration(addTime(-5, Calendar.SECOND))); + // assertEquals("1 Sekunde", prettyTime.formatDuration(addTime(-1, Calendar.SECOND))); + } + + @Test + public void testGrammaticalCaseMinutes() + { + assertEquals("vor 5 Minuten", prettyTime.format(addTime(-5, Calendar.MINUTE))); + assertEquals("vor 1 Minute", prettyTime.format(addTime(-1, Calendar.MINUTE))); + assertEquals("in 5 Minuten", prettyTime.format(addTime(5, Calendar.MINUTE))); + assertEquals("in 1 Minute", prettyTime.format(addTime(1, Calendar.MINUTE))); + assertEquals("5 Minuten", prettyTime.formatDuration(addTime(-5, Calendar.MINUTE))); + assertEquals("1 Minute", prettyTime.formatDuration(addTime(-1, Calendar.MINUTE))); + } + + @Test + public void testGrammaticalCaseHours() + { + assertEquals("vor 5 Stunden", prettyTime.format(addTime(-5, Calendar.HOUR))); + assertEquals("vor 1 Stunde", prettyTime.format(addTime(-1, Calendar.HOUR))); + assertEquals("in 5 Stunden", prettyTime.format(addTime(5, Calendar.HOUR))); + assertEquals("in 1 Stunde", prettyTime.format(addTime(1, Calendar.HOUR))); + assertEquals("5 Stunden", prettyTime.formatDuration(addTime(-5, Calendar.HOUR))); + assertEquals("1 Stunde", prettyTime.formatDuration(addTime(-1, Calendar.HOUR))); + } + + @Test + public void testGrammaticalCaseDays() + { + assertEquals("vor 5 Tagen", prettyTime.format(addTime(-5, Calendar.DAY_OF_MONTH))); + assertEquals("vor 1 Tag", prettyTime.format(addTime(-1, Calendar.DAY_OF_MONTH))); + assertEquals("in 5 Tagen", prettyTime.format(addTime(5, Calendar.DAY_OF_MONTH))); + assertEquals("in 1 Tag", prettyTime.format(addTime(1, Calendar.DAY_OF_MONTH))); + assertEquals("5 Tage", prettyTime.formatDuration(addTime(-5, Calendar.DAY_OF_MONTH))); + assertEquals("1 Tag", prettyTime.formatDuration(addTime(-1, Calendar.DAY_OF_MONTH))); + } + + @Test + public void testGrammaticalCaseMonths() + { + assertEquals("vor 5 Monaten", prettyTime.format(addTime(-5, Calendar.MONTH))); + assertEquals("vor 1 Monat", prettyTime.format(addTime(-1, Calendar.MONTH))); + assertEquals("in 5 Monaten", prettyTime.format(addTime(5, Calendar.MONTH))); + assertEquals("in 1 Monat", prettyTime.format(addTime(1, Calendar.MONTH))); + assertEquals("5 Monate", prettyTime.formatDuration(addTime(-5, Calendar.MONTH))); + assertEquals("1 Monat", prettyTime.formatDuration(addTime(-1, Calendar.MONTH))); + } + + @Test + public void testGrammaticalCaseYears() + { + assertEquals("vor 5 Jahren", prettyTime.format(addTime(-5, Calendar.YEAR))); + assertEquals("vor 1 Jahr", prettyTime.format(addTime(-1, Calendar.YEAR))); + assertEquals("in 5 Jahren", prettyTime.format(addTime(5, Calendar.YEAR))); + assertEquals("in 1 Jahr", prettyTime.format(addTime(13, Calendar.MONTH))); + assertEquals("5 Jahre", prettyTime.formatDuration(addTime(-5, Calendar.YEAR))); + assertEquals("1 Jahr", prettyTime.formatDuration(addTime(-1, Calendar.YEAR))); + } + + @Test + public void testGrammaticalCaseDecades() + { + assertEquals("vor 5 Jahrzehnten", prettyTime.format(addTime(-50, Calendar.YEAR))); + assertEquals("vor 1 Jahrzehnt", prettyTime.format(addTime(-10, Calendar.YEAR))); + assertEquals("in 5 Jahrzehnten", prettyTime.format(addTime(50, Calendar.YEAR))); + assertEquals("in 1 Jahrzehnt", prettyTime.format(addTime(11, Calendar.YEAR))); + assertEquals("5 Jahrzehnte", prettyTime.formatDuration(addTime(-50, Calendar.YEAR))); + assertEquals("1 Jahrzehnt", prettyTime.formatDuration(addTime(-10, Calendar.YEAR))); + } + + @Test + public void testGrammaticalCaseCenturies() + { + assertEquals("vor 5 Jahrhunderten", prettyTime.format(addTime(-500, Calendar.YEAR))); + assertEquals("vor 1 Jahrhundert", prettyTime.format(addTime(-100, Calendar.YEAR))); + assertEquals("in 5 Jahrhunderten", prettyTime.format(addTime(500, Calendar.YEAR))); + assertEquals("in 1 Jahrhundert", prettyTime.format(addTime(101, Calendar.YEAR))); + assertEquals("5 Jahrhunderte", prettyTime.formatDuration(addTime(-500, Calendar.YEAR))); + assertEquals("1 Jahrhundert", prettyTime.formatDuration(addTime(-100, Calendar.YEAR))); + } + + @Test + public void testGrammaticalCaseMillenia() + { + assertEquals("vor 5 Jahrtausenden", prettyTime.format(addTime(-5000, Calendar.YEAR))); + assertEquals("vor 1 Jahrtausend", prettyTime.format(addTime(-1001, Calendar.YEAR))); + assertEquals("in 5 Jahrtausenden", prettyTime.format(addTime(5000, Calendar.YEAR))); + assertEquals("in 1 Jahrtausend", prettyTime.format(addTime(1001, Calendar.YEAR))); + assertEquals("5 Jahrtausende", prettyTime.formatDuration(addTime(-5000, Calendar.YEAR))); + assertEquals("1 Jahrtausend", prettyTime.formatDuration(addTime(-1001, Calendar.YEAR))); + } + + // Method tearDown() is called automatically after every test method + @After + public void tearDown() throws Exception + { + Locale.setDefault(locale); + } + + /** + * Helper method to simplify unit tests and prevent code duplicates. + * + * @param amount Amount of time to add + * @param field Calendar field (ie. {@link Calendar#HOUR}, {@link Calendar#YEAR}) + * @return Date with the added quantity of time + */ + private Date addTime(int amount, int field) + { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(base); + calendar.add(field, amount); + return calendar.getTime(); + } + +} From 641428312b9162d8a442551cde0da573df8cd96d Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sat, 19 Dec 2020 13:14:08 -0500 Subject: [PATCH 056/147] Fix a few more misfiring tests --- .../java/org/ocpsoft/prettytime/PrettyTimeI18n_NO_Test.java | 5 +++-- .../src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_NO_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_NO_Test.java index f22fd9d4..a75a717e 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_NO_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_NO_Test.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals; import java.text.SimpleDateFormat; +import java.time.LocalDateTime; import java.util.Date; import java.util.Locale; @@ -42,7 +43,7 @@ public void setUp() throws Exception public void testPrettyTime() { PrettyTime p = new PrettyTime(locale); - assertEquals("straks", p.format(new Date())); + assertEquals("straks", p.format(LocalDateTime.now().plusSeconds(1))); } @Test @@ -207,4 +208,4 @@ public void testCenturiesAgo() throws Exception PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale); assertEquals("3 århundre siden", t.format(new Date(0))); } -} \ No newline at end of file +} diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java index 7b188147..8710cbf2 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java @@ -297,7 +297,7 @@ public void testWithinTwoHoursRounding() throws Exception public void testPreciseInTheFuture() throws Exception { PrettyTime t = new PrettyTime(); - List durations = t.calculatePreciseDuration(now.plusHours(5).plusMinutes(10)); + List durations = t.calculatePreciseDuration(now.plusHours(5).plusMinutes(10).plusSeconds(1)); Assert.assertTrue(durations.size() >= 2); Assert.assertEquals(5, durations.get(0).getQuantity()); Assert.assertEquals(10, durations.get(1).getQuantity()); @@ -307,7 +307,7 @@ public void testPreciseInTheFuture() throws Exception public void testPreciseInThePast() throws Exception { PrettyTime t = new PrettyTime(); - List durations = t.calculatePreciseDuration(now.minusHours(5).minusMinutes(10)); + List durations = t.calculatePreciseDuration(now.minusHours(5).minusMinutes(10).minusSeconds(1)); Assert.assertTrue(durations.size() >= 2); Assert.assertEquals(-5, durations.get(0).getQuantity()); Assert.assertEquals(-10, durations.get(1).getQuantity()); From 08894358b6b5ee1b587a0527fc42e05b60d1c57b Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sat, 19 Dec 2020 13:57:53 -0500 Subject: [PATCH 057/147] Add PrettyTime.setUnits(TimeUnit ...units) and PrettyTime.setUnits(TimeFormat format, TimeUnit ...units) APIs --- .../org/ocpsoft/prettytime/PrettyTime.java | 89 ++++++++++++++++++- .../prettytime/impl/ResourcesTimeUnit.java | 7 +- .../PrettyTimeAPIManipulationTest.java | 60 ++++++++----- .../ocpsoft/prettytime/PrettyTimeTest.java | 26 +++++- 4 files changed, 153 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index aaa18d0d..c3cfa667 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -349,6 +349,62 @@ public Duration approximateDuration(Instant then) return approximateDuration(then != null ? Date.from(then) : null); } + /** + * Calculate the approximate {@link Duration} between the reference {@link Instant} and given {@link LocalDateTime}. + * If the given {@link LocalDateTime} is null, the current value of {@link System#currentTimeMillis()} + * will be used instead. + * + * @see #getReference() + */ + public Duration approximateDuration(LocalDate then) + { + return approximateDuration(then != null ? then.atStartOfDay(ZoneId.systemDefault()).toInstant() : null); + } + + /** + * Calculate the approximate {@link Duration} between the reference {@link Instant} and given {@link LocalDate}. If + * the given {@link LocalDate} is null, the current value of {@link System#currentTimeMillis()} will be + * used instead. + * + * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference + * timestamp was provided + * @param zoneId The {@link ZoneId} to be used, not null + * @see #getReference() + */ + public Duration approximateDuration(LocalDate then, final ZoneId zoneId) + { + return approximateDuration(then != null ? then.atStartOfDay(ZoneId.systemDefault()).toInstant() : null); + } + + /** + * Calculate the approximate {@link Duration} between the reference {@link Instant} and given {@link LocalDateTime}. + * If the given {@link LocalDateTime} is null, the current value of {@link System#currentTimeMillis()} + * will be used instead. + * + * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference + * timestamp was provided + * @see #getReference() + */ + public Duration approximateDuration(LocalDateTime then) + { + return approximateDuration(then != null ? then.atZone(ZoneId.systemDefault()).toInstant() : null); + } + + /** + * Calculate the approximate {@link Duration} between the reference {@link Instant} and given {@link LocalDateTime}. + * If the given {@link LocalDateTime} is null, the current value of {@link System#currentTimeMillis()} + * will be used instead. + * + * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference + * timestamp was provided + * @param zoneId The {@link ZoneId} to be used, not null + * @see #getReference() + */ + public Duration approximateDuration(LocalDateTime then, final ZoneId zoneId) + { + return approximateDuration(then != null ? then.atZone(zoneId).toInstant() : null); + } + /** * Calculate to the precision of the smallest provided {@link TimeUnit}, the exact {@link Duration} represented by * the difference between the reference {@link Instant} and the given {@link Date}. If the given {@link Date} is @@ -1408,9 +1464,9 @@ public UNIT getUnit(final Class unitType) public PrettyTime registerUnit(final TimeUnit unit, TimeFormat format) { if (unit == null) - throw new IllegalArgumentException("Unit to register must not be null."); + throw new IllegalArgumentException("TimeUnit to register must not be null."); if (format == null) - throw new IllegalArgumentException("Format to register must not be null."); + throw new IllegalArgumentException("TimeFormat to register must not be null."); cachedUnits = null; @@ -1422,6 +1478,35 @@ public PrettyTime registerUnit(final TimeUnit unit, TimeFormat format) return this; } + public PrettyTime setUnits(final ResourcesTimeUnit... units) + { + if (units == null || units.length == 0) + throw new IllegalArgumentException("TimeUnit instance(s) to register must be provided."); + + this.clearUnits(); + for (ResourcesTimeUnit unit : units) { + TimeFormat format = new ResourcesTimeFormat((ResourcesTimeUnit) unit); + this.registerUnit(unit, format); + } + + return this; + } + + public PrettyTime setUnits(TimeFormat format, final TimeUnit... units) + { + if (units == null || units.length == 0) + throw new IllegalArgumentException("TimeUnit instance(s) to register must be provided."); + if (format == null) + throw new IllegalArgumentException("TimeFormat to register must not be null."); + + this.clearUnits(); + for (TimeUnit unit : units) { + this.registerUnit(unit, format); + } + + return this; + } + /** * Removes the mapping for the given {@link TimeUnit} type. This effectively de-registers the {@link TimeUnit} so it * will not be used in formatting. Returns the {@link TimeFormat} that was removed, or null if no unit diff --git a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeUnit.java b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeUnit.java index 6cb1b77a..7fbbf361 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeUnit.java +++ b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeUnit.java @@ -26,11 +26,14 @@ public abstract class ResourcesTimeUnit implements TimeUnit private long millisPerUnit = 1; /** - * Return the name of the resource bundle from which this unit's format should be loaded. + * Return the time-unit prefix to specify which value to load from the bundle. */ abstract protected String getResourceKeyPrefix(); - protected String getResourceBundleName() + /** + * Return the name of the resource bundle from which this unit's format should be loaded. + */ + protected final String getResourceBundleName() { return "org.ocpsoft.prettytime.i18n.Resources"; } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java index 86f607df..2d488a3a 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java @@ -19,8 +19,8 @@ import static org.junit.Assert.assertNotNull; import java.time.Instant; -import java.time.LocalDateTime; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.OffsetDateTime; import java.time.ZonedDateTime; import java.util.Calendar; @@ -35,16 +35,24 @@ public class PrettyTimeAPIManipulationTest { PrettyTime t = new PrettyTime(); + @Test(expected = IllegalArgumentException.class) + public void testApiMisuseSetUnits1() throws Exception + { + t.setUnits(); + } + @Test public void testApiMisuse1() throws Exception { - Assert.assertEquals(t.approximateDuration(new Date()), t.approximateDuration((Date) null)); + Assert.assertEquals(t.approximateDuration(LocalDateTime.now()), + t.approximateDuration((Date) null)); } @Test public void testApiMisuse2() throws Exception { - Assert.assertEquals(t.calculatePreciseDuration(new Date()), t.calculatePreciseDuration((Date) null)); + Assert.assertEquals(t.calculatePreciseDuration(LocalDateTime.now()), + t.calculatePreciseDuration((Date) null)); } @Test @@ -56,49 +64,49 @@ public void testApiMisuse3() throws Exception @Test public void testApiMisuse4() throws Exception { - Assert.assertEquals(t.format(new Date()), t.format((Date) null)); + Assert.assertEquals(t.format(LocalDateTime.now().plusSeconds(1)), t.format((Date) null)); } @Test public void testApiMisuse4_1() throws Exception { - Assert.assertEquals(t.format(new Date()), t.format((Calendar) null)); + Assert.assertEquals(t.format(LocalDateTime.now().plusSeconds(1)), t.format((Calendar) null)); } @Test public void testApiMisuse4_2() throws Exception { - Assert.assertEquals(t.format(new Date()), t.format((Duration) null)); + Assert.assertEquals(t.format(LocalDateTime.now().plusSeconds(1)), t.format((Duration) null)); } @Test public void testApiMisuse4_3() throws Exception { - Assert.assertEquals(t.format(new Date()), t.format((List) null)); + Assert.assertEquals(t.format(LocalDateTime.now().plusSeconds(1)), t.format((List) null)); } @Test public void testApiMisuse4_4() throws Exception { - Assert.assertEquals(t.format(new Date()), t.format((Instant) null)); + Assert.assertEquals(t.format(LocalDateTime.now().plusSeconds(1)), t.format((Instant) null)); } @Test public void testApiMisuse4_5() throws Exception { - Assert.assertEquals(t.format(new Date()), t.format((ZonedDateTime) null)); + Assert.assertEquals(t.format(LocalDateTime.now().plusSeconds(1)), t.format((ZonedDateTime) null)); } @Test public void testApiMisuse4_6() throws Exception { - Assert.assertEquals(t.format(new Date()), t.format((OffsetDateTime) null)); + Assert.assertEquals(t.format(LocalDateTime.now().plusSeconds(1)), t.format((OffsetDateTime) null)); } @Test public void testApiMisuse4_7_1() throws Exception { - Assert.assertEquals(t.format(new Date()), t.format((LocalDateTime) null, null)); + Assert.assertEquals(t.format(LocalDateTime.now().plusSeconds(1)), t.format((LocalDateTime) null, null)); } @Test(expected = NullPointerException.class) @@ -110,13 +118,13 @@ public void testApiMisuse4_7_2() @Test public void testApiMisuse4_8() { - Assert.assertEquals(t.format(new Date()), t.format((LocalDateTime) null)); + Assert.assertEquals(t.format(LocalDateTime.now().plusSeconds(1)), t.format((LocalDateTime) null)); } @Test public void testApiMisuse4_9_1() throws Exception { - Assert.assertEquals(t.format(new Date()), t.format((LocalDate) null, null)); + Assert.assertEquals(t.format(LocalDateTime.now().plusSeconds(1)), t.format((LocalDate) null, null)); } @Test(expected = NullPointerException.class) @@ -128,49 +136,53 @@ public void testApiMisuse4_9_2() @Test public void testApiMisuse5() throws Exception { - Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((Date) null)); + Assert.assertEquals(t.formatUnrounded(LocalDateTime.now().plusSeconds(1)), t.formatUnrounded((Date) null)); } @Test public void testApiMisuse5_1() throws Exception { - Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((Calendar) null)); + Assert.assertEquals(t.formatUnrounded(LocalDateTime.now().plusSeconds(1)), t.formatUnrounded((Calendar) null)); } @Test public void testApiMisuse5_2() throws Exception { - Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((Duration) null)); + Assert.assertEquals(t.formatUnrounded(LocalDateTime.now().plusSeconds(1)), t.formatUnrounded((Duration) null)); } @Test public void testApiMisuse5_3() throws Exception { - Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((List) null)); + Assert.assertEquals(t.formatUnrounded(LocalDateTime.now().plusSeconds(1)), + t.formatUnrounded((List) null)); } @Test public void testApiMisuse5_4() throws Exception { - Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((Instant) null)); + Assert.assertEquals(t.formatUnrounded(LocalDateTime.now().plusSeconds(1)), t.formatUnrounded((Instant) null)); } @Test public void testApiMisuse5_5() throws Exception { - Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((ZonedDateTime) null)); + Assert.assertEquals(t.formatUnrounded(LocalDateTime.now().plusSeconds(1)), + t.formatUnrounded((ZonedDateTime) null)); } @Test public void testApiMisuse5_6() throws Exception { - Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((OffsetDateTime) null)); + Assert.assertEquals(t.formatUnrounded(LocalDateTime.now().plusSeconds(1)), + t.formatUnrounded((OffsetDateTime) null)); } @Test public void testApiMisuse5_7_1() throws Exception { - Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((LocalDateTime) null, null)); + Assert.assertEquals(t.formatUnrounded(LocalDateTime.now().plusSeconds(1)), + t.formatUnrounded((LocalDateTime) null, null)); } @Test(expected = NullPointerException.class) @@ -182,13 +194,15 @@ public void testApiMisuse5_7_2() @Test public void testApiMisuse5_8() { - Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((LocalDateTime) null)); + Assert.assertEquals(t.formatUnrounded(LocalDateTime.now().plusSeconds(1)), + t.formatUnrounded((LocalDateTime) null)); } @Test public void testApiMisuse5_9_1() throws Exception { - Assert.assertEquals(t.formatUnrounded(new Date()), t.formatUnrounded((LocalDate) null, null)); + Assert.assertEquals(t.formatUnrounded(LocalDateTime.now().plusSeconds(1)), + t.formatUnrounded((LocalDate) null, null)); } @Test(expected = NullPointerException.class) diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java index 8710cbf2..0bde7241 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java @@ -75,12 +75,13 @@ public void testCalculatePreciceDuration() throws Exception new Date(System.currentTimeMillis() - (2 * 60 * 60 * 1000) - (2 * 60 * 1000))); Assert.assertEquals("2 hours 2 minutes ago", t.format(preciseDuration)); Assert.assertEquals("2 hours 2 minutes", t.formatDuration(preciseDuration)); - Assert.assertEquals("moments from now", t.format(t.calculatePreciseDuration(new Date()))); + Assert.assertEquals("moments ago", + t.format(t.calculatePreciseDuration(new Date(new Date().getTime() - 10)))); preciseDuration = t.calculatePreciseDuration(now.minusHours(2).minusMinutes(2)); Assert.assertEquals("2 hours 2 minutes ago", t.format(preciseDuration)); Assert.assertEquals("2 hours 2 minutes", t.formatDuration(preciseDuration)); - Assert.assertEquals("moments from now", t.format(t.calculatePreciseDuration(LocalDateTime.now()))); + Assert.assertEquals("moments from now", t.format(t.calculatePreciseDuration(LocalDateTime.now().plusSeconds(1)))); } @Test @@ -95,6 +96,27 @@ public void testCalculatePreciceDurationMillenia() throws Exception t.formatDuration(durations)); } + @Test + public void testCalculatePreciseDurationSingleUnit() + { + PrettyTime prettyTime = new PrettyTime(); + Minute minutes = new Minute(); + prettyTime.setUnits(minutes); + Assert.assertEquals("40 minutes ago", prettyTime.formatUnrounded(prettyTime + .calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); + } + + @Test + public void testCalculatePreciseDurationSingleUnitWithFormat() + { + PrettyTime prettyTime = new PrettyTime(); + Minute minutes = new Minute(); + TimeFormat format = new SimpleTimeFormat().setPluralName("woah man").setPattern("%n %u"); + prettyTime.setUnits(format, minutes); + Assert.assertEquals("40 woah man", prettyTime.formatUnrounded(prettyTime + .calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); + } + @Test public void testCalculatePreciseDuration2() { From 92888475338a937f0e4053d869e4389333515454 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sat, 19 Dec 2020 14:01:33 -0500 Subject: [PATCH 058/147] Dependabot security updates. --- samples/jstl/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index f0d807cf..db0356d7 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -15,12 +15,12 @@ org.eclipse.jetty jetty-server - 9.4.17.v20190418 + 9.4.35.v20201120 org.eclipse.jetty jetty-webapp - 7.2.2.v20101205 + 9.4.35.v20201120 @@ -66,4 +66,4 @@ - \ No newline at end of file + From 839587ced0408a39a16f460fc1c85341a20b5914 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sat, 19 Dec 2020 14:12:20 -0500 Subject: [PATCH 059/147] Use String.format("%d", numUnits) to apply locale-specific conversion of digits. Fixes #174 --- .../org/ocpsoft/prettytime/PrettyTime.java | 1 - .../prettytime/format/SimpleTimeFormat.java | 20 +++++++- .../prettytime/impl/ResourcesTimeFormat.java | 3 +- .../prettytime/PrettyTimeI18n_hi_IN_Test.java | 46 +++++++++---------- 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index c3cfa667..61708f55 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -332,7 +332,6 @@ public Duration approximateDuration(Date then) then = now(); final Instant ref = reference != null ? reference : Instant.now(); - long difference = then.getTime() - ref.toEpochMilli(); return calculateDuration(difference); } diff --git a/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java b/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java index 3575d84b..c2393154 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java +++ b/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java @@ -15,9 +15,11 @@ */ package org.ocpsoft.prettytime.format; +import java.util.Locale; import java.util.regex.Pattern; import org.ocpsoft.prettytime.Duration; +import org.ocpsoft.prettytime.LocaleAware; import org.ocpsoft.prettytime.TimeFormat; import org.ocpsoft.prettytime.TimeUnit; @@ -26,7 +28,7 @@ * * @author Lincoln Baxter, III */ -public class SimpleTimeFormat implements TimeFormat +public class SimpleTimeFormat implements TimeFormat, LocaleAware { private static final String NEGATIVE = "-"; public static final String SIGN = "%s"; @@ -35,6 +37,8 @@ public class SimpleTimeFormat implements TimeFormat private static final Pattern PATTERN_MULTIPLE_WHITESPACES = Pattern.compile("\\s{2,}"); + private Locale locale; + private String singularName = ""; private String pluralName = ""; private String futureSingularName = ""; @@ -49,6 +53,13 @@ public class SimpleTimeFormat implements TimeFormat private String pastSuffix = ""; private int roundingTolerance = 50; + @Override + public SimpleTimeFormat setLocale(Locale locale) + { + this.locale = locale; + return this; + } + @Override public String format(final Duration duration) { @@ -93,7 +104,11 @@ private String format(final Duration duration, final boolean round) private String applyPattern(final String sign, final String unit, final long quantity) { String result = getPattern(quantity).replace(SIGN, sign); - result = result.replace(QUANTITY, String.valueOf(quantity)); + String formatted = (this.locale != null) + ? String.format(this.locale, "%d", quantity) + : String.format("%d", quantity); + + result = result.replace(QUANTITY, formatted); result = result.replace(UNIT, unit); return result; } @@ -158,6 +173,7 @@ else if (duration.isInPast() && pastPluralName != null && pastSingularName.lengt /* * Builder Setters */ + public SimpleTimeFormat setPattern(final String pattern) { this.pattern = pattern; diff --git a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java index fb9faad3..48488b05 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java +++ b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java @@ -4,7 +4,6 @@ import java.util.ResourceBundle; import org.ocpsoft.prettytime.Duration; -import org.ocpsoft.prettytime.LocaleAware; import org.ocpsoft.prettytime.TimeFormat; import org.ocpsoft.prettytime.format.SimpleTimeFormat; @@ -13,7 +12,7 @@ * * @author lb3 */ -public class ResourcesTimeFormat extends SimpleTimeFormat implements LocaleAware +public class ResourcesTimeFormat extends SimpleTimeFormat { private final ResourcesTimeUnit unit; private TimeFormat override; 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 7f887501..2209ac7b 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 @@ -49,7 +49,7 @@ public void testCeilingInterval() throws Exception Date then = format.parse("5/20/2009"); Date ref = format.parse("6/17/2009"); PrettyTime t = new PrettyTime(ref); - assertEquals("1 महीना पहले", t.format(then)); + assertEquals("१ महीना पहले", t.format(then)); } @Test @@ -78,21 +78,21 @@ public void testRightNowVariance() throws Exception public void testMinutesFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); - assertEquals("12 मिनट बाद", t.format(new Date(1000 * 60 * 12))); + assertEquals("१२ मिनट बाद", t.format(new Date(1000 * 60 * 12))); } @Test public void testHoursFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); - assertEquals("3 घंटे बाद", t.format(new Date(1000 * 60 * 60 * 3))); + assertEquals("३ घंटे बाद", t.format(new Date(1000 * 60 * 60 * 3))); } @Test public void testDaysFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); - assertEquals("3 दिन बाद", + assertEquals("३ दिन बाद", t.format(new Date(1000 * 60 * 60 * 24 * 3))); } @@ -100,7 +100,7 @@ public void testDaysFromNow() throws Exception public void testWeeksFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); - assertEquals("3 सप्ताह बाद", + assertEquals("३ सप्ताह बाद", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); } @@ -108,7 +108,7 @@ public void testWeeksFromNow() throws Exception public void testMonthsFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); - assertEquals("3 महीने बाद", t.format(new Date(2629743830L * 3L))); + assertEquals("३ महीने बाद", t.format(new Date(2629743830L * 3L))); // assertEquals("अभी से 3 महीने बाद", t.format(new Date(1000 * 60 * 60 * 24 * 365 * 3L))); } @@ -116,7 +116,7 @@ public void testMonthsFromNow() throws Exception public void testYearsFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); - assertEquals("3 वर्ष बाद", + assertEquals("३ वर्ष बाद", t.format(new Date(2629743830L * 12L * 3L))); } @@ -124,7 +124,7 @@ public void testYearsFromNow() throws Exception public void testDecadesFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); - assertEquals("3 दशक बाद", + assertEquals("३ दशक बाद", t.format(new Date(315569259747L * 3L))); } @@ -132,7 +132,7 @@ public void testDecadesFromNow() throws Exception public void testCenturiesFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); - assertEquals("3 सदियों बाद", + assertEquals("३ सदियों बाद", t.format(new Date(3155692597470L * 3L))); } @@ -150,35 +150,35 @@ public void testMomentsAgo() throws Exception public void testMinutesAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12)); - assertEquals("12 मिनट पहले", t.format(new Date(0))); + assertEquals("१२ मिनट पहले", t.format(new Date(0))); } @Test public void testHoursAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3)); - assertEquals("3 घंटे पहले", t.format(new Date(0))); + assertEquals("३ घंटे पहले", t.format(new Date(0))); } @Test public void testDaysAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3)); - assertEquals("3 दिन पहले", t.format(new Date(0))); + assertEquals("३ दिन पहले", t.format(new Date(0))); } @Test public void testWeeksAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3)); - assertEquals("3 सप्ताह पहले", t.format(new Date(0))); + assertEquals("३ सप्ताह पहले", t.format(new Date(0))); } @Test public void testMonthsAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(2629743830L * 3L)); - assertEquals("3 महीने पहले", t.format(new Date(0))); + assertEquals("३ महीने पहले", t.format(new Date(0))); } @Test @@ -197,7 +197,7 @@ public long getMillisPerUnit() { return 5000; } - + @Override public boolean isPrecise() { @@ -214,38 +214,38 @@ public boolean isPrecise() .setPastPrefix("पहले ") .setPastSuffix("थे")); - assertEquals("भविष्य में 5 खेल होंगे", + assertEquals("भविष्य में ५ खेल होंगे", t.format(new Date(25000))); t.setReference(new Date(25000)); - assertEquals("पहले 5 खेल थे", t.format(new Date(0))); + assertEquals("पहले ५ खेल थे", t.format(new Date(0))); } @Test public void testYearsAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L)); - assertEquals("3 वर्ष पहले", t.format(new Date(0))); + assertEquals("३ वर्ष पहले", t.format(new Date(0))); } @Test public void testDecadesAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(315569259747L * 3L)); - assertEquals("3 दशक पहले", t.format(new Date(0))); + assertEquals("३ दशक पहले", t.format(new Date(0))); } @Test public void testCenturiesAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L)); - assertEquals("3 सदियों पहले", t.format(new Date(0))); + assertEquals("३ सदियों पहले", t.format(new Date(0))); } @Test public void testWithinTwoHoursRounding() throws Exception { PrettyTime t = new PrettyTime(); - assertEquals("2 घंटे पहले", + assertEquals("२ घंटे पहले", t.format(new Date(new Date().getTime() - 6543990))); } @@ -283,7 +283,7 @@ public void testFormattingDurationListInThePast() throws Exception PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3 + 1000 * 60 * 60 * 15 + 1000 * 60 * 38)); List durations = t.calculatePreciseDuration(new Date(0)); - assertEquals("3 दिन 15 घंटे 38 मिनट पहले", t.format(durations)); + assertEquals("३ दिन १५ घंटे ३८ मिनट पहले", t.format(durations)); } @Test @@ -292,7 +292,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)); - assertEquals("3 दिन 15 घंटे 38 मिनट बाद", t.format(durations)); + assertEquals("३ दिन १५ घंटे ३८ मिनट बाद", t.format(durations)); } // End of duplicate test -- // From cb596ba57cd27cf25b6511935320ed5a6d676aed Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sat, 19 Dec 2020 14:25:04 -0500 Subject: [PATCH 060/147] Bump natty to version 0.13. Fixes #163 --- nlp/pom.xml | 2 +- .../java/org/ocpsoft/prettytime/nlp/PrettyTimeParserTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nlp/pom.xml b/nlp/pom.xml index df5e4b22..3fae39a6 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -23,7 +23,7 @@ com.joestelmach natty - 0.10.1 + 0.13 antlr diff --git a/nlp/src/test/java/org/ocpsoft/prettytime/nlp/PrettyTimeParserTest.java b/nlp/src/test/java/org/ocpsoft/prettytime/nlp/PrettyTimeParserTest.java index 40abac80..62eb0af8 100644 --- a/nlp/src/test/java/org/ocpsoft/prettytime/nlp/PrettyTimeParserTest.java +++ b/nlp/src/test/java/org/ocpsoft/prettytime/nlp/PrettyTimeParserTest.java @@ -57,7 +57,7 @@ public void testParseSyntax() String formatted = new PrettyTime(Locale.ENGLISH).format(parse.get(0).getDates().get(0)); Assert.assertEquals("3 days ago", formatted); Assert.assertEquals(1, parse.get(0).getLine()); - Assert.assertEquals(9, parse.get(0).getPosition()); + Assert.assertEquals(10, parse.get(0).getPosition()); Assert.assertEquals(1, parse.get(0).getDates().size()); Assert.assertNull(parse.get(0).getRecursUntil()); Assert.assertFalse(parse.get(0).isRecurring()); From d7817fe6628ec73347e686531c44bbd24cda04a8 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sat, 19 Dec 2020 15:14:07 -0500 Subject: [PATCH 061/147] TimeUnits should have unique identifiers. Fixes #152 --- .../org/ocpsoft/prettytime/PrettyTime.java | 18 +++++++++--------- .../prettytime/impl/ResourcesTimeUnit.java | 10 ++++++++-- .../org/ocpsoft/prettytime/PrettyTimeTest.java | 8 ++++++++ .../PrettyTimeUnitConfigurationTest.java | 12 ++++++++++++ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index 61708f55..14df4735 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -26,10 +26,10 @@ import java.util.Collections; import java.util.Comparator; import java.util.Date; -import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import org.ocpsoft.prettytime.impl.DurationImpl; import org.ocpsoft.prettytime.impl.ResourcesTimeFormat; @@ -71,9 +71,9 @@ public class PrettyTime { private volatile Instant reference; private volatile Locale locale = Locale.getDefault(); - private final Map units = new LinkedHashMap<>(); + private final Map units = new ConcurrentHashMap<>(); private volatile List cachedUnits; - private final String overrideResourceBundle; + private String overrideResourceBundle; /** * Create a new {@link PrettyTime} instance that will always use the current value of @@ -83,7 +83,6 @@ public class PrettyTime public PrettyTime() { this((String) null); - initTimeUnits(); } /** @@ -95,7 +94,7 @@ public PrettyTime() public PrettyTime(final String overrideResourceBundle) { this.overrideResourceBundle = overrideResourceBundle; - initTimeUnits(); + this.initTimeUnits(); } /** @@ -268,9 +267,8 @@ public PrettyTime(final LocalDate reference, final ZoneId zoneId, final String o */ public PrettyTime(final Locale locale) { - this.overrideResourceBundle = null; + this(); setLocale(locale); - initTimeUnits(); } /** @@ -282,9 +280,8 @@ public PrettyTime(final Locale locale) */ public PrettyTime(final Locale locale, String overrideResourceBundle) { - this.overrideResourceBundle = overrideResourceBundle; + this(overrideResourceBundle); setLocale(locale); - initTimeUnits(); } /** @@ -333,6 +330,9 @@ public Duration approximateDuration(Date then) final Instant ref = reference != null ? reference : Instant.now(); long difference = then.getTime() - ref.toEpochMilli(); + if (difference == 0) { + difference = 1; + } return calculateDuration(difference); } diff --git a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeUnit.java b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeUnit.java index 7fbbf361..7eded02e 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeUnit.java +++ b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeUnit.java @@ -22,9 +22,16 @@ */ public abstract class ResourcesTimeUnit implements TimeUnit { + private static long ID = 0; + private long id = 0; private long maxQuantity = 0; private long millisPerUnit = 1; + public ResourcesTimeUnit() + { + this.id = ID++; + } + /** * Return the time-unit prefix to specify which value to load from the bundle. */ @@ -77,8 +84,7 @@ public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + Long.hashCode(maxQuantity); - result = prime * result + Long.hashCode(millisPerUnit); + result = prime * result + Long.hashCode(id); return result; } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java index 0bde7241..7da8077c 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java @@ -67,6 +67,14 @@ public void testRightNow() throws Exception Assert.assertEquals("moments from now", t.format(new Date())); } + @Test + public void testRightNowWithReference() throws Exception + { + Date now = new Date(); + PrettyTime t = new PrettyTime(); + Assert.assertEquals("moments from now", t.format(now)); + } + @Test public void testCalculatePreciceDuration() throws Exception { diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java index 8f36c24e..ae84f456 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals; import java.text.SimpleDateFormat; +import java.time.LocalDateTime; import java.util.Date; import java.util.Locale; @@ -60,7 +61,10 @@ public void testRightNow() throws Exception public void testMinutesFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0)); + System.out.println(t.getUnits()); + Assert.assertEquals(12, t.getUnits().size()); TimeFormat format = t.removeUnit(Minute.class); + Assert.assertEquals(11, t.getUnits().size()); Assert.assertNotNull(format); assertEquals("720 seconds from now", t.format(new Date(1000 * 60 * 12))); } @@ -74,6 +78,14 @@ public void testHoursFromNow() throws Exception assertEquals("180 minutes from now", t.format(new Date(1000 * 60 * 60 * 3))); } + @Test + public void testModifyUnitInPlace() + { + PrettyTime prettyTime = new PrettyTime(); + prettyTime.getUnit(JustNow.class).setMaxQuantity(1000L * 2L); + Assert.assertEquals("moments ago", prettyTime.format(LocalDateTime.now().minusSeconds(1))); + } + // Method tearDown() is called automatically after every test method @After public void tearDown() throws Exception From 1ff0b49dd5a9ad9a15deafa816ad05563e31c74b Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sat, 19 Dec 2020 15:19:22 -0500 Subject: [PATCH 062/147] Verify #155 is fixed in Version 5 --- .../PrettyTimeUnitConfigurationTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java index ae84f456..e7f77a59 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java @@ -26,6 +26,8 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.ocpsoft.prettytime.impl.ResourcesTimeFormat; +import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; import org.ocpsoft.prettytime.units.Hour; import org.ocpsoft.prettytime.units.JustNow; import org.ocpsoft.prettytime.units.Minute; @@ -86,6 +88,26 @@ public void testModifyUnitInPlace() Assert.assertEquals("moments ago", prettyTime.format(LocalDateTime.now().minusSeconds(1))); } + @Test + public void testRemoveAndReadUnit() + { + PrettyTime prettyTime = new PrettyTime(); + prettyTime.removeUnit(JustNow.class); + ResourcesTimeUnit justNow = new ResourcesTimeUnit() { + { + setMaxQuantity(10000); + } + + @Override + protected String getResourceKeyPrefix() + { + return "JustNow"; + } + }; + prettyTime.registerUnit(justNow, new ResourcesTimeFormat(justNow)); + Assert.assertEquals("moments ago", prettyTime.format(LocalDateTime.now().minusSeconds(1))); + } + // Method tearDown() is called automatically after every test method @After public void tearDown() throws Exception From 1f31ee0c0cc5ab7c6e85421ac9d7951af33ce276 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sat, 19 Dec 2020 15:24:17 -0500 Subject: [PATCH 063/147] [maven-release-plugin] prepare release 5.0.0.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index a9b2dc91..aa02a49a 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.7-SNAPSHOT + 5.0.0.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 406e0a5b..1918abec 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 4.0.7-SNAPSHOT + 5.0.0.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 2ea27fc1..944e2cdf 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.7-SNAPSHOT + 5.0.0.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 3fae39a6..340e3cf9 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.7-SNAPSHOT + 5.0.0.Final ../pom.xml diff --git a/pom.xml b/pom.xml index 06c9a0b4..66a16d0c 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 4.0.7-SNAPSHOT + 5.0.0.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 5.0.0.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index db0356d7..37112b29 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 4.0.7-SNAPSHOT + 5.0.0.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 4.0.7-SNAPSHOT + 5.0.0.Final diff --git a/samples/pom.xml b/samples/pom.xml index a237b0b6..100bba74 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 4.0.7-SNAPSHOT + 5.0.0.Final 4.0.0 From 5984e44108baea7fea790180a565eb855b5838b8 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sat, 19 Dec 2020 15:24:17 -0500 Subject: [PATCH 064/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index aa02a49a..8157b3b7 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.0.Final + 5.0.1-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 1918abec..109edde2 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.0.Final + 5.0.1-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 944e2cdf..b15c4d53 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.0.Final + 5.0.1-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 340e3cf9..6aa6e820 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.0.Final + 5.0.1-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index 66a16d0c..3de573fc 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.0.Final + 5.0.1-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 5.0.0.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 37112b29..061a78fd 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.0.Final + 5.0.1-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.0.Final + 5.0.1-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index 100bba74..85ad5c6d 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.0.Final + 5.0.1-SNAPSHOT 4.0.0 From acd14391b7a94a42cae21088ef8f0f8562a1c1d4 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sat, 19 Dec 2020 15:28:00 -0500 Subject: [PATCH 065/147] Update with notes for JDK <1.8 --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 42225eea..e1a722f0 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,14 @@ Social Style Date and Time Formatting for Java Learn more at http://ocpsoft.org/prettytime/ +Java 1.8 (Support JDK DateTime API) +======= +PrettyTime requires Java/JDK >=1.8 as of version `5.0.0.Final` or higher. + +Java <=1.7 +======= +Users requiring versions of Java/JDK less than or equal to 1.7 should use PrettyTime versions in the 4.x branch: `4.0.6.Final` or lower. + Android ======= To use prettytime in android, first add the following dependency to your app level build.gradle From 6f9c07f74f7e2b9f590d804b83c4203496ce97d9 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sat, 19 Dec 2020 15:35:49 -0500 Subject: [PATCH 066/147] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e1a722f0..39295b58 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Social Style Date and Time Formatting for Java Learn more at http://ocpsoft.org/prettytime/ -Java 1.8 (Support JDK DateTime API) +Java >=1.8 (Support JDK DateTime API) ======= PrettyTime requires Java/JDK >=1.8 as of version `5.0.0.Final` or higher. From b5a37ceb4546d35807a004005659ff1ef670769d Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sat, 19 Dec 2020 15:36:02 -0500 Subject: [PATCH 067/147] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 39295b58..eb43be13 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ prettytime ========== -[![Badge](http://www.libtastic.com/static/osbadges/152.png)](http://www.libtastic.com/technology/152/) - Social Style Date and Time Formatting for Java Learn more at http://ocpsoft.org/prettytime/ From 77ff7f98aa96e2da7c7ca2e3efd47aae98ced33f Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sat, 19 Dec 2020 15:36:31 -0500 Subject: [PATCH 068/147] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb43be13..f0817cdb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ prettytime ========== Social Style Date and Time Formatting for Java -Learn more at http://ocpsoft.org/prettytime/ +Learn more at https://www.ocpsoft.org/prettytime/ Java >=1.8 (Support JDK DateTime API) ======= From eddfb8b3cf74cca92d3e7d0d8c55b2c5b391f97c Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Tue, 22 Dec 2020 08:21:59 +0530 Subject: [PATCH 069/147] Use Objects.requireNonNull(). --- .../java/org/ocpsoft/prettytime/PrettyTime.java | 14 +++++--------- .../org/ocpsoft/prettytime/i18n/Resources_cs.java | 12 ++++-------- .../org/ocpsoft/prettytime/i18n/Resources_hr.java | 6 ++---- .../org/ocpsoft/prettytime/i18n/Resources_sk.java | 6 ++---- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index 14df4735..21bd3a61 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import org.ocpsoft.prettytime.impl.DurationImpl; @@ -1462,14 +1463,10 @@ public UNIT getUnit(final Class unitType) */ public PrettyTime registerUnit(final TimeUnit unit, TimeFormat format) { - if (unit == null) - throw new IllegalArgumentException("TimeUnit to register must not be null."); - if (format == null) - throw new IllegalArgumentException("TimeFormat to register must not be null."); - cachedUnits = null; - units.put(unit, format); + units.put(Objects.requireNonNull(unit, "TimeUnit to register must not be null."), + Objects.requireNonNull(format, "TimeFormat to register must not be null.")); if (unit instanceof LocaleAware) ((LocaleAware) unit).setLocale(locale); if (format instanceof LocaleAware) @@ -1484,7 +1481,7 @@ public PrettyTime setUnits(final ResourcesTimeUnit... units) this.clearUnits(); for (ResourcesTimeUnit unit : units) { - TimeFormat format = new ResourcesTimeFormat((ResourcesTimeUnit) unit); + TimeFormat format = new ResourcesTimeFormat(unit); this.registerUnit(unit, format); } @@ -1495,8 +1492,7 @@ public PrettyTime setUnits(TimeFormat format, final TimeUnit... units) { if (units == null || units.length == 0) throw new IllegalArgumentException("TimeUnit instance(s) to register must be provided."); - if (format == null) - throw new IllegalArgumentException("TimeFormat to register must not be null."); + Objects.requireNonNull(format, "TimeFormat to register must not be null."); this.clearUnits(); for (TimeUnit unit : units) { diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_cs.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_cs.java index 27d4ddc8..403c7832 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_cs.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_cs.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.List; import java.util.ListResourceBundle; +import java.util.Objects; import java.util.ResourceBundle; import org.ocpsoft.prettytime.Duration; @@ -227,10 +228,8 @@ else if (t instanceof Year) { private static class CsTimeFormatBuilder { - - private List names = new ArrayList(); - - private String resourceKeyPrefix; + private final List names = new ArrayList<>(); + private final String resourceKeyPrefix; CsTimeFormatBuilder(String resourceKeyPrefix) { @@ -249,10 +248,7 @@ CsTimeFormatBuilder addPastName(String name, long limit) private CsTimeFormatBuilder addName(boolean isFuture, String name, long limit) { - if (name == null) { - throw new IllegalArgumentException(); - } - names.add(new CsName(isFuture, name, limit)); + names.add(new CsName(isFuture, Objects.requireNonNull(name), limit)); return this; } diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_hr.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_hr.java index 1e9108ac..2c040bad 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_hr.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_hr.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.List; import java.util.ListResourceBundle; +import java.util.Objects; import java.util.ResourceBundle; import org.ocpsoft.prettytime.Duration; @@ -302,10 +303,7 @@ private static class HrTimeFormatBuilder private HrTimeFormatBuilder addName(final boolean isFuture, final String name, final long limit) { - if (name == null) { - throw new IllegalArgumentException(); - } - names.add(new HrName(isFuture, name, limit)); + names.add(new HrName(isFuture, Objects.requireNonNull(name), limit)); return this; } diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sk.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sk.java index a9c5cb7f..96e9b3a4 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sk.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sk.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.List; import java.util.ListResourceBundle; +import java.util.Objects; import java.util.ResourceBundle; import org.ocpsoft.prettytime.Duration; @@ -249,10 +250,7 @@ CsTimeFormatBuilder addPastName(String name, long limit) private CsTimeFormatBuilder addName(boolean isFuture, String name, long limit) { - if (name == null) { - throw new IllegalArgumentException(); - } - names.add(new CsName(isFuture, name, limit)); + names.add(new CsName(isFuture, Objects.requireNonNull(name), limit)); return this; } From 0c8211e15cc2db76d527c0215c86992351a5b459 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Tue, 22 Dec 2020 06:20:54 +0530 Subject: [PATCH 070/147] Add PrettyTime constructors that accept the java.time types as well as a Locale. --- .../org/ocpsoft/prettytime/PrettyTime.java | 360 ++++++++++++++++-- .../prettytime/impl/ResourcesTimeFormat.java | 4 +- .../PrettyTimeOverrideBundleTest.java | 8 +- 3 files changed, 330 insertions(+), 42 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index 14df4735..f4db0dbc 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -73,7 +73,7 @@ public class PrettyTime private volatile Locale locale = Locale.getDefault(); private final Map units = new ConcurrentHashMap<>(); private volatile List cachedUnits; - private String overrideResourceBundle; + private final String overrideResourceBundle; /** * Create a new {@link PrettyTime} instance that will always use the current value of @@ -87,7 +87,7 @@ public PrettyTime() /** * Create a new {@link PrettyTime} instance that will always use the current value of - * {@link System#currentTimeMillis()} to represent the reference point for {@link Date} comparison, and will use + * {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison, and will use * {@link Locale#getDefault()} as the selected {@link Locale} for language and dialect formatting. Will use * {@link String} as an optional override to the default resource bundles. */ @@ -99,21 +99,20 @@ public PrettyTime(final String overrideResourceBundle) /** * Create a new {@link PrettyTime} instance that will use the given {@link Date} timestamp to represent the reference - * point for {@link Date} comparison, and will use {@link Locale#getDefault()} as the selected {@link Locale} for + * point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected {@link Locale} for * language and dialect formatting. If the given {@link Date} is null, this instance will always use the - * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Date} comparison. + * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. */ public PrettyTime(final Date reference) { - this(); - setReference(reference); + this(reference, (String) null); } /** * Create a new {@link PrettyTime} instance that will use the given {@link Date} timestamp to represent the reference - * point for {@link Date} comparison, and will use {@link Locale#getDefault()} as the selected {@link Locale} for + * point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected {@link Locale} for * language and dialect formatting. If the given {@link Date} is null, this instance will always use the - * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Date} comparison. + * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. * Will use {@link String} as an optional override to the default resource bundles. * * @see #PrettyTime(Date). @@ -133,8 +132,7 @@ public PrettyTime(final Date reference, final String overrideResourceBundle) */ public PrettyTime(final Instant reference) { - this(); - setReference(reference); + this(reference, (String) null); } /** @@ -188,7 +186,7 @@ public PrettyTime(final LocalDateTime reference, final String overrideResourceBu */ public PrettyTime(final LocalDateTime reference, final ZoneId zoneId) { - this(reference, zoneId, null); + this(reference, zoneId, (String) null); } /** @@ -203,7 +201,7 @@ public PrettyTime(final LocalDateTime reference, final ZoneId zoneId) */ public PrettyTime(final LocalDateTime reference, final ZoneId zoneId, final String overrideResourceBundle) { - this(reference != null ? reference.atZone(zoneId).toInstant() : null, overrideResourceBundle); + this(reference != null ? reference.atZone(zoneId) : null, overrideResourceBundle); } /** @@ -215,7 +213,7 @@ public PrettyTime(final LocalDateTime reference, final ZoneId zoneId, final Stri */ public PrettyTime(final LocalDate reference) { - this(reference, ZoneId.systemDefault(), null); + this(reference, (String) null); } /** @@ -242,13 +240,13 @@ public PrettyTime(final LocalDate reference, final String overrideResourceBundle */ public PrettyTime(final LocalDate reference, final ZoneId zoneId) { - this(reference, zoneId, null); + this(reference, zoneId, (String) null); } /** - * Create a new {@link PrettyTime} instance that will use the given {@link Instant} timestamp to represent the + * Create a new {@link PrettyTime} instance that will use the given {@link LocalDate} to represent the * reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected - * {@link Locale} for language and dialect formatting. If the given {@link Instant} is null, this + * {@link Locale} for language and dialect formatting. If the given {@link LocalDate} is null, this * instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference point * for {@link Instant} comparison. Will use {@link String} as an optional override to the default resource bundles. * @@ -256,29 +254,86 @@ public PrettyTime(final LocalDate reference, final ZoneId zoneId) */ public PrettyTime(final LocalDate reference, final ZoneId zoneId, final String overrideResourceBundle) { - this(reference != null ? reference.atStartOfDay(zoneId).toInstant() : null, overrideResourceBundle); + this(reference != null ? reference.atStartOfDay(zoneId) : null, overrideResourceBundle); + } + + /** + * Create a new {@link PrettyTime} instance that will use the given {@link OffsetDateTime} to represent the + * reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected + * {@link Locale} for language and dialect formatting. If the given {@link OffsetDateTime} is null, this + * instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference point + * for {@link Instant} comparison. + * + * @see #PrettyTime(Instant) + */ + public PrettyTime(final OffsetDateTime reference) + { + this(reference, null); + } + + /** + * Create a new {@link PrettyTime} instance that will use the given {@link OffsetDateTime} to represent the + * reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected + * {@link Locale} for language and dialect formatting. If the given {@link OffsetDateTime} is null, this + * instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference point + * for {@link Instant} comparison. Will use {@link String} as an optional override to the default resource bundles. + * + * @see #PrettyTime(Instant) + */ + public PrettyTime(final OffsetDateTime reference, final String overrideResourceBundle) + { + this(overrideResourceBundle); + setReference(reference); + } + + /** + * Create a new {@link PrettyTime} instance that will use the given {@link ZonedDateTime} to represent the + * reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected + * {@link Locale} for language and dialect formatting. If the given {@link ZonedDateTime} is null, this + * instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference point + * for {@link Instant} comparison. Will use {@link String} as an optional override to the default resource bundles. + * + * @see #PrettyTime(Instant) + */ + public PrettyTime(final ZonedDateTime reference) + { + this(reference, null); + } + + /** + * Create a new {@link PrettyTime} instance that will use the given {@link ZonedDateTime} to represent the + * reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected + * {@link Locale} for language and dialect formatting. If the given {@link ZonedDateTime} is null, this + * instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference point + * for {@link Instant} comparison. Will use {@link String} as an optional override to the default resource bundles. + * + * @see #PrettyTime(Instant) + */ + public PrettyTime(final ZonedDateTime reference, final String overrideResourceBundle) + { + this(overrideResourceBundle); + setReference(reference); } /** * Construct a new {@link PrettyTime} instance that will always use the current value of - * {@link System#currentTimeMillis()} to represent the reference point for {@link Date} comparison. This instance + * {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. This instance * will use the given {@link Locale} instead of the system default. If the provided {@link Locale} is * null, {@link Locale#getDefault()} will be used. */ public PrettyTime(final Locale locale) { - this(); - setLocale(locale); + this(locale, null); } /** * Construct a new {@link PrettyTime} instance that will always use the current value of - * {@link System#currentTimeMillis()} to represent the reference point for {@link Date} comparison. This instance + * {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. This instance * will use the given {@link Locale} instead of the system default. If the provided {@link Locale} is * null, {@link Locale#getDefault()} will be used. Will use {@link String} as an optional override to * the default resource bundles. */ - public PrettyTime(final Locale locale, String overrideResourceBundle) + public PrettyTime(final Locale locale, final String overrideResourceBundle) { this(overrideResourceBundle); setLocale(locale); @@ -286,32 +341,235 @@ public PrettyTime(final Locale locale, String overrideResourceBundle) /** * Construct a new {@link PrettyTime} instance that will use the given {@link Date} timestamp to represent the - * reference point for {@link Date} comparison, and will use the given {@link Locale} instead of the system default. + * reference point for {@link Instant} comparison, and will use the given {@link Locale} instead of the system default. *

* If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
* If the given {@link Date} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Date} comparison. - *

- * See {@code PrettyTime#setReference(Date timestamp)}. + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. + * + * @see #setReference(Date) */ public PrettyTime(final Date reference, final Locale locale) { - this(locale); - setReference(reference); + this(reference, locale, null); } /** * Construct a new {@link PrettyTime} instance that will use the given {@link Date} timestamp to represent the - * reference point for {@link Date} comparison, and will use the given {@link Locale} instead of the system default. + * reference point for {@link Instant} comparison, and will use the given {@link Locale} instead of the system default. *

* If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
* If the given {@link Date} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Date} comparison. Will - * use {@link String} as an optional override to the default resource bundles. + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. + * Will use {@link String} as an optional override to the default resource bundles. + * + * @see #setReference(Date) + */ + public PrettyTime(final Date reference, final Locale locale, final String overrideResourceBundle) + { + this(locale, overrideResourceBundle); + setReference(reference); + } + + /** + * Construct a new {@link PrettyTime} instance that will use the given {@link Instant} timestamp to represent the + * reference point for {@link Instant} comparison, and will use the given {@link Locale} instead of the system default. + *

+ * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
+ * If the given {@link LocalDate} is null, this instance will always use current value of + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. + * + * @see #setReference(LocalDate) + */ + public PrettyTime(final Instant reference, final Locale locale) + { + this(reference, locale, null); + } + + /** + * Construct a new {@link PrettyTime} instance that will use the given {@link Instant} timestamp to represent the + * reference point for {@link Instant} comparison, and will use the given {@link Locale} instead of the system default. + *

+ * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
+ * If the given {@link Instant} is null, this instance will always use current value of + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. + * Will use {@link String} as an optional override to the default resource bundles. + * + * @see #setReference(Instant) + */ + public PrettyTime(final Instant reference, final Locale locale, final String overrideResourceBundle) + { + this(locale, overrideResourceBundle); + setReference(reference); + } + + /** + * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDate} with the system default + * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use the given + * {@link Locale} instead of the system default. + *

+ * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
+ * If the given {@link LocalDate} is null, this instance will always use current value of + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. + * + * @see #setReference(LocalDate) + */ + public PrettyTime(final LocalDate reference, final Locale locale) + { + this(reference, ZoneId.systemDefault(), locale); + } + + /** + * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDate} with the given {@link ZoneId} + * to represent the reference point for {@link Instant} comparison, and will use the given {@link Locale} instead of + * the system default. + *

+ * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
+ * If the given {@link LocalDate} is null, this instance will always use current value of + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. + * + * @see #setReference(LocalDate) + */ + public PrettyTime(final LocalDate reference, final ZoneId zoneId, final Locale locale) + { + this(locale); + setReference(reference, zoneId); + } + + /** + * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDate} with the system default + * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use the given + * {@link Locale} instead of the system default. *

- * See {@code PrettyTime#setReference(Date timestamp)}. + * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
+ * If the given {@link LocalDate} is null, this instance will always use current value of + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. + * Will use {@link String} as an optional override to the default resource bundles. + * + * @see #setReference(LocalDate) */ - public PrettyTime(final Date reference, final Locale locale, String overrideResourceBundle) + public PrettyTime(final LocalDate reference, final Locale locale, final String overrideResourceBundle) + { + this(reference, ZoneId.systemDefault(), locale, overrideResourceBundle); + } + + /** + * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDate} with the given {@link ZoneId} + * to represent the reference point for {@link Instant} comparison, and will use the given {@link Locale} instead of + * the system default. + *

+ * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
+ * If the given {@link LocalDate} is null, this instance will always use current value of + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. + * Will use {@link String} as an optional override to the default resource bundles. + * + * @see #setReference(LocalDate) + */ + public PrettyTime(final LocalDate reference, final ZoneId zoneId, final Locale locale, + final String overrideResourceBundle) + { + this(locale, overrideResourceBundle); + setReference(reference, zoneId); + } + + /** + * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDateTime} with the system default + * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use the given + * {@link Locale} instead of the system default. + *

+ * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
+ * If the given {@link LocalDateTime} is null, this instance will always use current value of + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. + * + * @see #setReference(LocalDateTime) + */ + public PrettyTime(final LocalDateTime reference, final Locale locale) + { + this(reference, ZoneId.systemDefault(), locale); + } + + /** + * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDateTime} with the given + * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use the given + * {@link Locale} instead of the system default. + *

+ * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
+ * If the given {@link LocalDateTime} is null, this instance will always use current value of + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. + * + * @see #setReference(LocalDateTime) + */ + public PrettyTime(final LocalDateTime reference, final ZoneId zoneId, final Locale locale) + { + this(locale); + setReference(reference, zoneId); + } + + /** + * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDateTime} with the system default + * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use the given + * {@link Locale} instead of the system default. + *

+ * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
+ * If the given {@link LocalDateTime} is null, this instance will always use current value of + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. + * Will use {@link String} as an optional override to the default resource bundles. + * + * @see #setReference(LocalDateTime) + */ + public PrettyTime(final LocalDateTime reference, final Locale locale, final String overrideResourceBundle) + { + this(reference, ZoneId.systemDefault(), locale, overrideResourceBundle); + } + + /** + * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDateTime} with the system default + * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use the given + * {@link Locale} instead of the system default. + *

+ * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
+ * If the given {@link LocalDateTime} is null, this instance will always use current value of + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. + * Will use {@link String} as an optional override to the default resource bundles. + * + * @see #setReference(LocalDateTime) + */ + public PrettyTime(final LocalDateTime reference, final ZoneId zoneId, final Locale locale, + final String overrideResourceBundle) + { + this(locale, overrideResourceBundle); + setReference(reference, zoneId); + } + + /** + * Construct a new {@link PrettyTime} instance that will use the given {@link OffsetDateTime} to represent the reference + * point for {@link Instant} comparison, and will use the given {@link Locale} instead of the system default. + *

+ * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
+ * If the given {@link OffsetDateTime} is null, this instance will always use current value of + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. + * Will use {@link String} as an optional override to the default resource bundles. + * + * @see #setReference(OffsetDateTime) + */ + public PrettyTime(final OffsetDateTime reference, final Locale locale, final String overrideResourceBundle) + { + this(locale, overrideResourceBundle); + setReference(reference); + } + + /** + * Construct a new {@link PrettyTime} instance that will use the given {@link ZonedDateTime} to represent the reference + * point for {@link Instant} comparison, and will use the given {@link Locale} instead of the system default. + *

+ * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
+ * If the given {@link ZonedDateTime} is null, this instance will always use current value of + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. + * Will use {@link String} as an optional override to the default resource bundles. + * + * @see #setReference(ZonedDateTime) + */ + public PrettyTime(final ZonedDateTime reference, final Locale locale, final String overrideResourceBundle) { this(locale, overrideResourceBundle); setReference(reference); @@ -1389,7 +1647,7 @@ public PrettyTime setReference(final LocalDateTime localDateTime) */ public PrettyTime setReference(final LocalDateTime localDateTime, final ZoneId zoneId) { - return setReference(localDateTime != null ? localDateTime.atZone(zoneId).toInstant() : null); + return setReference(localDateTime != null ? localDateTime.atZone(zoneId) : null); } /** @@ -1405,7 +1663,7 @@ public PrettyTime setReference(final LocalDateTime localDateTime, final ZoneId z */ public PrettyTime setReference(final LocalDate localDate) { - return setReference(localDate != null ? localDate.atStartOfDay() : null); + return setReference(localDate, ZoneId.systemDefault()); } /** @@ -1421,7 +1679,37 @@ public PrettyTime setReference(final LocalDate localDate) */ public PrettyTime setReference(final LocalDate localDate, final ZoneId zoneId) { - return setReference(localDate != null ? localDate.atStartOfDay(zoneId).toInstant() : null); + return setReference(localDate != null ? localDate.atStartOfDay(zoneId) : null); + } + + /** + * Converts the given {@link OffsetDateTime} to the reference {@link Instant}. If null, {@link PrettyTime} + * will always use the current value of {@link System#currentTimeMillis()} as the reference {@link Instant}. + *

+ * If the {@link Instant} formatted is before the reference {@link Instant}, the format command will produce a + * {@link String} that is in the past tense. If the {@link Instant} formatted is after the reference {@link Instant}, + * the format command will produce a {@link String} that is in the future tense. + * + * @see #setReference(Instant) + */ + public PrettyTime setReference(final OffsetDateTime offsetDateTime) + { + return setReference(offsetDateTime != null ? offsetDateTime.toInstant() : null); + } + + /** + * Converts the given {@link ZonedDateTime} to the reference {@link Instant}. If null, {@link PrettyTime} + * will always use the current value of {@link System#currentTimeMillis()} as the reference {@link Instant}. + *

+ * If the {@link Instant} formatted is before the reference {@link Instant}, the format command will produce a + * {@link String} that is in the past tense. If the {@link Instant} formatted is after the reference {@link Instant}, + * the format command will produce a {@link String} that is in the future tense. + * + * @see #setReference(Instant) + */ + public PrettyTime setReference(final ZonedDateTime zonedDateTime) + { + return setReference(zonedDateTime != null ? zonedDateTime.toInstant() : null); } /** diff --git a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java index 48488b05..32dd7c0b 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java +++ b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java @@ -16,11 +16,11 @@ public class ResourcesTimeFormat extends SimpleTimeFormat { private final ResourcesTimeUnit unit; private TimeFormat override; - private String overrideResourceBundle; // If used this bundle will override the included bundle + private final String overrideResourceBundle; // If used this bundle will override the included bundle public ResourcesTimeFormat(ResourcesTimeUnit unit) { - this.unit = unit; + this(unit, null); } public ResourcesTimeFormat(ResourcesTimeUnit unit, String overrideResourceBundle) diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeOverrideBundleTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeOverrideBundleTest.java index 59eed7e5..0e90e0c8 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeOverrideBundleTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeOverrideBundleTest.java @@ -20,7 +20,7 @@ import org.junit.Before; import org.junit.Test; -import java.util.Date; +import java.time.LocalDateTime; import java.util.Locale; public class PrettyTimeOverrideBundleTest @@ -37,9 +37,10 @@ public void setUp() throws Exception @Test public void testHoursAgo() throws Exception { - PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), Locale.ENGLISH, + final LocalDateTime now = LocalDateTime.now(); + PrettyTime t = new PrettyTime(now, Locale.ENGLISH, "org.ocpsoft.prettytime.i18n.override.Resources"); - Assert.assertEquals("3 hours ago override", t.format(new Date(0))); + Assert.assertEquals("3 hours ago override", t.format(now.minusHours(3))); } @After @@ -47,5 +48,4 @@ public void tearDown() throws Exception { Locale.setDefault(locale); } - } From 12e5dedecba61ae87e53e53f605c2e7e43890647 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Tue, 22 Dec 2020 07:46:32 +0530 Subject: [PATCH 071/147] Move method implementations from methods that accept Date to their equivalents that accept Instant. --- .../org/ocpsoft/prettytime/PrettyTime.java | 78 ++++++++----------- 1 file changed, 34 insertions(+), 44 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index f4db0dbc..57cbc38c 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -21,6 +21,7 @@ import java.time.OffsetDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; @@ -64,7 +65,7 @@ * //result: 10 minutes from now * *

- * + * * @author Lincoln Baxter, III */ public class PrettyTime @@ -581,17 +582,9 @@ public PrettyTime(final ZonedDateTime reference, final Locale locale, final Stri * * @see #getReference() */ - public Duration approximateDuration(Date then) + public Duration approximateDuration(final Date then) { - if (then == null) - then = now(); - - final Instant ref = reference != null ? reference : Instant.now(); - long difference = then.getTime() - ref.toEpochMilli(); - if (difference == 0) { - difference = 1; - } - return calculateDuration(difference); + return approximateDuration(then != null ? then.toInstant() : null); } /** @@ -601,9 +594,11 @@ public Duration approximateDuration(Date then) * * @see #getReference() */ - public Duration approximateDuration(Instant then) + public Duration approximateDuration(final Instant then) { - return approximateDuration(then != null ? Date.from(then) : null); + long difference = ChronoUnit.MILLIS.between(then != null ? then : Instant.now(), + reference != null ? reference : Instant.now()); + return calculateDuration(difference != 0 ? difference : 1); } /** @@ -613,9 +608,9 @@ public Duration approximateDuration(Instant then) * * @see #getReference() */ - public Duration approximateDuration(LocalDate then) + public Duration approximateDuration(final LocalDate then) { - return approximateDuration(then != null ? then.atStartOfDay(ZoneId.systemDefault()).toInstant() : null); + return approximateDuration(then, ZoneId.systemDefault()); } /** @@ -628,9 +623,9 @@ public Duration approximateDuration(LocalDate then) * @param zoneId The {@link ZoneId} to be used, not null * @see #getReference() */ - public Duration approximateDuration(LocalDate then, final ZoneId zoneId) + public Duration approximateDuration(final LocalDate then, final ZoneId zoneId) { - return approximateDuration(then != null ? then.atStartOfDay(ZoneId.systemDefault()).toInstant() : null); + return approximateDuration(then != null ? then.atStartOfDay(zoneId).toInstant() : null); } /** @@ -642,9 +637,9 @@ public Duration approximateDuration(LocalDate then, final ZoneId zoneId) * timestamp was provided * @see #getReference() */ - public Duration approximateDuration(LocalDateTime then) + public Duration approximateDuration(final LocalDateTime then) { - return approximateDuration(then != null ? then.atZone(ZoneId.systemDefault()).toInstant() : null); + return approximateDuration(then, ZoneId.systemDefault()); } /** @@ -657,7 +652,7 @@ public Duration approximateDuration(LocalDateTime then) * @param zoneId The {@link ZoneId} to be used, not null * @see #getReference() */ - public Duration approximateDuration(LocalDateTime then, final ZoneId zoneId) + public Duration approximateDuration(final LocalDateTime then, final ZoneId zoneId) { return approximateDuration(then != null ? then.atZone(zoneId).toInstant() : null); } @@ -669,7 +664,7 @@ public Duration approximateDuration(LocalDateTime then, final ZoneId zoneId) *

* Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder * of time (in milliseconds). - * + * * @param then The {@link Date} to be compared against the reference timestamp, or now if no reference * timestamp was provided * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list @@ -679,28 +674,7 @@ public Duration approximateDuration(LocalDateTime then, final ZoneId zoneId) */ public List calculatePreciseDuration(Date then) { - if (then == null) - then = now(); - - final Instant reference = this.reference != null ? this.reference : Instant.now(); - - List result = new ArrayList<>(); - long difference = then.getTime() - reference.toEpochMilli(); - Duration duration = calculateDuration(difference); - result.add(duration); - while (0 != duration.getDelta()) { - duration = calculateDuration(duration.getDelta()); - if (!result.isEmpty()) { - Duration last = result.get(result.size() - 1); - if (last.getUnit().equals(duration.getUnit())) { - break; - } - } - - if (duration.getUnit().isPrecise()) - result.add(duration); - } - return result; + return calculatePreciseDuration(then != null ? then.toInstant() : null); } /** @@ -720,7 +694,23 @@ public List calculatePreciseDuration(Date then) */ public List calculatePreciseDuration(final Instant then) { - return calculatePreciseDuration(then != null ? Date.from(then) : null); + List result = new ArrayList<>(); + Duration duration = calculateDuration(ChronoUnit.MILLIS.between(then != null ? then : Instant.now(), + reference != null ? reference : Instant.now())); + result.add(duration); + while (0 != duration.getDelta()) { + duration = calculateDuration(duration.getDelta()); + if (!result.isEmpty()) { + Duration last = result.get(result.size() - 1); + if (last.getUnit().equals(duration.getUnit())) { + break; + } + } + + if (duration.getUnit().isPrecise()) + result.add(duration); + } + return result; } /** From 4d893ae0949b97ece8d440a4a15fc5e0a4813322 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Tue, 22 Dec 2020 08:03:43 +0530 Subject: [PATCH 072/147] Remove the private now() method. --- .../org/ocpsoft/prettytime/PrettyTime.java | 81 ++++++------------- 1 file changed, 26 insertions(+), 55 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index 57cbc38c..5fc3220a 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -808,11 +808,7 @@ public List calculatePreciseDuration(final LocalDate then, final ZoneI */ public String format(Date then) { - if (then == null) - then = now(); - - Duration d = approximateDuration(then); - return format(d); + return format(approximateDuration(then != null ? then.toInstant() : Instant.now())); } /** @@ -824,9 +820,7 @@ public String format(Date then) */ public String format(Calendar then) { - if (then == null) - return format(now()); - return format(then.getTime()); + return format(then != null ? then.toInstant() : Instant.now()); } /** @@ -840,7 +834,7 @@ public String format(Calendar then) public String format(final Duration duration) { if (duration == null) - return format(now()); + return format(Instant.now()); TimeFormat format = getFormat(duration.getUnit()); String time = format.format(duration); @@ -859,7 +853,7 @@ public String format(final Duration duration) public String format(final List durations) { if (durations == null || durations.isEmpty()) - return format(now()); + return format(Instant.now()); StringBuilder result = new StringBuilder(); @@ -983,13 +977,9 @@ public String format(final LocalDate then) * @param then the {@link Date} to be formatted * @return A formatted string representing {@code then} */ - public String formatUnrounded(Date then) + public String formatUnrounded(final Date then) { - if (then == null) - then = now(); - - Duration d = approximateDuration(then); - return formatUnrounded(d); + return formatUnrounded(then != null ? then.toInstant() : Instant.now()); } /** @@ -1002,9 +992,7 @@ public String formatUnrounded(Date then) */ public String formatUnrounded(Calendar then) { - if (then == null) - return formatUnrounded(now()); - return formatUnrounded(then.getTime()); + return formatUnrounded(then != null ? then.toInstant() : Instant.now()); } /** @@ -1018,7 +1006,7 @@ public String formatUnrounded(Calendar then) public String formatUnrounded(Duration duration) { if (duration == null) - return formatUnrounded(now()); + return formatUnrounded(Instant.now()); TimeFormat format = getFormat(duration.getUnit()); String time = format.formatUnrounded(duration); @@ -1036,7 +1024,7 @@ public String formatUnrounded(Duration duration) public String formatUnrounded(List durations) { if (durations == null || durations.isEmpty()) - return format(now()); + return format(Instant.now()); StringBuilder result = new StringBuilder(); @@ -1161,10 +1149,9 @@ public String formatUnrounded(final LocalDate then) * @param then the date to be formatted * @return A formatted string of the given {@link Date} */ - public String formatDuration(Date then) + public String formatDuration(final Date then) { - Duration duration = approximateDuration(then); - return formatDuration(duration); + return formatDuration(approximateDuration(then)); } /** @@ -1177,13 +1164,10 @@ public String formatDuration(Date then) * @param then the date to be formatted * @return A formatted string of the given {@link Date} */ - public String formatDuration(Calendar then) + public String formatDuration(final Calendar then) { - if (then == null) - return formatDuration(now()); - - Duration duration = approximateDuration(then.getTime()); - return formatDuration(duration); + return then == null ? formatDuration(Instant.now()) : + formatDuration(approximateDuration(then.toInstant())); } /** @@ -1198,7 +1182,7 @@ public String formatDuration(Calendar then) public String formatDuration(Duration duration) { if (duration == null) - return format(now()); + return format(Instant.now()); TimeFormat timeFormat = getFormat(duration.getUnit()); return timeFormat.format(duration); @@ -1216,12 +1200,12 @@ public String formatDuration(Duration duration) public String formatDuration(final List durations) { if (durations == null || durations.isEmpty()) - return format(now()); + return format(Instant.now()); StringBuilder result = new StringBuilder(); - Duration duration = null; - TimeFormat format = null; + Duration duration; + TimeFormat format; for (int i = 0; i < durations.size(); i++) { duration = durations.get(i); format = getFormat(duration.getUnit()); @@ -1363,8 +1347,7 @@ public String formatDuration(final LocalDate then) */ public String formatDurationUnrounded(Date then) { - Duration duration = approximateDuration(then); - return formatDurationUnrounded(duration); + return formatDurationUnrounded(approximateDuration(then)); } /** @@ -1377,13 +1360,10 @@ public String formatDurationUnrounded(Date then) * @param then the date to be formatted * @return A formatted string of the given {@link Date} */ - public String formatDurationUnrounded(Calendar then) + public String formatDurationUnrounded(final Calendar then) { - if (then == null) - return formatDuration(now()); - - Duration duration = approximateDuration(then.getTime()); - return formatDurationUnrounded(duration); + return then == null ? formatDuration(Instant.now()) : + formatDurationUnrounded(approximateDuration(then.toInstant())); } /** @@ -1397,11 +1377,7 @@ public String formatDurationUnrounded(Calendar then) */ public String formatDurationUnrounded(Duration duration) { - if (duration == null) - return format(now()); - - TimeFormat timeFormat = getFormat(duration.getUnit()); - return timeFormat.formatUnrounded(duration); + return duration == null ? format(Instant.now()) : getFormat(duration.getUnit()).formatUnrounded(duration); } /** @@ -1416,11 +1392,11 @@ public String formatDurationUnrounded(Duration duration) public String formatDurationUnrounded(final List durations) { if (durations == null || durations.isEmpty()) - return format(now()); + return format(Instant.now()); StringBuilder result = new StringBuilder(); - Duration duration = null; - TimeFormat format = null; + Duration duration; + TimeFormat format; for (int i = 0; i < durations.size(); i++) { duration = durations.get(i); format = getFormat(duration.getUnit()); @@ -1869,11 +1845,6 @@ public List clearUnits() /* * Internal methods. */ - private Date now() - { - return new Date(); - } - private void initTimeUnits() { addUnit(new JustNow()); From 5eca0e69203a3d1b262379275d6f8d4fcbaae1c0 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Mon, 4 Jan 2021 11:14:06 -0500 Subject: [PATCH 073/147] Revert "Make further java.time changes." --- .../org/ocpsoft/prettytime/PrettyTime.java | 519 +++++------------- .../prettytime/impl/ResourcesTimeFormat.java | 4 +- .../PrettyTimeOverrideBundleTest.java | 8 +- 3 files changed, 141 insertions(+), 390 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index d6fd1346..21bd3a61 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -21,7 +21,6 @@ import java.time.OffsetDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; -import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; @@ -66,7 +65,7 @@ * //result: 10 minutes from now * *

- * + * * @author Lincoln Baxter, III */ public class PrettyTime @@ -75,7 +74,7 @@ public class PrettyTime private volatile Locale locale = Locale.getDefault(); private final Map units = new ConcurrentHashMap<>(); private volatile List cachedUnits; - private final String overrideResourceBundle; + private String overrideResourceBundle; /** * Create a new {@link PrettyTime} instance that will always use the current value of @@ -89,7 +88,7 @@ public PrettyTime() /** * Create a new {@link PrettyTime} instance that will always use the current value of - * {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison, and will use + * {@link System#currentTimeMillis()} to represent the reference point for {@link Date} comparison, and will use * {@link Locale#getDefault()} as the selected {@link Locale} for language and dialect formatting. Will use * {@link String} as an optional override to the default resource bundles. */ @@ -101,20 +100,21 @@ public PrettyTime(final String overrideResourceBundle) /** * Create a new {@link PrettyTime} instance that will use the given {@link Date} timestamp to represent the reference - * point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected {@link Locale} for + * point for {@link Date} comparison, and will use {@link Locale#getDefault()} as the selected {@link Locale} for * language and dialect formatting. If the given {@link Date} is null, this instance will always use the - * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. + * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Date} comparison. */ public PrettyTime(final Date reference) { - this(reference, (String) null); + this(); + setReference(reference); } /** * Create a new {@link PrettyTime} instance that will use the given {@link Date} timestamp to represent the reference - * point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected {@link Locale} for + * point for {@link Date} comparison, and will use {@link Locale#getDefault()} as the selected {@link Locale} for * language and dialect formatting. If the given {@link Date} is null, this instance will always use the - * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. + * current value of {@link System#currentTimeMillis()} to represent the reference point for {@link Date} comparison. * Will use {@link String} as an optional override to the default resource bundles. * * @see #PrettyTime(Date). @@ -134,7 +134,8 @@ public PrettyTime(final Date reference, final String overrideResourceBundle) */ public PrettyTime(final Instant reference) { - this(reference, (String) null); + this(); + setReference(reference); } /** @@ -188,7 +189,7 @@ public PrettyTime(final LocalDateTime reference, final String overrideResourceBu */ public PrettyTime(final LocalDateTime reference, final ZoneId zoneId) { - this(reference, zoneId, (String) null); + this(reference, zoneId, null); } /** @@ -203,7 +204,7 @@ public PrettyTime(final LocalDateTime reference, final ZoneId zoneId) */ public PrettyTime(final LocalDateTime reference, final ZoneId zoneId, final String overrideResourceBundle) { - this(reference != null ? reference.atZone(zoneId) : null, overrideResourceBundle); + this(reference != null ? reference.atZone(zoneId).toInstant() : null, overrideResourceBundle); } /** @@ -215,7 +216,7 @@ public PrettyTime(final LocalDateTime reference, final ZoneId zoneId, final Stri */ public PrettyTime(final LocalDate reference) { - this(reference, (String) null); + this(reference, ZoneId.systemDefault(), null); } /** @@ -242,13 +243,13 @@ public PrettyTime(final LocalDate reference, final String overrideResourceBundle */ public PrettyTime(final LocalDate reference, final ZoneId zoneId) { - this(reference, zoneId, (String) null); + this(reference, zoneId, null); } /** - * Create a new {@link PrettyTime} instance that will use the given {@link LocalDate} to represent the + * Create a new {@link PrettyTime} instance that will use the given {@link Instant} timestamp to represent the * reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected - * {@link Locale} for language and dialect formatting. If the given {@link LocalDate} is null, this + * {@link Locale} for language and dialect formatting. If the given {@link Instant} is null, this * instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference point * for {@link Instant} comparison. Will use {@link String} as an optional override to the default resource bundles. * @@ -256,86 +257,29 @@ public PrettyTime(final LocalDate reference, final ZoneId zoneId) */ public PrettyTime(final LocalDate reference, final ZoneId zoneId, final String overrideResourceBundle) { - this(reference != null ? reference.atStartOfDay(zoneId) : null, overrideResourceBundle); - } - - /** - * Create a new {@link PrettyTime} instance that will use the given {@link OffsetDateTime} to represent the - * reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected - * {@link Locale} for language and dialect formatting. If the given {@link OffsetDateTime} is null, this - * instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference point - * for {@link Instant} comparison. - * - * @see #PrettyTime(Instant) - */ - public PrettyTime(final OffsetDateTime reference) - { - this(reference, null); - } - - /** - * Create a new {@link PrettyTime} instance that will use the given {@link OffsetDateTime} to represent the - * reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected - * {@link Locale} for language and dialect formatting. If the given {@link OffsetDateTime} is null, this - * instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference point - * for {@link Instant} comparison. Will use {@link String} as an optional override to the default resource bundles. - * - * @see #PrettyTime(Instant) - */ - public PrettyTime(final OffsetDateTime reference, final String overrideResourceBundle) - { - this(overrideResourceBundle); - setReference(reference); - } - - /** - * Create a new {@link PrettyTime} instance that will use the given {@link ZonedDateTime} to represent the - * reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected - * {@link Locale} for language and dialect formatting. If the given {@link ZonedDateTime} is null, this - * instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference point - * for {@link Instant} comparison. Will use {@link String} as an optional override to the default resource bundles. - * - * @see #PrettyTime(Instant) - */ - public PrettyTime(final ZonedDateTime reference) - { - this(reference, null); - } - - /** - * Create a new {@link PrettyTime} instance that will use the given {@link ZonedDateTime} to represent the - * reference point for {@link Instant} comparison, and will use {@link Locale#getDefault()} as the selected - * {@link Locale} for language and dialect formatting. If the given {@link ZonedDateTime} is null, this - * instance will always use the current value of {@link System#currentTimeMillis()} to represent the reference point - * for {@link Instant} comparison. Will use {@link String} as an optional override to the default resource bundles. - * - * @see #PrettyTime(Instant) - */ - public PrettyTime(final ZonedDateTime reference, final String overrideResourceBundle) - { - this(overrideResourceBundle); - setReference(reference); + this(reference != null ? reference.atStartOfDay(zoneId).toInstant() : null, overrideResourceBundle); } /** * Construct a new {@link PrettyTime} instance that will always use the current value of - * {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. This instance + * {@link System#currentTimeMillis()} to represent the reference point for {@link Date} comparison. This instance * will use the given {@link Locale} instead of the system default. If the provided {@link Locale} is * null, {@link Locale#getDefault()} will be used. */ public PrettyTime(final Locale locale) { - this(locale, null); + this(); + setLocale(locale); } /** * Construct a new {@link PrettyTime} instance that will always use the current value of - * {@link System#currentTimeMillis()} to represent the reference point for {@link Instant} comparison. This instance + * {@link System#currentTimeMillis()} to represent the reference point for {@link Date} comparison. This instance * will use the given {@link Locale} instead of the system default. If the provided {@link Locale} is * null, {@link Locale#getDefault()} will be used. Will use {@link String} as an optional override to * the default resource bundles. */ - public PrettyTime(final Locale locale, final String overrideResourceBundle) + public PrettyTime(final Locale locale, String overrideResourceBundle) { this(overrideResourceBundle); setLocale(locale); @@ -343,235 +287,32 @@ public PrettyTime(final Locale locale, final String overrideResourceBundle) /** * Construct a new {@link PrettyTime} instance that will use the given {@link Date} timestamp to represent the - * reference point for {@link Instant} comparison, and will use the given {@link Locale} instead of the system default. + * reference point for {@link Date} comparison, and will use the given {@link Locale} instead of the system default. *

* If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
* If the given {@link Date} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. - * - * @see #setReference(Date) + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Date} comparison. + *

+ * See {@code PrettyTime#setReference(Date timestamp)}. */ public PrettyTime(final Date reference, final Locale locale) { - this(reference, locale, null); + this(locale); + setReference(reference); } /** * Construct a new {@link PrettyTime} instance that will use the given {@link Date} timestamp to represent the - * reference point for {@link Instant} comparison, and will use the given {@link Locale} instead of the system default. + * reference point for {@link Date} comparison, and will use the given {@link Locale} instead of the system default. *

* If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
* If the given {@link Date} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. - * Will use {@link String} as an optional override to the default resource bundles. - * - * @see #setReference(Date) - */ - public PrettyTime(final Date reference, final Locale locale, final String overrideResourceBundle) - { - this(locale, overrideResourceBundle); - setReference(reference); - } - - /** - * Construct a new {@link PrettyTime} instance that will use the given {@link Instant} timestamp to represent the - * reference point for {@link Instant} comparison, and will use the given {@link Locale} instead of the system default. + * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Date} comparison. Will + * use {@link String} as an optional override to the default resource bundles. *

- * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
- * If the given {@link LocalDate} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. - * - * @see #setReference(LocalDate) + * See {@code PrettyTime#setReference(Date timestamp)}. */ - public PrettyTime(final Instant reference, final Locale locale) - { - this(reference, locale, null); - } - - /** - * Construct a new {@link PrettyTime} instance that will use the given {@link Instant} timestamp to represent the - * reference point for {@link Instant} comparison, and will use the given {@link Locale} instead of the system default. - *

- * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
- * If the given {@link Instant} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. - * Will use {@link String} as an optional override to the default resource bundles. - * - * @see #setReference(Instant) - */ - public PrettyTime(final Instant reference, final Locale locale, final String overrideResourceBundle) - { - this(locale, overrideResourceBundle); - setReference(reference); - } - - /** - * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDate} with the system default - * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use the given - * {@link Locale} instead of the system default. - *

- * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
- * If the given {@link LocalDate} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. - * - * @see #setReference(LocalDate) - */ - public PrettyTime(final LocalDate reference, final Locale locale) - { - this(reference, ZoneId.systemDefault(), locale); - } - - /** - * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDate} with the given {@link ZoneId} - * to represent the reference point for {@link Instant} comparison, and will use the given {@link Locale} instead of - * the system default. - *

- * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
- * If the given {@link LocalDate} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. - * - * @see #setReference(LocalDate) - */ - public PrettyTime(final LocalDate reference, final ZoneId zoneId, final Locale locale) - { - this(locale); - setReference(reference, zoneId); - } - - /** - * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDate} with the system default - * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use the given - * {@link Locale} instead of the system default. - *

- * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
- * If the given {@link LocalDate} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. - * Will use {@link String} as an optional override to the default resource bundles. - * - * @see #setReference(LocalDate) - */ - public PrettyTime(final LocalDate reference, final Locale locale, final String overrideResourceBundle) - { - this(reference, ZoneId.systemDefault(), locale, overrideResourceBundle); - } - - /** - * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDate} with the given {@link ZoneId} - * to represent the reference point for {@link Instant} comparison, and will use the given {@link Locale} instead of - * the system default. - *

- * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
- * If the given {@link LocalDate} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. - * Will use {@link String} as an optional override to the default resource bundles. - * - * @see #setReference(LocalDate) - */ - public PrettyTime(final LocalDate reference, final ZoneId zoneId, final Locale locale, - final String overrideResourceBundle) - { - this(locale, overrideResourceBundle); - setReference(reference, zoneId); - } - - /** - * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDateTime} with the system default - * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use the given - * {@link Locale} instead of the system default. - *

- * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
- * If the given {@link LocalDateTime} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. - * - * @see #setReference(LocalDateTime) - */ - public PrettyTime(final LocalDateTime reference, final Locale locale) - { - this(reference, ZoneId.systemDefault(), locale); - } - - /** - * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDateTime} with the given - * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use the given - * {@link Locale} instead of the system default. - *

- * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
- * If the given {@link LocalDateTime} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. - * - * @see #setReference(LocalDateTime) - */ - public PrettyTime(final LocalDateTime reference, final ZoneId zoneId, final Locale locale) - { - this(locale); - setReference(reference, zoneId); - } - - /** - * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDateTime} with the system default - * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use the given - * {@link Locale} instead of the system default. - *

- * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
- * If the given {@link LocalDateTime} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. - * Will use {@link String} as an optional override to the default resource bundles. - * - * @see #setReference(LocalDateTime) - */ - public PrettyTime(final LocalDateTime reference, final Locale locale, final String overrideResourceBundle) - { - this(reference, ZoneId.systemDefault(), locale, overrideResourceBundle); - } - - /** - * Construct a new {@link PrettyTime} instance that will use the given {@link LocalDateTime} with the system default - * {@link ZoneId} to represent the reference point for {@link Instant} comparison, and will use the given - * {@link Locale} instead of the system default. - *

- * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
- * If the given {@link LocalDateTime} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. - * Will use {@link String} as an optional override to the default resource bundles. - * - * @see #setReference(LocalDateTime) - */ - public PrettyTime(final LocalDateTime reference, final ZoneId zoneId, final Locale locale, - final String overrideResourceBundle) - { - this(locale, overrideResourceBundle); - setReference(reference, zoneId); - } - - /** - * Construct a new {@link PrettyTime} instance that will use the given {@link OffsetDateTime} to represent the reference - * point for {@link Instant} comparison, and will use the given {@link Locale} instead of the system default. - *

- * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
- * If the given {@link OffsetDateTime} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. - * Will use {@link String} as an optional override to the default resource bundles. - * - * @see #setReference(OffsetDateTime) - */ - public PrettyTime(final OffsetDateTime reference, final Locale locale, final String overrideResourceBundle) - { - this(locale, overrideResourceBundle); - setReference(reference); - } - - /** - * Construct a new {@link PrettyTime} instance that will use the given {@link ZonedDateTime} to represent the reference - * point for {@link Instant} comparison, and will use the given {@link Locale} instead of the system default. - *

- * If the provided {@link Locale} is null, {@link Locale#getDefault()} will be used instead.
- * If the given {@link ZonedDateTime} is null, this instance will always use current value of - * {@link System#currentTimeMillis()} will be used to represent the reference point for {@link Instant} comparison. - * Will use {@link String} as an optional override to the default resource bundles. - * - * @see #setReference(ZonedDateTime) - */ - public PrettyTime(final ZonedDateTime reference, final Locale locale, final String overrideResourceBundle) + public PrettyTime(final Date reference, final Locale locale, String overrideResourceBundle) { this(locale, overrideResourceBundle); setReference(reference); @@ -583,9 +324,17 @@ public PrettyTime(final ZonedDateTime reference, final Locale locale, final Stri * * @see #getReference() */ - public Duration approximateDuration(final Date then) + public Duration approximateDuration(Date then) { - return approximateDuration(then != null ? then.toInstant() : null); + if (then == null) + then = now(); + + final Instant ref = reference != null ? reference : Instant.now(); + long difference = then.getTime() - ref.toEpochMilli(); + if (difference == 0) { + difference = 1; + } + return calculateDuration(difference); } /** @@ -595,11 +344,9 @@ public Duration approximateDuration(final Date then) * * @see #getReference() */ - public Duration approximateDuration(final Instant then) + public Duration approximateDuration(Instant then) { - long difference = ChronoUnit.MILLIS.between(then != null ? then : Instant.now(), - reference != null ? reference : Instant.now()); - return calculateDuration(difference != 0 ? difference : 1); + return approximateDuration(then != null ? Date.from(then) : null); } /** @@ -609,9 +356,9 @@ public Duration approximateDuration(final Instant then) * * @see #getReference() */ - public Duration approximateDuration(final LocalDate then) + public Duration approximateDuration(LocalDate then) { - return approximateDuration(then, ZoneId.systemDefault()); + return approximateDuration(then != null ? then.atStartOfDay(ZoneId.systemDefault()).toInstant() : null); } /** @@ -624,9 +371,9 @@ public Duration approximateDuration(final LocalDate then) * @param zoneId The {@link ZoneId} to be used, not null * @see #getReference() */ - public Duration approximateDuration(final LocalDate then, final ZoneId zoneId) + public Duration approximateDuration(LocalDate then, final ZoneId zoneId) { - return approximateDuration(then != null ? then.atStartOfDay(zoneId).toInstant() : null); + return approximateDuration(then != null ? then.atStartOfDay(ZoneId.systemDefault()).toInstant() : null); } /** @@ -638,9 +385,9 @@ public Duration approximateDuration(final LocalDate then, final ZoneId zoneId) * timestamp was provided * @see #getReference() */ - public Duration approximateDuration(final LocalDateTime then) + public Duration approximateDuration(LocalDateTime then) { - return approximateDuration(then, ZoneId.systemDefault()); + return approximateDuration(then != null ? then.atZone(ZoneId.systemDefault()).toInstant() : null); } /** @@ -653,7 +400,7 @@ public Duration approximateDuration(final LocalDateTime then) * @param zoneId The {@link ZoneId} to be used, not null * @see #getReference() */ - public Duration approximateDuration(final LocalDateTime then, final ZoneId zoneId) + public Duration approximateDuration(LocalDateTime then, final ZoneId zoneId) { return approximateDuration(then != null ? then.atZone(zoneId).toInstant() : null); } @@ -665,7 +412,7 @@ public Duration approximateDuration(final LocalDateTime then, final ZoneId zoneI *

* Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder * of time (in milliseconds). - * + * * @param then The {@link Date} to be compared against the reference timestamp, or now if no reference * timestamp was provided * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list @@ -675,7 +422,28 @@ public Duration approximateDuration(final LocalDateTime then, final ZoneId zoneI */ public List calculatePreciseDuration(Date then) { - return calculatePreciseDuration(then != null ? then.toInstant() : null); + if (then == null) + then = now(); + + final Instant reference = this.reference != null ? this.reference : Instant.now(); + + List result = new ArrayList<>(); + long difference = then.getTime() - reference.toEpochMilli(); + Duration duration = calculateDuration(difference); + result.add(duration); + while (0 != duration.getDelta()) { + duration = calculateDuration(duration.getDelta()); + if (!result.isEmpty()) { + Duration last = result.get(result.size() - 1); + if (last.getUnit().equals(duration.getUnit())) { + break; + } + } + + if (duration.getUnit().isPrecise()) + result.add(duration); + } + return result; } /** @@ -695,23 +463,7 @@ public List calculatePreciseDuration(Date then) */ public List calculatePreciseDuration(final Instant then) { - List result = new ArrayList<>(); - Duration duration = calculateDuration(ChronoUnit.MILLIS.between(then != null ? then : Instant.now(), - reference != null ? reference : Instant.now())); - result.add(duration); - while (0 != duration.getDelta()) { - duration = calculateDuration(duration.getDelta()); - if (!result.isEmpty()) { - Duration last = result.get(result.size() - 1); - if (last.getUnit().equals(duration.getUnit())) { - break; - } - } - - if (duration.getUnit().isPrecise()) - result.add(duration); - } - return result; + return calculatePreciseDuration(then != null ? Date.from(then) : null); } /** @@ -809,7 +561,11 @@ public List calculatePreciseDuration(final LocalDate then, final ZoneI */ public String format(Date then) { - return format(approximateDuration(then != null ? then.toInstant() : Instant.now())); + if (then == null) + then = now(); + + Duration d = approximateDuration(then); + return format(d); } /** @@ -821,7 +577,9 @@ public String format(Date then) */ public String format(Calendar then) { - return format(then != null ? then.toInstant() : Instant.now()); + if (then == null) + return format(now()); + return format(then.getTime()); } /** @@ -835,7 +593,7 @@ public String format(Calendar then) public String format(final Duration duration) { if (duration == null) - return format(Instant.now()); + return format(now()); TimeFormat format = getFormat(duration.getUnit()); String time = format.format(duration); @@ -854,7 +612,7 @@ public String format(final Duration duration) public String format(final List durations) { if (durations == null || durations.isEmpty()) - return format(Instant.now()); + return format(now()); StringBuilder result = new StringBuilder(); @@ -978,9 +736,13 @@ public String format(final LocalDate then) * @param then the {@link Date} to be formatted * @return A formatted string representing {@code then} */ - public String formatUnrounded(final Date then) + public String formatUnrounded(Date then) { - return formatUnrounded(then != null ? then.toInstant() : Instant.now()); + if (then == null) + then = now(); + + Duration d = approximateDuration(then); + return formatUnrounded(d); } /** @@ -993,7 +755,9 @@ public String formatUnrounded(final Date then) */ public String formatUnrounded(Calendar then) { - return formatUnrounded(then != null ? then.toInstant() : Instant.now()); + if (then == null) + return formatUnrounded(now()); + return formatUnrounded(then.getTime()); } /** @@ -1007,7 +771,7 @@ public String formatUnrounded(Calendar then) public String formatUnrounded(Duration duration) { if (duration == null) - return formatUnrounded(Instant.now()); + return formatUnrounded(now()); TimeFormat format = getFormat(duration.getUnit()); String time = format.formatUnrounded(duration); @@ -1025,7 +789,7 @@ public String formatUnrounded(Duration duration) public String formatUnrounded(List durations) { if (durations == null || durations.isEmpty()) - return format(Instant.now()); + return format(now()); StringBuilder result = new StringBuilder(); @@ -1150,9 +914,10 @@ public String formatUnrounded(final LocalDate then) * @param then the date to be formatted * @return A formatted string of the given {@link Date} */ - public String formatDuration(final Date then) + public String formatDuration(Date then) { - return formatDuration(approximateDuration(then)); + Duration duration = approximateDuration(then); + return formatDuration(duration); } /** @@ -1165,10 +930,13 @@ public String formatDuration(final Date then) * @param then the date to be formatted * @return A formatted string of the given {@link Date} */ - public String formatDuration(final Calendar then) + public String formatDuration(Calendar then) { - return then == null ? formatDuration(Instant.now()) : - formatDuration(approximateDuration(then.toInstant())); + if (then == null) + return formatDuration(now()); + + Duration duration = approximateDuration(then.getTime()); + return formatDuration(duration); } /** @@ -1183,7 +951,7 @@ public String formatDuration(final Calendar then) public String formatDuration(Duration duration) { if (duration == null) - return format(Instant.now()); + return format(now()); TimeFormat timeFormat = getFormat(duration.getUnit()); return timeFormat.format(duration); @@ -1201,12 +969,12 @@ public String formatDuration(Duration duration) public String formatDuration(final List durations) { if (durations == null || durations.isEmpty()) - return format(Instant.now()); + return format(now()); StringBuilder result = new StringBuilder(); - Duration duration; - TimeFormat format; + Duration duration = null; + TimeFormat format = null; for (int i = 0; i < durations.size(); i++) { duration = durations.get(i); format = getFormat(duration.getUnit()); @@ -1348,7 +1116,8 @@ public String formatDuration(final LocalDate then) */ public String formatDurationUnrounded(Date then) { - return formatDurationUnrounded(approximateDuration(then)); + Duration duration = approximateDuration(then); + return formatDurationUnrounded(duration); } /** @@ -1361,10 +1130,13 @@ public String formatDurationUnrounded(Date then) * @param then the date to be formatted * @return A formatted string of the given {@link Date} */ - public String formatDurationUnrounded(final Calendar then) + public String formatDurationUnrounded(Calendar then) { - return then == null ? formatDuration(Instant.now()) : - formatDurationUnrounded(approximateDuration(then.toInstant())); + if (then == null) + return formatDuration(now()); + + Duration duration = approximateDuration(then.getTime()); + return formatDurationUnrounded(duration); } /** @@ -1378,7 +1150,11 @@ public String formatDurationUnrounded(final Calendar then) */ public String formatDurationUnrounded(Duration duration) { - return duration == null ? format(Instant.now()) : getFormat(duration.getUnit()).formatUnrounded(duration); + if (duration == null) + return format(now()); + + TimeFormat timeFormat = getFormat(duration.getUnit()); + return timeFormat.formatUnrounded(duration); } /** @@ -1393,11 +1169,11 @@ public String formatDurationUnrounded(Duration duration) public String formatDurationUnrounded(final List durations) { if (durations == null || durations.isEmpty()) - return format(Instant.now()); + return format(now()); StringBuilder result = new StringBuilder(); - Duration duration; - TimeFormat format; + Duration duration = null; + TimeFormat format = null; for (int i = 0; i < durations.size(); i++) { duration = durations.get(i); format = getFormat(duration.getUnit()); @@ -1614,7 +1390,7 @@ public PrettyTime setReference(final LocalDateTime localDateTime) */ public PrettyTime setReference(final LocalDateTime localDateTime, final ZoneId zoneId) { - return setReference(localDateTime != null ? localDateTime.atZone(zoneId) : null); + return setReference(localDateTime != null ? localDateTime.atZone(zoneId).toInstant() : null); } /** @@ -1630,7 +1406,7 @@ public PrettyTime setReference(final LocalDateTime localDateTime, final ZoneId z */ public PrettyTime setReference(final LocalDate localDate) { - return setReference(localDate, ZoneId.systemDefault()); + return setReference(localDate != null ? localDate.atStartOfDay() : null); } /** @@ -1646,37 +1422,7 @@ public PrettyTime setReference(final LocalDate localDate) */ public PrettyTime setReference(final LocalDate localDate, final ZoneId zoneId) { - return setReference(localDate != null ? localDate.atStartOfDay(zoneId) : null); - } - - /** - * Converts the given {@link OffsetDateTime} to the reference {@link Instant}. If null, {@link PrettyTime} - * will always use the current value of {@link System#currentTimeMillis()} as the reference {@link Instant}. - *

- * If the {@link Instant} formatted is before the reference {@link Instant}, the format command will produce a - * {@link String} that is in the past tense. If the {@link Instant} formatted is after the reference {@link Instant}, - * the format command will produce a {@link String} that is in the future tense. - * - * @see #setReference(Instant) - */ - public PrettyTime setReference(final OffsetDateTime offsetDateTime) - { - return setReference(offsetDateTime != null ? offsetDateTime.toInstant() : null); - } - - /** - * Converts the given {@link ZonedDateTime} to the reference {@link Instant}. If null, {@link PrettyTime} - * will always use the current value of {@link System#currentTimeMillis()} as the reference {@link Instant}. - *

- * If the {@link Instant} formatted is before the reference {@link Instant}, the format command will produce a - * {@link String} that is in the past tense. If the {@link Instant} formatted is after the reference {@link Instant}, - * the format command will produce a {@link String} that is in the future tense. - * - * @see #setReference(Instant) - */ - public PrettyTime setReference(final ZonedDateTime zonedDateTime) - { - return setReference(zonedDateTime != null ? zonedDateTime.toInstant() : null); + return setReference(localDate != null ? localDate.atStartOfDay(zoneId).toInstant() : null); } /** @@ -1841,6 +1587,11 @@ public List clearUnits() /* * Internal methods. */ + private Date now() + { + return new Date(); + } + private void initTimeUnits() { addUnit(new JustNow()); diff --git a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java index 32dd7c0b..48488b05 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java +++ b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java @@ -16,11 +16,11 @@ public class ResourcesTimeFormat extends SimpleTimeFormat { private final ResourcesTimeUnit unit; private TimeFormat override; - private final String overrideResourceBundle; // If used this bundle will override the included bundle + private String overrideResourceBundle; // If used this bundle will override the included bundle public ResourcesTimeFormat(ResourcesTimeUnit unit) { - this(unit, null); + this.unit = unit; } public ResourcesTimeFormat(ResourcesTimeUnit unit, String overrideResourceBundle) diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeOverrideBundleTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeOverrideBundleTest.java index 0e90e0c8..59eed7e5 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeOverrideBundleTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeOverrideBundleTest.java @@ -20,7 +20,7 @@ import org.junit.Before; import org.junit.Test; -import java.time.LocalDateTime; +import java.util.Date; import java.util.Locale; public class PrettyTimeOverrideBundleTest @@ -37,10 +37,9 @@ public void setUp() throws Exception @Test public void testHoursAgo() throws Exception { - final LocalDateTime now = LocalDateTime.now(); - PrettyTime t = new PrettyTime(now, Locale.ENGLISH, + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), Locale.ENGLISH, "org.ocpsoft.prettytime.i18n.override.Resources"); - Assert.assertEquals("3 hours ago override", t.format(now.minusHours(3))); + Assert.assertEquals("3 hours ago override", t.format(new Date(0))); } @After @@ -48,4 +47,5 @@ public void tearDown() throws Exception { Locale.setDefault(locale); } + } From 781177e102e6694f0be73b5916ca59ba8aa00e44 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Tue, 5 Jan 2021 05:33:56 +0530 Subject: [PATCH 074/147] Fix test failures. --- .../org/ocpsoft/prettytime/PrettyTime.java | 46 +++++++++---------- .../PrettyTimeAPIManipulationTest.java | 6 +-- .../prettytime/PrettyTimeI18n_DA_Test.java | 3 +- .../prettytime/PrettyTimeI18n_EL_Test.java | 4 +- .../prettytime/PrettyTimeI18n_EO_Test.java | 13 ++---- .../prettytime/PrettyTimeI18n_HE_Test.java | 12 ++--- .../prettytime/PrettyTimeI18n_IW_Test.java | 12 ++--- .../ocpsoft/prettytime/PrettyTimeTest.java | 11 ++--- 8 files changed, 48 insertions(+), 59 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index 21bd3a61..515e1204 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -420,15 +420,35 @@ public Duration approximateDuration(LocalDateTime then, final ZoneId zoneId) * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference * between compared dates. */ - public List calculatePreciseDuration(Date then) + public List calculatePreciseDuration(final Date then) + { + return calculatePreciseDuration(then != null ? then.toInstant() : null); + } + + /** + * Calculate to the precision of the smallest provided {@link TimeUnit}, the exact {@link Duration} represented by + * the difference between the reference {@link Instant} and the given {@link Instant}. If the given {@link Instant} + * is null, the current value of {@link System#currentTimeMillis()} will be used instead. + *

+ * Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder + * of time (in milliseconds). + * + * @param then The {@link Instant} to be compared against the reference timestamp, or now if no reference + * timestamp was provided + * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list + * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous + * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference + * between compared dates. + */ + public List calculatePreciseDuration(Instant then) { if (then == null) - then = now(); + then = Instant.now(); final Instant reference = this.reference != null ? this.reference : Instant.now(); List result = new ArrayList<>(); - long difference = then.getTime() - reference.toEpochMilli(); + long difference = then.toEpochMilli() - reference.toEpochMilli(); Duration duration = calculateDuration(difference); result.add(duration); while (0 != duration.getDelta()) { @@ -446,26 +466,6 @@ public List calculatePreciseDuration(Date then) return result; } - /** - * Calculate to the precision of the smallest provided {@link TimeUnit}, the exact {@link Duration} represented by - * the difference between the reference {@link Instant} and the given {@link Instant}. If the given {@link Instant} - * is null, the current value of {@link System#currentTimeMillis()} will be used instead. - *

- * Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder - * of time (in milliseconds). - * - * @param then The {@link Instant} to be compared against the reference timestamp, or now if no reference - * timestamp was provided - * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list - * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous - * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference - * between compared dates. - */ - public List calculatePreciseDuration(final Instant then) - { - return calculatePreciseDuration(then != null ? Date.from(then) : null); - } - /** * Calculate to the precision of the smallest provided {@link TimeUnit}, the exact {@link Duration} represented by * the difference between the reference {@link Instant} and the given {@link LocalDateTime} using the system default diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java index 2d488a3a..27a4169e 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java @@ -45,14 +45,14 @@ public void testApiMisuseSetUnits1() throws Exception public void testApiMisuse1() throws Exception { Assert.assertEquals(t.approximateDuration(LocalDateTime.now()), - t.approximateDuration((Date) null)); + t.approximateDuration((LocalDateTime) null)); } @Test public void testApiMisuse2() throws Exception { Assert.assertEquals(t.calculatePreciseDuration(LocalDateTime.now()), - t.calculatePreciseDuration((Date) null)); + t.calculatePreciseDuration((LocalDateTime) null)); } @Test @@ -241,7 +241,7 @@ public void testApiMisuse13() throws Exception t.getUnits(); } - @Test(expected = IllegalArgumentException.class) + @Test(expected = NullPointerException.class) public void testApiMisuse14() throws Exception { t.registerUnit(null, 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 8fae8d26..64d42408 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 @@ -69,8 +69,7 @@ public void testCeilingInterval() throws Exception public void testNullDate() throws Exception { PrettyTime t = new PrettyTime(locale); - Date date = null; - assertEquals("straks", t.format(date)); + assertEquals("straks", t.format((Date) null)); } @Test 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 a437268c..228df2a3 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 @@ -34,8 +34,8 @@ public void testCeilingInterval() throws Exception { @Test public void testNullDate() throws Exception { PrettyTime t = new PrettyTime(); - Date date = null; - Assert.assertEquals("στιγμές από τώρα", t.format(date)); + final String format = t.format((Date) null); + Assert.assertTrue("πριν από στιγμές".equals(format) || "στιγμές από τώρα".equals(format)); } @Test 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 ad834015..de5b0fa8 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 @@ -16,6 +16,7 @@ package org.ocpsoft.prettytime; import java.text.SimpleDateFormat; +import java.time.LocalDate; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -79,16 +80,12 @@ public void testCalculatePreciceDuration() throws Exception } @Test - @SuppressWarnings("deprecation") 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( - "antaŭ 1 jarmilo 9 jarcentoj 4 jardekoj 4 jaroj 8 monatoj 1 semajno 6 tagoj 20 horoj 5 minutoj", - t.format(durations)); - Assert.assertEquals("1 jarmilo 9 jarcentoj 4 jardekoj 4 jaroj 8 monatoj 1 semajno 6 tagoj 20 horoj 5 minutoj", - t.formatDuration(durations)); + 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)); } @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 453bcb75..5a31f518 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 @@ -4,6 +4,7 @@ package org.ocpsoft.prettytime; import java.text.SimpleDateFormat; +import java.time.LocalDate; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -58,15 +59,12 @@ public void testCalculatePreciceDuration() throws Exception } @Test - @SuppressWarnings("deprecation") 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 מילניום 9 מאות 4 עשורים 4 שנים 8 חודשים 1 שבוע 6 ימים 20 שעות 5 דקות", - t.format(durations)); - Assert.assertEquals("1 מילניום 9 מאות 4 עשורים 4 שנים 8 חודשים 1 שבוע 6 ימים 20 שעות 5 דקות", - t.formatDuration(durations)); + 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)); } @Test 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 8da2e196..fdf1bde2 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 @@ -9,6 +9,7 @@ import org.ocpsoft.prettytime.units.Minute; import java.text.SimpleDateFormat; +import java.time.LocalDate; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -54,15 +55,12 @@ public void testCalculatePreciceDuration() throws Exception } @Test - @SuppressWarnings("deprecation") 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 מילניום 9 מאות 4 עשורים 4 שנים 8 חודשים 1 שבוע 6 ימים 20 שעות 5 דקות", - t.format(durations)); - Assert.assertEquals("1 מילניום 9 מאות 4 עשורים 4 שנים 8 חודשים 1 שבוע 6 ימים 20 שעות 5 דקות", - t.formatDuration(durations)); + 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)); } @Test diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java index 7da8077c..c9747ee0 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java @@ -93,15 +93,12 @@ public void testCalculatePreciceDuration() throws Exception } @Test - @SuppressWarnings("deprecation") 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 millennium 9 centuries 4 decades 4 years 8 months 1 week 6 days 20 hours 5 minutes ago", - t.format(durations)); - Assert.assertEquals("1 millennium 9 centuries 4 decades 4 years 8 months 1 week 6 days 20 hours 5 minutes", - t.formatDuration(durations)); + PrettyTime t = new PrettyTime(LocalDate.of(2000, 2, 2)); + List durations = t.calculatePreciseDuration(LocalDate.of(100, 1, 1)); + Assert.assertEquals("1 millennium 9 centuries 1 month 1 day 8 hours 34 minutes ago", t.format(durations)); + Assert.assertEquals("1 millennium 9 centuries 1 month 1 day 8 hours 34 minutes", t.formatDuration(durations)); } @Test From 50981790887561af714d89afda8c4bf996668290 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 10 Mar 2021 23:16:15 +0000 Subject: [PATCH 075/147] Bump jetty-server in /samples/jstl Bumps [jetty-server](https://github.com/eclipse/jetty.project) from 9.4.35.v20201120 to 9.4.38.v20210224. - [Release notes](https://github.com/eclipse/jetty.project/releases) - [Commits](https://github.com/eclipse/jetty.project/compare/jetty-9.4.35.v20201120...jetty-9.4.38.v20210224) Signed-off-by: dependabot[bot] --- samples/jstl/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 061a78fd..3bb63d3c 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -15,7 +15,7 @@ org.eclipse.jetty jetty-server - 9.4.35.v20201120 + 9.4.38.v20210224 org.eclipse.jetty From f6789675d6efff4c772ec4c136a9c602ec75c921 Mon Sep 17 00:00:00 2001 From: iamthesenate1 <77978836+iamthesenate1@users.noreply.github.com> Date: Thu, 11 Mar 2021 21:27:50 +0200 Subject: [PATCH 076/147] Correct one minute translation in Romanian --- .../src/main/java/org/ocpsoft/prettytime/i18n/Resources_ro.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ro.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ro.java index e537efa7..dcdd1c34 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ro.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ro.java @@ -74,7 +74,7 @@ public class Resources_ro extends ListResourceBundle { "MinuteFutureSuffix", " de acum" }, { "MinutePastPrefix", "" }, { "MinutePastSuffix", " in urma" }, - { "MinuteSingularName", "minuta" }, + { "MinuteSingularName", "minut" }, { "MinutePluralName", "minute" }, { "MonthPattern", "%n %u" }, { "MonthFuturePrefix", "" }, From 8f374c56d6edfc4eaa0eb5647f25acac444db674 Mon Sep 17 00:00:00 2001 From: nadiration <59365236+nadiration@users.noreply.github.com> Date: Fri, 19 Mar 2021 16:41:59 +0300 Subject: [PATCH 077/147] Added Somali language --- .../ocpsoft/prettytime/i18n/Resources_so.java | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_so.java diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_so.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_so.java new file mode 100644 index 00000000..9b59df99 --- /dev/null +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_so.java @@ -0,0 +1,121 @@ +/* + * Copyright 2012 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ocpsoft.prettytime.i18n; + +import java.util.ListResourceBundle; + +public class Resources_en extends ListResourceBundle +{ + private static final Object[][] OBJECTS = new Object[][] { + { "CenturyPattern", "%n %u" }, + { "CenturyFuturePrefix", "" }, + { "CenturyFutureSuffix", " kadib" }, + { "CenturyPastPrefix", "" }, + { "CenturyPastSuffix", " kahor" }, + { "CenturySingularName", "qarni" }, + { "CenturyPluralName", "qarni" }, + { "DayPattern", "%n %u" }, + { "DayFuturePrefix", "" }, + { "DayFutureSuffix", " kadib" }, + { "DayPastPrefix", "" }, + { "DayPastSuffix", " kahor" }, + { "DaySingularName", "maalin" }, + { "DayPluralName", "maalmood" }, + { "DecadePattern", "%n %u" }, + { "DecadeFuturePrefix", "" }, + { "DecadeFutureSuffix", " kadib" }, + { "DecadePastPrefix", "" }, + { "DecadePastSuffix", " kahor" }, + { "DecadeSingularName", "toban sano" }, + { "DecadePluralName", "toban sanooyin" }, + { "HourPattern", "%n %u" }, + { "HourFuturePrefix", "" }, + { "HourFutureSuffix", " kadib" }, + { "HourPastPrefix", "" }, + { "HourPastSuffix", " kahor" }, + { "HourSingularName", "saac" }, + { "HourPluralName", "saac" }, + { "JustNowPattern", "%u" }, + { "JustNowFuturePrefix", "" }, + { "JustNowFutureSuffix", "waxyar kadib" }, + { "JustNowPastPrefix", "waxyar kahor" }, + { "JustNowPastSuffix", "" }, + { "JustNowSingularName", "" }, + { "JustNowPluralName", "" }, + { "MillenniumPattern", "%n %u" }, + { "MillenniumFuturePrefix", "" }, + { "MillenniumFutureSuffix", " kadib" }, + { "MillenniumPastPrefix", "" }, + { "MillenniumPastSuffix", " kahor" }, + { "MillenniumSingularName", "kun sano" }, + { "MillenniumPluralName", "kun sano" }, + { "MillisecondPattern", "%n %u" }, + { "MillisecondFuturePrefix", "" }, + { "MillisecondFutureSuffix", " kadib" }, + { "MillisecondPastPrefix", "" }, + { "MillisecondPastSuffix", " ago" }, + { "MillisecondSingularName", "ilbiriqsi kayar" }, + { "MillisecondPluralName", "ilbiriqsi kayar" }, + { "MinutePattern", "%n %u" }, + { "MinuteFuturePrefix", "" }, + { "MinuteFutureSuffix", " kadib" }, + { "MinutePastPrefix", "" }, + { "MinutePastSuffix", " kahor" }, + { "MinuteSingularName", "daqiiqo" }, + { "MinutePluralName", "daqiiqo" }, + { "MonthPattern", "%n %u" }, + { "MonthFuturePrefix", "" }, + { "MonthFutureSuffix", " kadib" }, + { "MonthPastPrefix", "" }, + { "MonthPastSuffix", " kahor" }, + { "MonthSingularName", "bil" }, + { "MonthPluralName", "bilood" }, + { "SecondPattern", "%n %u" }, + { "SecondFuturePrefix", "" }, + { "SecondFutureSuffix", " kadib" }, + { "SecondPastPrefix", "" }, + { "SecondPastSuffix", " kahor" }, + { "SecondSingularName", "ilbiriqsi" }, + { "SecondPluralName", "ilbiriqsi" }, + { "WeekPattern", "%n %u" }, + { "WeekFuturePrefix", "" }, + { "WeekFutureSuffix", " kadib" }, + { "WeekPastPrefix", "" }, + { "WeekPastSuffix", " kahor" }, + { "WeekSingularName", "todobaad" }, + { "WeekPluralName", "todobaad" }, + { "YearPattern", "%n %u" }, + { "YearFuturePrefix", "" }, + { "YearFutureSuffix", " kadib" }, + { "YearPastPrefix", "" }, + { "YearPastSuffix", " kahor" }, + { "YearSingularName", "sano" }, + { "YearPluralName", "sano" }, + { "AbstractTimeUnitPattern", "" }, + { "AbstractTimeUnitFuturePrefix", "" }, + { "AbstractTimeUnitFutureSuffix", "" }, + { "AbstractTimeUnitPastPrefix", "" }, + { "AbstractTimeUnitPastSuffix", "" }, + { "AbstractTimeUnitSingularName", "" }, + { "AbstractTimeUnitPluralName", "" } }; + + @Override + public Object[][] getContents() + { + return OBJECTS; + } + +} From 0ccd7163aec7830342c33d60dc5f2826487f2245 Mon Sep 17 00:00:00 2001 From: nadiration <59365236+nadiration@users.noreply.github.com> Date: Fri, 19 Mar 2021 18:15:08 +0300 Subject: [PATCH 078/147] Create PrettyTimeI18n_SO_Test.java --- .../org/ocpsoft/PrettyTimeI18n_SO_Test.java | 508 ++++++++++++++++++ 1 file changed, 508 insertions(+) create mode 100644 core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java diff --git a/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java b/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java new file mode 100644 index 00000000..132d6140 --- /dev/null +++ b/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java @@ -0,0 +1,508 @@ +/* + * Copyright 2012 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ocpsoft.prettytime; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.Calendar; +import java.util.Date; +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 PrettyTimeTest +{ + private Locale locale; + private LocalDateTime now; + + @Before + public void setUp() throws Exception + { + locale = Locale.getDefault(); + Locale.setDefault(Locale.ROOT); + now = LocalDateTime.now(); + } + + @Test + 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 + { + PrettyTime t = new PrettyTime(); + Date date = null; + Assert.assertEquals("waxyar kadib", t.format(date)); + } + + @Test + public void testRightNow() throws Exception + { + PrettyTime t = new PrettyTime(); + Assert.assertEquals("waxyar kadib", t.format(new Date())); + } + + @Test + public void testRightNowWithReference() throws Exception + { + Date now = new Date(); + PrettyTime t = new PrettyTime(); + Assert.assertEquals("waxyar kadib", t.format(now)); + } + + @Test + public void testCalculatePreciceDuration() throws Exception + { + PrettyTime t = new PrettyTime(); + List preciseDuration = t.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)))); + + 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)))); + } + + @Test + @SuppressWarnings("deprecation") + 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)); + 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)); + } + + @Test + 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)))); + } + + @Test + 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)))); + } + + @Test + 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)))); + } + + @Test + 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 + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("12 daqiiqo kadib", t.format(now.plusMinutes(12))); + } + + @Test + 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 + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 maalmood kadib", t.format(now.plusDays(3))); + } + + @Test + 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 + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 bilood kadib", t.format(now.plusMonths(3))); + } + + @Test + 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 + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 toban sanooyin kadib", t.format(now.plus(3, ChronoUnit.DECADES))); + } + + @Test + public void testCenturiesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 qarni kadib", t.format(now.plus(3, ChronoUnit.CENTURIES))); + } + + /* + * Past + */ + @Test + 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 + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("12 daqiiqo kahor", t.format(now.minusMinutes(12))); + } + + @Test + 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 + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 saac kahor", t.format(now.minusHours(3))); + } + + @Test + 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 + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 maalmood kahor", t.format(now.minusDays(3))); + } + + @Test + 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 + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 bilood kahor", t.format(now.minusMonths(3))); + } + + @Test + public void testCustomFormat() throws Exception + { + PrettyTime t = new PrettyTime(now); + TimeUnit unit = new TimeUnit() { + @Override + public long getMaxQuantity() + { + return 0; + } + + @Override + public long getMillisPerUnit() + { + return 5000; + } + + @Override + 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...")); + + final LocalDateTime fiveTicks = now.plusSeconds(25); + Assert.assertEquals("isburburi kadib: 5 tik ... BILOW!", t.format(fiveTicks)); + t.setReference(fiveTicks); + Assert.assertEquals("isburburintii waxay ahayd: 5 tik kahor...", t.format(now)); + } + + @Test + public void testYearsAgo() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 sank kahor", t.format(now.minusYears(3))); + } + + @Test + 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 + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("3 qarni kahor", t.format(now.minus(3, ChronoUnit.CENTURIES))); + } + + @Test + 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 + { + PrettyTime t = new PrettyTime(); + List durations = t.calculatePreciseDuration(now.plusHours(5).plusMinutes(10).plusSeconds(1)); + Assert.assertTrue(durations.size() >= 2); + Assert.assertEquals(5, durations.get(0).getQuantity()); + Assert.assertEquals(10, durations.get(1).getQuantity()); + } + + @Test + 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); + Assert.assertEquals(-5, durations.get(0).getQuantity()); + Assert.assertEquals(-10, durations.get(1).getQuantity()); + } + + @Test + 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 + { + 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 + { + PrettyTime t = new PrettyTime(now); + final LocalDateTime threeDecadesAgo = now.minus(3, ChronoUnit.DECADES); + Assert.assertEquals("3 toban sanooyin kadib", t.format(threeDecadesAgo)); + t.setLocale(Locale.GERMAN); + Assert.assertEquals("vor 3 Jahrzehnten", t.format(threeDecadesAgo)); + } + + /** + * 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 + { + Calendar c = Calendar.getInstance(); + Date r = c.getTime(); + PrettyTime t = new PrettyTime(); + t.setLocale(Locale.ENGLISH); + t.setReference(r); + c.add(Calendar.YEAR, -1); + Assert.assertEquals("1 sano kahor", t.format(c)); + } + + /** + * Tests formatApproximateDuration and by proxy, formatDuration. + * + * @throws Exception + */ + @Test + 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(); + String result = t.formatDuration(tenMinAgo); + Assert.assertEquals("10 daqiiqo", result); + + result = t.formatDuration(now.minusMinutes(10)); + Assert.assertEquals("10 daqiiqo", result); + } + + @Test + 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(); + String result = t.formatDuration(tenMinAgo); + Assert.assertEquals("11 daqiiqo", result); + + result = t.formatDuration(now.minusMinutes(10).minusSeconds(40)); + Assert.assertEquals("11 daqiiqo", result); + } + + @Test + 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(); + String result = t.formatDurationUnrounded(tenMinAgo); + Assert.assertEquals("10 daqiiqo", result); + + result = t.formatDurationUnrounded(now.minusMinutes(10).minusSeconds(40)); + Assert.assertEquals("10 daqiiqo", result); + } + + @Test + 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)))); + } + + @Test + 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)))); + } + + @Test + 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)))); + } + + @Test + 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)))); + } + + @Test + 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)))); + } + + @Test + 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)))); + } + + @After + public void tearDown() throws Exception + { + Locale.setDefault(locale); + } + +} From e5bbc6c778ccfdbf5f253983c5b32105d3f4c030 Mon Sep 17 00:00:00 2001 From: nadiration <59365236+nadiration@users.noreply.github.com> Date: Mon, 5 Apr 2021 13:07:09 +0300 Subject: [PATCH 079/147] Set SO locale Co-authored-by: George Gastaldi --- core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java b/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java index 132d6140..096e5242 100644 --- a/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java +++ b/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java @@ -41,7 +41,7 @@ public class PrettyTimeTest public void setUp() throws Exception { locale = Locale.getDefault(); - Locale.setDefault(Locale.ROOT); + Locale.setDefault(new Locale("so","SO")); now = LocalDateTime.now(); } From 288ff12eca796133904b14a4ca08e48d00981ab3 Mon Sep 17 00:00:00 2001 From: nadiration <59365236+nadiration@users.noreply.github.com> Date: Wed, 7 Apr 2021 17:17:12 +0300 Subject: [PATCH 080/147] Update Resources_so.java --- .../src/main/java/org/ocpsoft/prettytime/i18n/Resources_so.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_so.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_so.java index 9b59df99..1d6a1e1f 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_so.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_so.java @@ -66,7 +66,7 @@ public class Resources_en extends ListResourceBundle { "MillisecondFuturePrefix", "" }, { "MillisecondFutureSuffix", " kadib" }, { "MillisecondPastPrefix", "" }, - { "MillisecondPastSuffix", " ago" }, + { "MillisecondPastSuffix", " kahor" }, { "MillisecondSingularName", "ilbiriqsi kayar" }, { "MillisecondPluralName", "ilbiriqsi kayar" }, { "MinutePattern", "%n %u" }, From 4cd339acea69131be8f5829b4c2aaa0ddd3496fa Mon Sep 17 00:00:00 2001 From: nadiration <59365236+nadiration@users.noreply.github.com> Date: Wed, 7 Apr 2021 17:26:54 +0300 Subject: [PATCH 081/147] Update PrettyTimeI18n_SO_Test.java --- core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java b/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java index 096e5242..92112c98 100644 --- a/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java +++ b/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java @@ -93,7 +93,7 @@ public void testCalculatePreciceDuration() throws Exception } @Test - @SuppressWarnings("deprecation") + @SuppressWarnings("Digniin") public void testCalculatePreciceDurationMillenia() throws Exception { PrettyTime t = new PrettyTime(new Date(2014, 8, 15, 0, 0)); From 759d7f8db33b119459d58253a747af67ac0d7940 Mon Sep 17 00:00:00 2001 From: nadiration <59365236+nadiration@users.noreply.github.com> Date: Sat, 10 Apr 2021 09:40:57 +0300 Subject: [PATCH 082/147] Update PrettyTimeI18n_SO_Test.java --- core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java b/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java index 92112c98..096e5242 100644 --- a/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java +++ b/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java @@ -93,7 +93,7 @@ public void testCalculatePreciceDuration() throws Exception } @Test - @SuppressWarnings("Digniin") + @SuppressWarnings("deprecation") public void testCalculatePreciceDurationMillenia() throws Exception { PrettyTime t = new PrettyTime(new Date(2014, 8, 15, 0, 0)); From 8642ca9c58e237da577497c28c83a9ac8e8c2910 Mon Sep 17 00:00:00 2001 From: nadiration <59365236+nadiration@users.noreply.github.com> Date: Sat, 10 Apr 2021 09:52:49 +0300 Subject: [PATCH 083/147] Update PrettyTimeI18n_SO_Test.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @lincolnthree those German linea were in the original english test file so when i was translating i was like 'what are they doing here??' but then i thought it's best i leave them alone 😁 --- core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java b/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java index 096e5242..a880de89 100644 --- a/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java +++ b/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java @@ -365,8 +365,6 @@ 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)); - t.setLocale(Locale.GERMAN); - Assert.assertEquals("vor 3 Jahrzehnten", t.format(threeDecadesAgo)); } /** From bab22bd8a7f294735b0f78a5ab3094b2bebfea74 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Fri, 30 Apr 2021 09:05:23 -0400 Subject: [PATCH 084/147] Fix issues with SO resource bundle compilation. --- .../ocpsoft/prettytime/i18n/Resources_so.java | 2 +- .../PrettyTimeI18n_SO_Test.java | 213 +++++++----------- 2 files changed, 80 insertions(+), 135 deletions(-) rename core/src/test/java/org/ocpsoft/{ => prettytime}/PrettyTimeI18n_SO_Test.java (71%) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_so.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_so.java index 1d6a1e1f..6af63cdf 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_so.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_so.java @@ -17,7 +17,7 @@ import java.util.ListResourceBundle; -public class Resources_en extends ListResourceBundle +public class Resources_so extends ListResourceBundle { private static final Object[][] OBJECTS = new Object[][] { { "CenturyPattern", "%n %u" }, diff --git a/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SO_Test.java similarity index 71% rename from core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java rename to core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SO_Test.java index a880de89..5a979701 100644 --- a/core/src/test/java/org/ocpsoft/PrettyTimeI18n_SO_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SO_Test.java @@ -32,59 +32,51 @@ import org.ocpsoft.prettytime.impl.ResourcesTimeFormat; import org.ocpsoft.prettytime.units.Minute; -public class PrettyTimeTest -{ +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")); + 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(); 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))); + List preciseDuration = t + .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)))); + Assert.assertEquals("waxyar kahor", t.format(t.calculatePreciseDuration(new Date(new Date().getTime() - 10)))); preciseDuration = t.calculatePreciseDuration(now.minusHours(2).minusMinutes(2)); Assert.assertEquals("2 saac 2 daqiiqo kahor", t.format(preciseDuration)); @@ -94,107 +86,95 @@ public void testCalculatePreciceDuration() throws Exception @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)); + 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)); 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)))); + Assert.assertEquals("40 daqiiqo kahor", + 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)))); + Assert.assertEquals("40 daqiiqo", + 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)))); + Assert.assertEquals("40 daqiiqo kahor", + 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))); } @@ -203,91 +183,77 @@ 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...")); + 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...")); final LocalDateTime fiveTicks = now.plusSeconds(25); Assert.assertEquals("isburburi kadib: 5 tik ... BILOW!", t.format(fiveTicks)); @@ -296,36 +262,31 @@ public boolean isPrecise() } @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))); } @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); @@ -334,8 +295,7 @@ 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); @@ -344,39 +304,35 @@ 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)); } /** - * 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(); @@ -392,8 +348,7 @@ 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(); @@ -405,8 +360,7 @@ 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(); @@ -418,8 +372,7 @@ 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(); @@ -431,75 +384,67 @@ 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)))); + 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)))); + Assert.assertEquals("40 daqiiqo", prettyTime + .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); } From 727a1f45043fbaae7b3198ca29a75e112da0ff3e Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Fri, 30 Apr 2021 09:07:46 -0400 Subject: [PATCH 085/147] [maven-release-plugin] prepare release 5.0.1.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 8157b3b7..ef67cac0 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.1-SNAPSHOT + 5.0.1.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 109edde2..7e83fb3b 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.1-SNAPSHOT + 5.0.1.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index b15c4d53..c0a8e1bb 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.1-SNAPSHOT + 5.0.1.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 6aa6e820..fd4f51a0 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.1-SNAPSHOT + 5.0.1.Final ../pom.xml diff --git a/pom.xml b/pom.xml index 3de573fc..ee41234f 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.1-SNAPSHOT + 5.0.1.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 5.0.1.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 3bb63d3c..d66bfe49 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.1-SNAPSHOT + 5.0.1.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.1-SNAPSHOT + 5.0.1.Final diff --git a/samples/pom.xml b/samples/pom.xml index 85ad5c6d..3044d4e5 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.1-SNAPSHOT + 5.0.1.Final 4.0.0 From 3c2206d5b909b33354f9c09a8053a08b5ac93954 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Fri, 30 Apr 2021 09:07:46 -0400 Subject: [PATCH 086/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index ef67cac0..dda3879c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.1.Final + 5.0.2-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 7e83fb3b..21b671a3 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.1.Final + 5.0.2-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index c0a8e1bb..7bcf489b 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.1.Final + 5.0.2-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index fd4f51a0..e64a2a22 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.1.Final + 5.0.2-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index ee41234f..86891e17 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.1.Final + 5.0.2-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 5.0.1.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index d66bfe49..1c257d1b 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.1.Final + 5.0.2-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.1.Final + 5.0.2-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index 3044d4e5..477dc3c6 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.1.Final + 5.0.2-SNAPSHOT 4.0.0 From c86e446cb3cb11b2d3c797544a6760c91bd1a7aa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 23 Jun 2021 20:52:19 +0000 Subject: [PATCH 087/147] Bump jetty-server in /samples/jstl Bumps [jetty-server](https://github.com/eclipse/jetty.project) from 9.4.38.v20210224 to 9.4.41.v20210516. - [Release notes](https://github.com/eclipse/jetty.project/releases) - [Commits](https://github.com/eclipse/jetty.project/compare/jetty-9.4.38.v20210224...jetty-9.4.41.v20210516) --- updated-dependencies: - dependency-name: org.eclipse.jetty:jetty-server dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- samples/jstl/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 1c257d1b..7de0d38a 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -15,7 +15,7 @@ org.eclipse.jetty jetty-server - 9.4.38.v20210224 + 9.4.41.v20210516 org.eclipse.jetty From a7b4296c06e98a29d8f18b2802ae0dad2ef65b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=9Awistak?= Date: Thu, 12 Aug 2021 20:31:53 +0200 Subject: [PATCH 088/147] Added support for plural forms in Polish language --- .../ocpsoft/prettytime/i18n/Resources_pl.java | 258 +++++++++----- .../prettytime/PrettyTimeI18n_PL_Test.java | 328 ++++++++++++++++++ 2 files changed, 492 insertions(+), 94 deletions(-) create mode 100644 core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_PL_Test.java diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_pl.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_pl.java index 452e1159..9095d132 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_pl.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_pl.java @@ -15,102 +15,96 @@ */ package org.ocpsoft.prettytime.i18n; +import org.ocpsoft.prettytime.Duration; +import org.ocpsoft.prettytime.TimeFormat; +import org.ocpsoft.prettytime.TimeUnit; +import org.ocpsoft.prettytime.impl.TimeFormatProvider; +import org.ocpsoft.prettytime.units.*; + import java.util.ListResourceBundle; -public class Resources_pl extends ListResourceBundle +public class Resources_pl extends ListResourceBundle implements TimeFormatProvider { - private static final Object[][] OBJECTS = new Object[][] { - { "CenturyPattern", "%n %u" }, - { "CenturyFuturePrefix", "za " }, - { "CenturyFutureSuffix", "" }, - { "CenturyPastPrefix", "" }, - { "CenturyPastSuffix", " temu" }, - { "CenturySingularName", "wiek" }, - { "CenturyPluralName", "wiek(i/ów)" }, - { "DayPattern", "%n %u" }, - { "DayFuturePrefix", "za " }, - { "DayFutureSuffix", "" }, - { "DayPastPrefix", "" }, - { "DayPastSuffix", " temu" }, - { "DaySingularName", "dzień" }, - { "DayPluralName", "dni" }, - { "DecadePattern", "%n %u" }, - { "DecadeFuturePrefix", "za " }, - { "DecadeFutureSuffix", "" }, - { "DecadePastPrefix", "" }, - { "DecadePastSuffix", " temu" }, - { "DecadeSingularName", "dekadę" }, - { "DecadePluralName", "dekad" }, - { "HourPattern", "%n %u" }, - { "HourFuturePrefix", "za " }, - { "HourFutureSuffix", "" }, - { "HourPastPrefix", "" }, - { "HourPastSuffix", " temu" }, - { "HourSingularName", "godz." }, - { "HourPluralName", "godz." }, - { "JustNowPattern", "%u" }, - { "JustNowFuturePrefix", "" }, - { "JustNowFutureSuffix", "za chwilę" }, - { "JustNowPastPrefix", "przed chwilą" }, - { "JustNowPastSuffix", "" }, - { "JustNowSingularName", "" }, - { "JustNowPluralName", "" }, - { "MillenniumPattern", "%n %u" }, - { "MillenniumFuturePrefix", "za " }, - { "MillenniumFutureSuffix", "" }, - { "MillenniumPastPrefix", "" }, - { "MillenniumPastSuffix", " temu" }, - { "MillenniumSingularName", "milenium" }, - { "MillenniumPluralName", "milenia" }, - { "MillisecondPattern", "%n %u" }, - { "MillisecondFuturePrefix", "za " }, - { "MillisecondFutureSuffix", "" }, - { "MillisecondPastPrefix", "" }, - { "MillisecondPastSuffix", " temu" }, - { "MillisecondSingularName", "milisek." }, - { "MillisecondPluralName", "milisek." }, - { "MinutePattern", "%n %u" }, - { "MinuteFuturePrefix", "za " }, - { "MinuteFutureSuffix", "" }, - { "MinutePastPrefix", "" }, - { "MinutePastSuffix", " temu" }, - { "MinuteSingularName", "min" }, - { "MinutePluralName", "min" }, - { "MonthPattern", "%n %u" }, - { "MonthFuturePrefix", "za " }, - { "MonthFutureSuffix", "" }, - { "MonthPastPrefix", "" }, - { "MonthPastSuffix", " temu" }, - { "MonthSingularName", "mies." }, - { "MonthPluralName", "mies." }, - { "SecondPattern", "%n %u" }, - { "SecondFuturePrefix", "za " }, - { "SecondFutureSuffix", "" }, - { "SecondPastPrefix", "" }, - { "SecondPastSuffix", " temu" }, - { "SecondSingularName", "sek." }, - { "SecondPluralName", "sek." }, - { "WeekPattern", "%n %u" }, - { "WeekFuturePrefix", "za " }, - { "WeekFutureSuffix", "" }, - { "WeekPastPrefix", "" }, - { "WeekPastSuffix", " temu" }, - { "WeekSingularName", "tydzień" }, - { "WeekPluralName", "tygodni(e)" }, - { "YearPattern", "%n %u" }, - { "YearFuturePrefix", "za " }, - { "YearFutureSuffix", "" }, - { "YearPastPrefix", "" }, - { "YearPastSuffix", " temu" }, - { "YearSingularName", "rok" }, - { "YearPluralName", "lat(a)" }, - { "AbstractTimeUnitPattern", "" }, - { "AbstractTimeUnitFuturePrefix", "" }, - { "AbstractTimeUnitFutureSuffix", "" }, - { "AbstractTimeUnitPastPrefix", "" }, - { "AbstractTimeUnitPastSuffix", "" }, - { "AbstractTimeUnitSingularName", "" }, - { "AbstractTimeUnitPluralName", "" } }; + private static final Object[][] OBJECTS = new Object[0][0]; + + private static final int tolerance = 50; + + // see http://translate.sourceforge.net/wiki/l10n/pluralforms + private static final int polishPluralForms = 3; + + private static class TimeFormatAided implements TimeFormat + { + private final String[] plurals; + + public TimeFormatAided(String... plurals) + { + if (plurals.length != polishPluralForms) { + throw new IllegalArgumentException("Wrong plural forms number for Polish language!"); + } + this.plurals = plurals; + } + + @Override + public String format(Duration duration) + { + long quantity = duration.getQuantityRounded(tolerance); + return String.valueOf(quantity); + } + + @Override + public String formatUnrounded(Duration duration) + { + long quantity = Math.abs(duration.getQuantity()); + return String.valueOf(quantity); + } + + @Override + public String decorate(Duration duration, String time) + { + return performDecoration( + duration.isInPast(), + duration.isInFuture(), + duration.getQuantityRounded(tolerance), + time); + } + + @Override + public String decorateUnrounded(Duration duration, String time) + { + return performDecoration( + duration.isInPast(), + duration.isInFuture(), + Math.abs(duration.getQuantity()), + time); + } + + private String performDecoration(boolean past, boolean future, long n, String time) + { + // a bit cryptic, yet well-tested + // consider http://translate.sourceforge.net/wiki/l10n/pluralforms + int pluralIdx = (n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); + if (pluralIdx > polishPluralForms) { + // impossible happening + throw new IllegalStateException("Wrong plural index was calculated somehow for Polish language"); + } + + StringBuilder result = new StringBuilder(); + + if (future) { + result.append("za "); + } + + result.append(time); + result.append(' '); + result.append(plurals[pluralIdx]); + + if (past) { + result.append(" temu"); + } + + return result.toString(); + } + } @Override public Object[][] getContents() @@ -118,4 +112,80 @@ public Object[][] getContents() return OBJECTS; } -} \ No newline at end of file + @Override + public TimeFormat getFormatFor(TimeUnit t) + { + if (t instanceof JustNow) { + return new TimeFormat() { + @Override + public String format(Duration duration) + { + return performFormat(duration); + } + + @Override + public String formatUnrounded(Duration duration) + { + return performFormat(duration); + } + + private String performFormat(Duration duration) + { + if (duration.isInFuture()) { + return "za chwilę"; + } + if (duration.isInPast()) { + return "przed chwilą"; + } + return null; + } + + @Override + public String decorate(Duration duration, String time) + { + return time; + } + + @Override + public String decorateUnrounded(Duration duration, String time) + { + return time; + } + }; + } + else if (t instanceof Century) { + return new TimeFormatAided("wiek", "wieki", "wieków"); + } + else if (t instanceof Day) { + return new TimeFormatAided("dzień", "dni", "dni"); + } + else if (t instanceof Decade) { + return new TimeFormatAided("dekadę", "dekady", "dekad"); + } + else if (t instanceof Hour) { + return new TimeFormatAided("godzinę", "godziny", "godzin"); + } + else if (t instanceof Millennium) { + return new TimeFormatAided("milenium", "milenia", "mileniów"); + } + else if (t instanceof Millisecond) { + return new TimeFormatAided("milisekundę", "milisekundy", "milisekund"); + } + else if (t instanceof Minute) { + return new TimeFormatAided("minutę", "minuty", "minut"); + } + else if (t instanceof Month) { + return new TimeFormatAided("miesiąc", "miesiące", "miesięcy"); + } + else if (t instanceof Second) { + return new TimeFormatAided("sekundę", "sekundy", "sekund"); + } + else if (t instanceof Week) { + return new TimeFormatAided("tydzień", "tygodnie", "tygodni"); + } + else if (t instanceof Year) { + return new TimeFormatAided("rok", "lata", "lat"); + } + return null; // error + } +} 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 new file mode 100644 index 00000000..3c57f8d8 --- /dev/null +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_PL_Test.java @@ -0,0 +1,328 @@ +package org.ocpsoft.prettytime; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +import static org.junit.Assert.assertEquals; + +public class PrettyTimeI18n_PL_Test +{ + private final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); + private Locale locale; + + @Before + public void setUp() throws Exception + { + locale = new Locale("pl"); + Locale.setDefault(locale); + } + + @Test + public void testPrettyTime() + { + PrettyTime p = new PrettyTime(locale); + assertEquals("przed chwilą", p.format(new Date())); + } + + @Test + public void testPrettyTimeCenturies() + { + PrettyTime p = new PrettyTime(new Date(3155692597470L * 3L), locale); + assertEquals("3 wieki temu", p.format(new Date(0))); + + p = new PrettyTime(new Date(0), locale); + assertEquals("za 3 wieki", p.format(new Date(3155692597470L * 3L))); + } + + @Test + public void testCeilingInterval() throws Exception + { + Date then = format.parse("20/5/2009"); + Date ref = format.parse("17/6/2009"); + PrettyTime t = new PrettyTime(ref, locale); + assertEquals("1 miesiąc temu", t.format(then)); + } + + @Test + public void testNullDate() throws Exception + { + PrettyTime t = new PrettyTime(locale); + Date date = null; + assertEquals("za chwilę", t.format(date)); + } + + @Test + public void testRightNow() throws Exception + { + PrettyTime t = new PrettyTime(locale); + assertEquals("za chwilę", t.format(new Date())); + } + + @Test + public void testRightNowVariance() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("za chwilę", t.format(new Date(600))); + } + + @Test + public void testMinutesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("za 12 minut", t.format(new Date(1000 * 60 * 12))); + } + + @Test + public void testHoursFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("za 3 godziny", t.format(new Date(1000 * 60 * 60 * 3))); + } + + @Test + public void testDaysFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("za 3 dni", t.format(new Date(1000 * 60 * 60 * 24 * 3))); + } + + @Test + public void testWeeksFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("za 3 tygodnie", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); + } + + @Test + public void testMonthsFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("za 3 miesiące", t.format(new Date(2629743830L * 3L))); + } + + @Test + public void testYearsFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("za 3 lata", t.format(new Date(2629743830L * 12L * 3L))); + } + + @Test + public void testDecadesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("za 3 dekady", t.format(new Date(315569259747L * 3L))); + } + + @Test + public void testCenturiesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("za 3 wieki", t.format(new Date(3155692597470L * 3L))); + } + + /* + * Past + */ + @Test + public void testMomentsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(6000), locale); + assertEquals("przed chwilą", t.format(new Date(0))); + } + + @Test + public void testMinutesAgo1() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60), locale); + assertEquals("1 minutę temu", t.formatUnrounded(new Date(0))); + assertEquals("1 minutę temu", t.format(new Date(0))); + } + + @Test + public void testMinutesAgo2() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 3), locale); + assertEquals("3 minuty temu", t.formatUnrounded(new Date(0))); + assertEquals("3 minuty temu", t.format(new Date(0))); + } + + @Test + public void testMinutesAgo3() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale); + assertEquals("12 minut temu", t.formatUnrounded(new Date(0))); + assertEquals("12 minut temu", t.format(new Date(0))); + } + + @Test + public void testHoursAgo1() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60), locale); + assertEquals("1 godzinę temu", t.formatUnrounded(new Date(0))); + assertEquals("1 godzinę temu", t.format(new Date(0))); + } + + @Test + public void testHoursAgo2() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale); + assertEquals("3 godziny temu", t.formatUnrounded(new Date(0))); + assertEquals("3 godziny temu", t.format(new Date(0))); + } + + @Test + public void testHoursAgo3() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 5), locale); + assertEquals("5 godzin temu", t.formatUnrounded(new Date(0))); + assertEquals("5 godzin temu", t.format(new Date(0))); + } + + @Test + public void testDaysAgo1() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24), locale); + assertEquals("1 dzień temu", t.formatUnrounded(new Date(0))); + assertEquals("1 dzień temu", t.format(new Date(0))); + } + + @Test + public void testDaysAgo2() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale); + assertEquals("3 dni temu", t.formatUnrounded(new Date(0))); + assertEquals("3 dni temu", t.format(new Date(0))); + } + + @Test + public void testDaysAgo3() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 5), locale); + assertEquals("5 dni temu", t.formatUnrounded(new Date(0))); + assertEquals("5 dni temu", t.format(new Date(0))); + } + + @Test + public void testWeeksAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7), locale); + assertEquals("1 tydzień temu", t.formatUnrounded(new Date(0))); + assertEquals("1 tydzień temu", t.format(new Date(0))); + } + + @Test + public void testWeeksAgo2() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale); + assertEquals("3 tygodnie temu", t.formatUnrounded(new Date(0))); + assertEquals("3 tygodnie temu", t.format(new Date(0))); + } + + @Test + public void testMonthsAgo1() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L), locale); + assertEquals("1 miesiąc temu", t.formatUnrounded(new Date(0))); + assertEquals("1 miesiąc temu", t.format(new Date(0))); + } + + @Test + public void testMonthsAgo2() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale); + assertEquals("3 miesiące temu", t.formatUnrounded(new Date(0))); + assertEquals("3 miesiące temu", t.format(new Date(0))); + } + + @Test + public void testMonthsAgo3() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 5L), locale); + assertEquals("5 miesięcy temu", t.formatUnrounded(new Date(0))); + assertEquals("5 miesięcy temu", t.format(new Date(0))); + } + + @Test + public void testYearsAgo1() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 12L), locale); + assertEquals("1 rok temu", t.formatUnrounded(new Date(0))); + assertEquals("1 rok temu", t.format(new Date(0))); + } + + @Test + public void testYearsAgo2() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale); + assertEquals("3 lata temu", t.formatUnrounded(new Date(0))); + assertEquals("3 lata temu", t.format(new Date(0))); + } + + @Test + public void testYearsAgo3() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 5L), locale); + assertEquals("5 lat temu", t.formatUnrounded(new Date(0))); + assertEquals("5 lat temu", t.format(new Date(0))); + } + + @Test + public void testDecadesAgo1() throws Exception + { + PrettyTime t = new PrettyTime(new Date(315569259747L), locale); + assertEquals("1 dekadę temu", t.formatUnrounded(new Date(0))); + assertEquals("1 dekadę temu", t.format(new Date(0))); + } + + @Test + public void testDecadesAgo2() throws Exception + { + PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale); + assertEquals("3 dekady temu", t.formatUnrounded(new Date(0))); + assertEquals("3 dekady temu", t.format(new Date(0))); + } + + @Test + public void testDecadesAgo3() throws Exception + { + PrettyTime t = new PrettyTime(new Date(315569259747L * 5L), locale); + assertEquals("5 dekad temu", t.formatUnrounded(new Date(0))); + assertEquals("5 dekad temu", t.format(new Date(0))); + } + + @Test + public void testCenturiesAgo1() throws Exception + { + PrettyTime t = new PrettyTime(new Date(3155692597470L), locale); + assertEquals("1 wiek temu", t.formatUnrounded(new Date(0))); + assertEquals("1 wiek temu", t.format(new Date(0))); + } + + @Test + public void testCenturiesAgo2() throws Exception + { + PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale); + assertEquals("3 wieki temu", t.formatUnrounded(new Date(0))); + assertEquals("3 wieki temu", t.format(new Date(0))); + } + + @Test + public void testCenturiesAgo3() throws Exception + { + PrettyTime t = new PrettyTime(new Date(3155692597470L * 5L), locale); + assertEquals("5 wieków temu", t.formatUnrounded(new Date(0))); + assertEquals("5 wieków temu", t.format(new Date(0))); + } + + @After + public void tearDown() throws Exception + { + Locale.setDefault(locale); + } +} From b79faa3a2943102967869e4c8066dfe29cf862b7 Mon Sep 17 00:00:00 2001 From: Christian Strebel Date: Fri, 27 Aug 2021 14:56:02 +0200 Subject: [PATCH 089/147] Fix #224 move format out of synchronized block --- .../java/org/ocpsoft/prettytime/jsf/PrettyTimeConverter.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jsf/src/main/java/org/ocpsoft/prettytime/jsf/PrettyTimeConverter.java b/jsf/src/main/java/org/ocpsoft/prettytime/jsf/PrettyTimeConverter.java index 96b44ee0..4d9dd279 100644 --- a/jsf/src/main/java/org/ocpsoft/prettytime/jsf/PrettyTimeConverter.java +++ b/jsf/src/main/java/org/ocpsoft/prettytime/jsf/PrettyTimeConverter.java @@ -59,12 +59,13 @@ public String getAsString(final FacesContext context, final UIComponent comp, fi { // Use locale of current viewer. Locale locale = context.getViewRoot().getLocale(); + PrettyTime prettyTime; synchronized (PRETTY_TIME_LOCALE_MAP) { - return PRETTY_TIME_LOCALE_MAP.computeIfAbsent(locale, PrettyTime::new) - .format((Date) value); + prettyTime = PRETTY_TIME_LOCALE_MAP.computeIfAbsent(locale, PrettyTime::new); } + return prettyTime.format((Date) value); } throw new ConverterException("May only be used to convert java.util.Date objects. Got: " + (value != null ? value.getClass() : "null")); } From 92ff937392604d601dce8b7cb14346c42859d570 Mon Sep 17 00:00:00 2001 From: Oliver Becker Date: Tue, 7 Sep 2021 10:53:18 +0200 Subject: [PATCH 090/147] Fix for #227: Wrong grammatical case in german locale when formatting a list of durations Fix for the logic that adjusts the german grammatical case for some units in the `decorate` and `decorateUnrounded` methods. The new logic replaces all occurrences of words that need to be adjusted in the translated time string, the old logic did this only for single durations. This should also fix issue #220, because the new logic simply replaces plural words and doesn't check if the duration is a plural duration. Contains also a minor improvement in SimpleTimeFormat.isPlural() that prevents computing the same number twice. Fix formatting. --- .../org/ocpsoft/prettytime/PrettyTime.java | 40 ++--- .../prettytime/format/SimpleTimeFormat.java | 10 +- .../ocpsoft/prettytime/i18n/Resources_de.java | 45 +++-- .../prettytime/PrettyTimeI18n_DE_Test.java | 170 +++++++++--------- 4 files changed, 134 insertions(+), 131 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index 515e1204..a79339ac 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -366,8 +366,8 @@ public Duration approximateDuration(LocalDate then) * the given {@link LocalDate} is null, the current value of {@link System#currentTimeMillis()} will be * used instead. * - * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference - * timestamp was provided + * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference + * timestamp was provided * @param zoneId The {@link ZoneId} to be used, not null * @see #getReference() */ @@ -382,7 +382,7 @@ public Duration approximateDuration(LocalDate then, final ZoneId zoneId) * will be used instead. * * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference - * timestamp was provided + * timestamp was provided * @see #getReference() */ public Duration approximateDuration(LocalDateTime then) @@ -395,8 +395,8 @@ public Duration approximateDuration(LocalDateTime then) * If the given {@link LocalDateTime} is null, the current value of {@link System#currentTimeMillis()} * will be used instead. * - * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference - * timestamp was provided + * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference + * timestamp was provided * @param zoneId The {@link ZoneId} to be used, not null * @see #getReference() */ @@ -414,7 +414,7 @@ public Duration approximateDuration(LocalDateTime then, final ZoneId zoneId) * of time (in milliseconds). * * @param then The {@link Date} to be compared against the reference timestamp, or now if no reference - * timestamp was provided + * timestamp was provided * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference @@ -434,7 +434,7 @@ public List calculatePreciseDuration(final Date then) * of time (in milliseconds). * * @param then The {@link Instant} to be compared against the reference timestamp, or now if no reference - * timestamp was provided + * timestamp was provided * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference @@ -476,7 +476,7 @@ public List calculatePreciseDuration(Instant then) * of time (in milliseconds). * * @param then The {@link LocalDateTime} to be compared against the reference timestamp, or now if no - * reference timestamp was provided + * reference timestamp was provided * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference @@ -496,8 +496,8 @@ public List calculatePreciseDuration(final LocalDateTime then) * Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder * of time (in milliseconds). * - * @param then The {@link LocalDateTime} to be compared against the reference timestamp, or now if no - * reference timestamp was provided + * @param then The {@link LocalDateTime} to be compared against the reference timestamp, or now if no + * reference timestamp was provided * @param zoneId The {@link ZoneId} to be used, not null * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous @@ -519,7 +519,7 @@ public List calculatePreciseDuration(final LocalDateTime then, final Z * of time (in milliseconds). * * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference - * timestamp was provided + * timestamp was provided * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous * element's delta. The first element is the largest {@link TimeUnit} to fit within the total difference @@ -539,8 +539,8 @@ public List calculatePreciseDuration(final LocalDate then) * Note: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder * of time (in milliseconds). * - * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference - * timestamp was provided + * @param then The {@link LocalDate} to be compared against the reference timestamp, or now if no reference + * timestamp was provided * @param zoneId The {@link ZoneId} to be used, not null * @return A sorted {@link List} of {@link Duration} objects, from largest to smallest. Each element in the list * represents the approximate duration (number of times) that {@link TimeUnit} to fit into the previous @@ -674,7 +674,7 @@ public String format(final OffsetDateTime then) * Format the given {@link LocalDateTime} object using the given {@link ZoneId}. If the given {@link LocalDateTime} * is null, the current value of {@link System#currentTimeMillis()} will be used instead. * - * @param then the {@link LocalDateTime} to be formatted + * @param then the {@link LocalDateTime} to be formatted * @param zoneId the {@link ZoneId} to be used, not null * @return A formatted string representing {@code then} */ @@ -704,7 +704,7 @@ public String format(final LocalDateTime then) * This assumes that the time of the given date is midnight. *

* - * @param then the {@link LocalDate} to be formatted + * @param then the {@link LocalDate} to be formatted * @param zoneId the {@link ZoneId} to be used, not null * @return A formatted string representing {@code then} */ @@ -848,7 +848,7 @@ public String formatUnrounded(final OffsetDateTime then) * given {@link LocalDateTime} is null, the current value of {@link System#currentTimeMillis()} will be * used instead. * - * @param then the {@link LocalDateTime} to be formatted + * @param then the {@link LocalDateTime} to be formatted * @param zoneId the {@link ZoneId} to be used, not null * @return A formatted string representing {@code then} */ @@ -879,7 +879,7 @@ public String formatUnrounded(final LocalDateTime then) * This assumes that the time of the given date is midnight. *

* - * @param then the {@link LocalDate} to be formatted + * @param then the {@link LocalDate} to be formatted * @param zoneId the {@link ZoneId} to be used, not null * @return A formatted string representing {@code then} */ @@ -1043,7 +1043,7 @@ public String formatDuration(final OffsetDateTime then) * {@link System#currentTimeMillis()} will be used instead. *

* - * @param then the {@link LocalDateTime} to be formatted + * @param then the {@link LocalDateTime} to be formatted * @param zoneId the {@link ZoneId} to be used, not null * @return A formatted string of the given {@link LocalDateTime} */ @@ -1077,7 +1077,7 @@ public String formatDuration(final LocalDateTime then) * This assumes that the time of the given date is midnight. *

* - * @param then the {@link LocalDate} to be formatted + * @param then the {@link LocalDate} to be formatted * @param zoneId the {@link ZoneId} to be used, not null * @return A formatted string of the given {@link LocalDate} */ @@ -1466,7 +1466,7 @@ public PrettyTime registerUnit(final TimeUnit unit, TimeFormat format) cachedUnits = null; units.put(Objects.requireNonNull(unit, "TimeUnit to register must not be null."), - Objects.requireNonNull(format, "TimeFormat to register must not be null.")); + Objects.requireNonNull(format, "TimeFormat to register must not be null.")); if (unit instanceof LocaleAware) ((LocaleAware) unit).setLocale(locale); if (format instanceof LocaleAware) diff --git a/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java b/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java index c2393154..88b837f5 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java +++ b/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java @@ -128,7 +128,7 @@ protected long getQuantity(Duration duration, boolean round) return Math.abs(round ? duration.getQuantityRounded(roundingTolerance) : duration.getQuantity()); } - protected String getGramaticallyCorrectName(final Duration d, boolean round) + protected String getGramaticallyCorrectName(final Duration d, final boolean round) { String result = getSingularName(d); if (isPlural(d, round)) { @@ -137,9 +137,10 @@ protected String getGramaticallyCorrectName(final Duration d, boolean round) return result; } - protected boolean isPlural(final Duration d, boolean round) + protected boolean isPlural(final Duration d, final boolean round) { - return (Math.abs(getQuantity(d, round)) == 0) || (Math.abs(getQuantity(d, round)) > 1); + final long quantity = Math.abs(getQuantity(d, round)); + return (quantity == 0) || (quantity > 1); } private String getSign(final Duration d) @@ -206,9 +207,6 @@ public SimpleTimeFormat setPastSuffix(final String pastSuffix) /** * The percentage of the current {@link TimeUnit}.getMillisPerUnit() for which the quantity may be rounded up by one. - * - * @param roundingTolerance - * @return */ public SimpleTimeFormat setRoundingTolerance(final int roundingTolerance) { diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_de.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_de.java index d123c823..f8666b38 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_de.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_de.java @@ -16,7 +16,13 @@ package org.ocpsoft.prettytime.i18n; import java.util.ListResourceBundle; +import java.util.Map; import java.util.ResourceBundle; +import java.util.function.Function; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.ocpsoft.prettytime.Duration; import org.ocpsoft.prettytime.TimeFormat; @@ -130,14 +136,22 @@ protected Object[][] getContents() @Override public TimeFormat getFormatFor(TimeUnit t) { - return new DeTimeFormat(this, t, t.getClass().getSimpleName()); + return new DeTimeFormat(this, t); } private static class DeTimeFormat extends SimpleTimeFormat { + // Map for changing all occurring nominative plurals to dative (for achieving "in x Jahren" or "vor x Monaten") + private static final Map unitsToAdjust = Stream + .of("Jahrtausende", "Jahrhunderte", "Jahrzehnte", "Jahre", "Monate", "Tage") + .collect(Collectors.toMap(Function.identity(), s -> s + "n")); - public DeTimeFormat(final ResourceBundle bundle, final TimeUnit unit, String prefix) + private static final Pattern grammerReplacementPattern = Pattern + .compile("\\b(" + String.join("|", unitsToAdjust.keySet()) + ")\\b"); + + public DeTimeFormat(final ResourceBundle bundle, final TimeUnit unit) { + String prefix = unit.getClass().getSimpleName(); setPattern(bundle.getString(prefix + "Pattern")); setFuturePrefix(bundle.getString(prefix + "FuturePrefix")); setFutureSuffix(bundle.getString(prefix + "FutureSuffix")); @@ -150,26 +164,25 @@ public DeTimeFormat(final ResourceBundle bundle, final TimeUnit unit, String pre @Override public String decorate(Duration duration, String time) { - // Change the nominative plural to dative by appending an "n" (Tage -> Tagen / Monate -> Monaten) - if (isPlural(duration, true)) { - if (time != null && time.trim().length() > 0 && !time.endsWith("n")) { - time += "n"; - } - } - return super.decorate(duration, time); + return super.decorate(duration, adjustGrammar(time)); } @Override public String decorateUnrounded(Duration duration, String time) { - // Change the nominative plural to dative by appending an "n" (Tage -> Tagen / Monate -> Monaten) - if (isPlural(duration, false)) { - if (time != null && time.trim().length() > 0 && !time.endsWith("n")) { - time += "n"; - } + return super.decorateUnrounded(duration, adjustGrammar(time)); + } + + private String adjustGrammar(String time) + { + Matcher matcher = grammerReplacementPattern.matcher(time); + StringBuffer sb = new StringBuffer(); + while (matcher.find()) { + matcher.appendReplacement(sb, unitsToAdjust.get(matcher.group(1))); } - return super.decorateUnrounded(duration, time); + matcher.appendTail(sb); + + return sb.toString(); } } - } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_DE_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_DE_Test.java index 50a32633..f699014d 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_DE_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_DE_Test.java @@ -1,169 +1,161 @@ -/** +/* * @author hertg */ package org.ocpsoft.prettytime; import static org.junit.Assert.assertEquals; -import java.util.Calendar; -import java.util.Date; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.List; import java.util.Locale; -import org.junit.After; import org.junit.Before; import org.junit.Test; public class PrettyTimeI18n_DE_Test { - private Locale locale; - private Date base; + private LocalDateTime base; private PrettyTime prettyTime; @Before public void setUp() throws Exception { - locale = new Locale("de"); - base = new Date(); - prettyTime = new PrettyTime(base, locale); + base = LocalDateTime.parse("2020-09-20T12:00:00"); + prettyTime = new PrettyTime(base); + prettyTime.setLocale(Locale.GERMAN); } @Test public void testGrammaticalCaseMilliseconds() { - assertEquals("gerade eben", prettyTime.format(addTime(-5, Calendar.MILLISECOND))); - assertEquals("gerade eben", prettyTime.format(addTime(-1, Calendar.MILLISECOND))); - assertEquals("Jetzt", prettyTime.format(addTime(5, Calendar.MILLISECOND))); - assertEquals("Jetzt", prettyTime.format(addTime(1, Calendar.MILLISECOND))); + assertEquals("gerade eben", prettyTime.format(base.minus(5, ChronoUnit.MILLIS))); + assertEquals("gerade eben", prettyTime.format(base.minus(1, ChronoUnit.MILLIS))); + assertEquals("Jetzt", prettyTime.format(base.plus(5, ChronoUnit.MILLIS))); + assertEquals("Jetzt", prettyTime.format(base.plus(1, ChronoUnit.MILLIS))); // the following tests are commented out, because the formatDuration() method // only returns an empty string for durations in the milliseconds - // assertEquals("5 Millisekunden", prettyTime.formatDuration(addTime(-5, Calendar.MILLISECOND))); - // assertEquals("1 Millisekunde", prettyTime.formatDuration(addTime(-1, Calendar.MILLISECOND))); + // assertEquals("5 Millisekunden", prettyTime.formatDuration(base.minus(5, Calendar.MILLISECOND))); + // assertEquals("1 Millisekunde", prettyTime.formatDuration(base.minus(1, Calendar.MILLISECOND))); } @Test public void testGrammaticalCaseSeconds() { - assertEquals("gerade eben", prettyTime.format(addTime(-5, Calendar.SECOND))); - assertEquals("gerade eben", prettyTime.format(addTime(-1, Calendar.SECOND))); - assertEquals("Jetzt", prettyTime.format(addTime(5, Calendar.SECOND))); - assertEquals("Jetzt", prettyTime.format(addTime(1, Calendar.SECOND))); + assertEquals("gerade eben", prettyTime.format(base.minus(5, ChronoUnit.SECONDS))); + assertEquals("gerade eben", prettyTime.format(base.minus(1, ChronoUnit.SECONDS))); + assertEquals("Jetzt", prettyTime.format(base.plus(5, ChronoUnit.SECONDS))); + assertEquals("Jetzt", prettyTime.format(base.plus(1, ChronoUnit.SECONDS))); // the following tests are commented out, because the formatDuration() method // only returns an empty string for durations in the seconds - // assertEquals("5 Sekunden", prettyTime.formatDuration(addTime(-5, Calendar.SECOND))); - // assertEquals("1 Sekunde", prettyTime.formatDuration(addTime(-1, Calendar.SECOND))); + // assertEquals("5 Sekunden", prettyTime.formatDuration(base.minus(5, ChronoUnit.SECONDS))); + // assertEquals("1 Sekunde", prettyTime.formatDuration(base.minus(1, ChronoUnit.SECONDS))); } @Test public void testGrammaticalCaseMinutes() { - assertEquals("vor 5 Minuten", prettyTime.format(addTime(-5, Calendar.MINUTE))); - assertEquals("vor 1 Minute", prettyTime.format(addTime(-1, Calendar.MINUTE))); - assertEquals("in 5 Minuten", prettyTime.format(addTime(5, Calendar.MINUTE))); - assertEquals("in 1 Minute", prettyTime.format(addTime(1, Calendar.MINUTE))); - assertEquals("5 Minuten", prettyTime.formatDuration(addTime(-5, Calendar.MINUTE))); - assertEquals("1 Minute", prettyTime.formatDuration(addTime(-1, Calendar.MINUTE))); + assertEquals("vor 5 Minuten", prettyTime.format(base.minus(5, ChronoUnit.MINUTES))); + assertEquals("vor 1 Minute", prettyTime.format(base.minus(1, ChronoUnit.MINUTES))); + assertEquals("in 5 Minuten", prettyTime.format(base.plus(5, ChronoUnit.MINUTES))); + assertEquals("in 1 Minute", prettyTime.format(base.plus(1, ChronoUnit.MINUTES))); + assertEquals("5 Minuten", prettyTime.formatDuration(base.minus(5, ChronoUnit.MINUTES))); + assertEquals("1 Minute", prettyTime.formatDuration(base.minus(1, ChronoUnit.MINUTES))); } @Test public void testGrammaticalCaseHours() { - assertEquals("vor 5 Stunden", prettyTime.format(addTime(-5, Calendar.HOUR))); - assertEquals("vor 1 Stunde", prettyTime.format(addTime(-1, Calendar.HOUR))); - assertEquals("in 5 Stunden", prettyTime.format(addTime(5, Calendar.HOUR))); - assertEquals("in 1 Stunde", prettyTime.format(addTime(1, Calendar.HOUR))); - assertEquals("5 Stunden", prettyTime.formatDuration(addTime(-5, Calendar.HOUR))); - assertEquals("1 Stunde", prettyTime.formatDuration(addTime(-1, Calendar.HOUR))); + assertEquals("vor 5 Stunden", prettyTime.format(base.minus(5, ChronoUnit.HOURS))); + assertEquals("vor 1 Stunde", prettyTime.format(base.minus(1, ChronoUnit.HOURS))); + assertEquals("in 5 Stunden", prettyTime.format(base.plus(5, ChronoUnit.HOURS))); + assertEquals("in 1 Stunde", prettyTime.format(base.plus(1, ChronoUnit.HOURS))); + assertEquals("5 Stunden", prettyTime.formatDuration(base.minus(5, ChronoUnit.HOURS))); + assertEquals("1 Stunde", prettyTime.formatDuration(base.minus(1, ChronoUnit.HOURS))); } @Test public void testGrammaticalCaseDays() { - assertEquals("vor 5 Tagen", prettyTime.format(addTime(-5, Calendar.DAY_OF_MONTH))); - assertEquals("vor 1 Tag", prettyTime.format(addTime(-1, Calendar.DAY_OF_MONTH))); - assertEquals("in 5 Tagen", prettyTime.format(addTime(5, Calendar.DAY_OF_MONTH))); - assertEquals("in 1 Tag", prettyTime.format(addTime(1, Calendar.DAY_OF_MONTH))); - assertEquals("5 Tage", prettyTime.formatDuration(addTime(-5, Calendar.DAY_OF_MONTH))); - assertEquals("1 Tag", prettyTime.formatDuration(addTime(-1, Calendar.DAY_OF_MONTH))); + assertEquals("vor 5 Tagen", prettyTime.format(base.minus(5, ChronoUnit.DAYS))); + assertEquals("vor 1 Tag", prettyTime.format(base.minus(1, ChronoUnit.DAYS))); + assertEquals("in 5 Tagen", prettyTime.format(base.plus(5, ChronoUnit.DAYS))); + assertEquals("in 1 Tag", prettyTime.format(base.plus(1, ChronoUnit.DAYS))); + assertEquals("5 Tage", prettyTime.formatDuration(base.minus(5, ChronoUnit.DAYS))); + assertEquals("1 Tag", prettyTime.formatDuration(base.minus(1, ChronoUnit.DAYS))); } @Test public void testGrammaticalCaseMonths() { - assertEquals("vor 5 Monaten", prettyTime.format(addTime(-5, Calendar.MONTH))); - assertEquals("vor 1 Monat", prettyTime.format(addTime(-1, Calendar.MONTH))); - assertEquals("in 5 Monaten", prettyTime.format(addTime(5, Calendar.MONTH))); - assertEquals("in 1 Monat", prettyTime.format(addTime(1, Calendar.MONTH))); - assertEquals("5 Monate", prettyTime.formatDuration(addTime(-5, Calendar.MONTH))); - assertEquals("1 Monat", prettyTime.formatDuration(addTime(-1, Calendar.MONTH))); + assertEquals("vor 5 Monaten", prettyTime.format(base.minus(5, ChronoUnit.MONTHS))); + assertEquals("vor 1 Monat", prettyTime.format(base.minus(1, ChronoUnit.MONTHS))); + assertEquals("in 5 Monaten", prettyTime.format(base.plus(5, ChronoUnit.MONTHS))); + assertEquals("in 1 Monat", prettyTime.format(base.plus(1, ChronoUnit.MONTHS))); + assertEquals("5 Monate", prettyTime.formatDuration(base.minus(5, ChronoUnit.MONTHS))); + assertEquals("1 Monat", prettyTime.formatDuration(base.minus(1, ChronoUnit.MONTHS))); } @Test public void testGrammaticalCaseYears() { - assertEquals("vor 5 Jahren", prettyTime.format(addTime(-5, Calendar.YEAR))); - assertEquals("vor 1 Jahr", prettyTime.format(addTime(-1, Calendar.YEAR))); - assertEquals("in 5 Jahren", prettyTime.format(addTime(5, Calendar.YEAR))); - assertEquals("in 1 Jahr", prettyTime.format(addTime(13, Calendar.MONTH))); - assertEquals("5 Jahre", prettyTime.formatDuration(addTime(-5, Calendar.YEAR))); - assertEquals("1 Jahr", prettyTime.formatDuration(addTime(-1, Calendar.YEAR))); + assertEquals("vor 5 Jahren", prettyTime.format(base.minus(5, ChronoUnit.YEARS))); + assertEquals("vor 1 Jahr", prettyTime.format(base.minus(1, ChronoUnit.YEARS))); + assertEquals("in 5 Jahren", prettyTime.format(base.plus(5, ChronoUnit.YEARS))); + assertEquals("in 1 Jahr", prettyTime.format(base.plus(13, ChronoUnit.MONTHS))); + assertEquals("5 Jahre", prettyTime.formatDuration(base.minus(5, ChronoUnit.YEARS))); + assertEquals("1 Jahr", prettyTime.formatDuration(base.plus(13, ChronoUnit.MONTHS))); } @Test public void testGrammaticalCaseDecades() { - assertEquals("vor 5 Jahrzehnten", prettyTime.format(addTime(-50, Calendar.YEAR))); - assertEquals("vor 1 Jahrzehnt", prettyTime.format(addTime(-10, Calendar.YEAR))); - assertEquals("in 5 Jahrzehnten", prettyTime.format(addTime(50, Calendar.YEAR))); - assertEquals("in 1 Jahrzehnt", prettyTime.format(addTime(11, Calendar.YEAR))); - assertEquals("5 Jahrzehnte", prettyTime.formatDuration(addTime(-50, Calendar.YEAR))); - assertEquals("1 Jahrzehnt", prettyTime.formatDuration(addTime(-10, Calendar.YEAR))); + assertEquals("vor 5 Jahrzehnten", prettyTime.format(base.minus(50, ChronoUnit.YEARS))); + assertEquals("vor 1 Jahrzehnt", prettyTime.format(base.minus(10, ChronoUnit.YEARS))); + assertEquals("in 5 Jahrzehnten", prettyTime.format(base.plus(50, ChronoUnit.YEARS))); + assertEquals("in 1 Jahrzehnt", prettyTime.format(base.plus(11, ChronoUnit.YEARS))); + assertEquals("5 Jahrzehnte", prettyTime.formatDuration(base.minus(50, ChronoUnit.YEARS))); + assertEquals("1 Jahrzehnt", prettyTime.formatDuration(base.minus(10, ChronoUnit.YEARS))); } @Test public void testGrammaticalCaseCenturies() { - assertEquals("vor 5 Jahrhunderten", prettyTime.format(addTime(-500, Calendar.YEAR))); - assertEquals("vor 1 Jahrhundert", prettyTime.format(addTime(-100, Calendar.YEAR))); - assertEquals("in 5 Jahrhunderten", prettyTime.format(addTime(500, Calendar.YEAR))); - assertEquals("in 1 Jahrhundert", prettyTime.format(addTime(101, Calendar.YEAR))); - assertEquals("5 Jahrhunderte", prettyTime.formatDuration(addTime(-500, Calendar.YEAR))); - assertEquals("1 Jahrhundert", prettyTime.formatDuration(addTime(-100, Calendar.YEAR))); + assertEquals("vor 5 Jahrhunderten", prettyTime.format(base.minus(500, ChronoUnit.YEARS))); + assertEquals("vor 1 Jahrhundert", prettyTime.format(base.minus(100, ChronoUnit.YEARS))); + assertEquals("in 5 Jahrhunderten", prettyTime.format(base.plus(500, ChronoUnit.YEARS))); + assertEquals("in 1 Jahrhundert", prettyTime.format(base.plus(101, ChronoUnit.YEARS))); + assertEquals("5 Jahrhunderte", prettyTime.formatDuration(base.minus(500, ChronoUnit.YEARS))); + assertEquals("1 Jahrhundert", prettyTime.formatDuration(base.minus(100, ChronoUnit.YEARS))); } @Test public void testGrammaticalCaseMillenia() { - assertEquals("vor 5 Jahrtausenden", prettyTime.format(addTime(-5000, Calendar.YEAR))); - assertEquals("vor 1 Jahrtausend", prettyTime.format(addTime(-1001, Calendar.YEAR))); - assertEquals("in 5 Jahrtausenden", prettyTime.format(addTime(5000, Calendar.YEAR))); - assertEquals("in 1 Jahrtausend", prettyTime.format(addTime(1001, Calendar.YEAR))); - assertEquals("5 Jahrtausende", prettyTime.formatDuration(addTime(-5000, Calendar.YEAR))); - assertEquals("1 Jahrtausend", prettyTime.formatDuration(addTime(-1001, Calendar.YEAR))); + assertEquals("vor 5 Jahrtausenden", prettyTime.format(base.minus(5000, ChronoUnit.YEARS))); + assertEquals("vor 1 Jahrtausend", prettyTime.format(base.minus(1000, ChronoUnit.YEARS))); + assertEquals("in 5 Jahrtausenden", prettyTime.format(base.plus(5000, ChronoUnit.YEARS))); + assertEquals("in 1 Jahrtausend", prettyTime.format(base.plus(1001, ChronoUnit.YEARS))); + assertEquals("5 Jahrtausende", prettyTime.formatDuration(base.minus(5000, ChronoUnit.YEARS))); + assertEquals("1 Jahrtausend", prettyTime.formatDuration(base.minus(1000, ChronoUnit.YEARS))); } - // Method tearDown() is called automatically after every test method - @After - public void tearDown() throws Exception - { - Locale.setDefault(locale); - } - - /** - * Helper method to simplify unit tests and prevent code duplicates. - * - * @param amount Amount of time to add - * @param field Calendar field (ie. {@link Calendar#HOUR}, {@link Calendar#YEAR}) - * @return Date with the added quantity of time - */ - private Date addTime(int amount, int field) + @Test + public void testGrammaticalCasesForMultipleDurations() { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(base); - calendar.add(field, amount); - return calendar.getTime(); + LocalDateTime then = base.minus(2, ChronoUnit.YEARS) + .minus(3, ChronoUnit.MONTHS) + .minus(4, ChronoUnit.DAYS) + .minus(6, ChronoUnit.HOURS) + .minus(30, ChronoUnit.MINUTES); + final List durations = prettyTime.calculatePreciseDuration(then); + + // note: days are not accurate due to a contained leap year, + // hours and minutes are not accurate on the scale of years + // (a prettytime year has always about 365,242 days) + assertEquals("vor 2 Jahren 3 Monaten 5 Tagen 11 Stunden 25 Minuten", prettyTime.format(durations)); } - } From 35e9d838a1d0edfba6c7ae4dd3ca0d80b0c4bca6 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Wed, 8 Sep 2021 15:35:54 -0400 Subject: [PATCH 091/147] Document code formatter settings. --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index f0817cdb..e61f4e2d 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,9 @@ Be sure to check maven central for the latest version: https://repo1.maven.org/m DEVELOPMENT =========== force-release: mvn release:prepare release:perform -DskipTests=true -DdevelopmentVersion=4.0.2-SNAPSHOT -DreleaseVersion=4.0.1.Final -Dtag=4.0.1.Final -Darguments="-DskipTests=true -Dmaven.test.skip=true" + +CODE FORMAT DEFINITIONS/CONFIG +============================== +Please use the following eclipse-style code formatter settings when submitting PRs: + +https://github.com/ocpsoft/common/blob/master/ocpsoft-eclipse-code-format.xml From d170bcb6db57222e2e61afc8b1d54408f9f7e3fe Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Wed, 8 Sep 2021 15:36:52 -0400 Subject: [PATCH 092/147] Remove stale changelog. --- CHANGELOG.txt | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 CHANGELOG.txt diff --git a/CHANGELOG.txt b/CHANGELOG.txt deleted file mode 100644 index 45c59540..00000000 --- a/CHANGELOG.txt +++ /dev/null @@ -1,17 +0,0 @@ -=== 1.0.8 === -Support for outputting formatted lists of Duration objects - nessumo -Japanese - Eric Silverberg -Swedish - Anders Hedström - -=== 1.0.7 === - -Croatian - Miroslav Rešetar -Vientamese - Xuân Tính - http://www.tinhtruong.info/2010/06/vietnamese-resource-bundle-for.html -Turkish - Halil -Norwegian - Magnus Byrkjeflot - www.mylog.no -Estonian - Matti Jagula -Polish - Upender Gilakathula -Romanian - Upender Gilakathula -Hungarian - Balázs Németh - -=== 1.0.6 and Previous === \ No newline at end of file From bb139e3643747b70c24ab769d7227335c493c420 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Wed, 8 Sep 2021 15:40:43 -0400 Subject: [PATCH 093/147] [maven-release-plugin] prepare release 5.0.2.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index dda3879c..d9e3ef1f 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.2-SNAPSHOT + 5.0.2.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 21b671a3..f623e7ee 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.2-SNAPSHOT + 5.0.2.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 7bcf489b..0e63748f 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.2-SNAPSHOT + 5.0.2.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index e64a2a22..4250fcb9 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.2-SNAPSHOT + 5.0.2.Final ../pom.xml diff --git a/pom.xml b/pom.xml index 86891e17..4de511eb 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.2-SNAPSHOT + 5.0.2.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 5.0.2.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 7de0d38a..9e07eca2 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.2-SNAPSHOT + 5.0.2.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.2-SNAPSHOT + 5.0.2.Final diff --git a/samples/pom.xml b/samples/pom.xml index 477dc3c6..c159ea13 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.2-SNAPSHOT + 5.0.2.Final 4.0.0 From 057edc19de6bf9b654548fa03cc307c97e742a17 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Wed, 8 Sep 2021 15:40:43 -0400 Subject: [PATCH 094/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index d9e3ef1f..a0144b31 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.2.Final + 5.0.3-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index f623e7ee..3dc77d3d 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.2.Final + 5.0.3-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 0e63748f..3f087581 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.2.Final + 5.0.3-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 4250fcb9..bd579ea8 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.2.Final + 5.0.3-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index 4de511eb..81ac6de2 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.2.Final + 5.0.3-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 5.0.2.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 9e07eca2..d57a0d13 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.2.Final + 5.0.3-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.2.Final + 5.0.3-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index c159ea13..6277479c 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.2.Final + 5.0.3-SNAPSHOT 4.0.0 From b21d33b3021420717a30d89dfbcea5ee537a5eaa Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Wed, 8 Sep 2021 15:41:47 -0400 Subject: [PATCH 095/147] Update build instructions. --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e61f4e2d..3f6294a4 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,10 @@ Be sure to check maven central for the latest version: https://repo1.maven.org/m DEVELOPMENT =========== -force-release: mvn release:prepare release:perform -DskipTests=true -DdevelopmentVersion=4.0.2-SNAPSHOT -DreleaseVersion=4.0.1.Final -Dtag=4.0.1.Final -Darguments="-DskipTests=true -Dmaven.test.skip=true" +export RELEASE_VERSION="5.x.x.Final" +export SNAPSHOT_VERSION="5.x.x-SNAPSHOT" + +force-release: mvn release:prepare release:perform -DskipTests=true -DdevelopmentVersion=$SNAPSHOT_VERSION -DreleaseVersion=$RELEASE_VERSION -Dtag=$RELEASE_VERSION -Darguments="-DskipTests=true -Dmaven.test.skip=true" CODE FORMAT DEFINITIONS/CONFIG ============================== From 1add203563496af9bea32f0f57a784ef17d467ab Mon Sep 17 00:00:00 2001 From: astatio <29357305+astatio@users.noreply.github.com> Date: Sun, 24 Apr 2022 15:53:09 +0100 Subject: [PATCH 096/147] Workaround NPE in format(List) Transforming the units to String makes them "findable". Added a throw to format(List) because getting an NPE without any message is not good. --- .../main/java/org/ocpsoft/prettytime/PrettyTime.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index a79339ac..93b97eb4 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -621,6 +621,9 @@ public String format(final List durations) for (int i = 0; i < durations.size(); i++) { duration = durations.get(i); format = getFormat(duration.getUnit()); + // check if format is null, if so, throw an exception + if (format == null) + throw new IllegalArgumentException("Unsupported time unit: " + duration.getUnit()); /* * Round only the last element @@ -1302,10 +1305,15 @@ public String formatDurationUnrounded(final LocalDate then) */ public TimeFormat getFormat(TimeUnit unit) { - if (unit != null && units.get(unit) != null) { + if (unit == null) return null; + if (units.get(unit) != null) { return units.get(unit); + } 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))); + return map.get(unit.toString()); } - return null; } /** From 91a6324ed7d1ec412c7321ac8d43d8b8cc3c3e24 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Wed, 18 May 2022 13:43:37 -0400 Subject: [PATCH 097/147] [maven-release-plugin] prepare release 5.0.3.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index a0144b31..b48119a9 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.3-SNAPSHOT + 5.0.3.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 3dc77d3d..7e4ec69d 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.3-SNAPSHOT + 5.0.3.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 3f087581..347b91ad 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.3-SNAPSHOT + 5.0.3.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index bd579ea8..9095513a 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.3-SNAPSHOT + 5.0.3.Final ../pom.xml diff --git a/pom.xml b/pom.xml index 81ac6de2..21bfd014 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.3-SNAPSHOT + 5.0.3.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 5.0.3.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index d57a0d13..15e83c30 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.3-SNAPSHOT + 5.0.3.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.3-SNAPSHOT + 5.0.3.Final diff --git a/samples/pom.xml b/samples/pom.xml index 6277479c..e9a2f16f 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.3-SNAPSHOT + 5.0.3.Final 4.0.0 From d1fdafcb7d8752737d22d1e9c10a8ff9e52d188f Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Wed, 18 May 2022 13:43:37 -0400 Subject: [PATCH 098/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index b48119a9..78a70b31 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.3.Final + 5.0.4-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 7e4ec69d..7772433e 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.3.Final + 5.0.4-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 347b91ad..948b2cb7 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.3.Final + 5.0.4-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 9095513a..4835a17f 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.3.Final + 5.0.4-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index 21bfd014..b5b51109 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.3.Final + 5.0.4-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 5.0.3.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 15e83c30..30ba26b3 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.3.Final + 5.0.4-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.3.Final + 5.0.4-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index e9a2f16f..3ab10b4a 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.3.Final + 5.0.4-SNAPSHOT 4.0.0 From 343b5413b961fb60f7a909dd45d17d4039e3afe0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 7 Jul 2022 22:06:43 +0000 Subject: [PATCH 099/147] Bump jetty-server from 9.4.41.v20210516 to 10.0.10 in /samples/jstl Bumps [jetty-server](https://github.com/eclipse/jetty.project) from 9.4.41.v20210516 to 10.0.10. - [Release notes](https://github.com/eclipse/jetty.project/releases) - [Commits](https://github.com/eclipse/jetty.project/compare/jetty-9.4.41.v20210516...jetty-10.0.10) --- updated-dependencies: - dependency-name: org.eclipse.jetty:jetty-server dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- samples/jstl/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 30ba26b3..4f771bc2 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -15,7 +15,7 @@ org.eclipse.jetty jetty-server - 9.4.41.v20210516 + 10.0.10 org.eclipse.jetty From 15b1412fec456ac5a11c9cc7c2cc9320b94378b1 Mon Sep 17 00:00:00 2001 From: Baptiste Pernet Date: Thu, 14 Jul 2022 13:28:35 -0700 Subject: [PATCH 100/147] Issue #235: add reference date --- .../prettytime/nlp/PrettyTimeParser.java | 23 +++++++++++++------ .../prettytime/nlp/PrettyTimeParserTest.java | 15 ++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/nlp/src/main/java/org/ocpsoft/prettytime/nlp/PrettyTimeParser.java b/nlp/src/main/java/org/ocpsoft/prettytime/nlp/PrettyTimeParser.java index fb2f4fa1..1b14efdc 100644 --- a/nlp/src/main/java/org/ocpsoft/prettytime/nlp/PrettyTimeParser.java +++ b/nlp/src/main/java/org/ocpsoft/prettytime/nlp/PrettyTimeParser.java @@ -144,14 +144,23 @@ else if (number < 100) */ public List parse(String language) { - language = words2numbers(language); + return parse(language, new Date()); + } - List result = new ArrayList(); - List groups = parser.parse(language); - for (com.joestelmach.natty.DateGroup group : groups) { - result.addAll(group.getDates()); - } - return result; + /** + * Parse the given language and return a {@link List} with all discovered {@link Date} instances. + * + * @param referenceDate date to use as a reference for the parsing. + */ + public List parse(String language, Date referenceDate) { + language = words2numbers(language); + + List result = new ArrayList<>(); + List groups = parser.parse(language, referenceDate); + for (com.joestelmach.natty.DateGroup group : groups) { + result.addAll(group.getDates()); + } + return result; } /** diff --git a/nlp/src/test/java/org/ocpsoft/prettytime/nlp/PrettyTimeParserTest.java b/nlp/src/test/java/org/ocpsoft/prettytime/nlp/PrettyTimeParserTest.java index 62eb0af8..d2ee9471 100644 --- a/nlp/src/test/java/org/ocpsoft/prettytime/nlp/PrettyTimeParserTest.java +++ b/nlp/src/test/java/org/ocpsoft/prettytime/nlp/PrettyTimeParserTest.java @@ -97,4 +97,19 @@ public void testParseYesterday() Assert.assertEquals(yesterday.get(Calendar.MONTH), parsedDate.get(Calendar.MONTH)); Assert.assertEquals(yesterday.get(Calendar.YEAR), parsedDate.get(Calendar.YEAR)); } + + @Test + public void testParseYesterdayFromReferenceDate() + { + Date july14th2022 = new Date(1657830053000L); + List parse = new PrettyTimeParser().parse("yesterday", july14th2022); + + Assert.assertEquals(1, parse.size()); + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(parse.get(0)); + Assert.assertEquals(13, calendar.get(Calendar.DAY_OF_MONTH)); + Assert.assertEquals(6, calendar.get(Calendar.MONTH)); + Assert.assertEquals(2022, calendar.get(Calendar.YEAR)); + } } From 876567cf91b34b66e00f678b2ca1fb7ef6352e0e Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Thu, 1 Sep 2022 12:41:01 -0400 Subject: [PATCH 101/147] fix: #237 broken default constructor --- .../prettytime/nlp/PrettyTimeParser.java | 59 ++++++++++--------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/nlp/src/main/java/org/ocpsoft/prettytime/nlp/PrettyTimeParser.java b/nlp/src/main/java/org/ocpsoft/prettytime/nlp/PrettyTimeParser.java index 1b14efdc..884f86b0 100644 --- a/nlp/src/main/java/org/ocpsoft/prettytime/nlp/PrettyTimeParser.java +++ b/nlp/src/main/java/org/ocpsoft/prettytime/nlp/PrettyTimeParser.java @@ -15,8 +15,8 @@ import com.joestelmach.natty.Parser; /** - * A utility for parsing natural language date and time expressions. (e.g. "Let's get lunch at two pm", - * "I did it 3 days ago") + * A utility for parsing natural language date and time expressions. (e.g. "Let's get lunch at two pm", "I did it 3 days + * ago") *

* Usage: *

@@ -78,17 +78,13 @@ public class PrettyTimeParser public PrettyTimeParser(TimeZone timezone) { parser = new Parser(timezone); - } - /** - * Create a new {@link PrettyTimeParser} with the current system default {@link TimeZone}. - */ - public PrettyTimeParser() - { - this(TimeZone.getDefault()); - for (int hours = 0; hours < 24; hours++) - for (int min = 0; min < 60; min++) + for (int hours = 0; hours < 24; hours++) { + for (int min = 0; min < 60; min++) { translations.put(provideRepresentation(hours * 100 + min), "" + hours * 100 + min); + } + } + translations.put(provideRepresentation(60), "" + 60); translations.put(provideRepresentation(70), "" + 70); translations.put(provideRepresentation(80), "" + 80); @@ -105,6 +101,14 @@ public PrettyTimeParser() periods.add("from now"); } + /** + * Create a new {@link PrettyTimeParser} with the current system default {@link TimeZone}. + */ + public PrettyTimeParser() + { + this(TimeZone.getDefault()); + } + /** * Provides a string representation for the number passed. This method works for limited set of numbers as parsing * will only be done at maximum for 2400, which will be used in military time format. @@ -117,13 +121,11 @@ private String provideRepresentation(int number) key = "zero"; else if (number < 20) key = numNames[number]; - else if (number < 100) - { + else if (number < 100) { int unit = number % 10; key = tensNames[number / 10] + numNames[unit]; } - else - { + else { int unit = number % 10; int ten = number % 100 - unit; int hundred = (number - ten) / 100; @@ -147,20 +149,21 @@ public List parse(String language) return parse(language, new Date()); } - /** - * Parse the given language and return a {@link List} with all discovered {@link Date} instances. - * - * @param referenceDate date to use as a reference for the parsing. - */ - public List parse(String language, Date referenceDate) { - language = words2numbers(language); + /** + * Parse the given language and return a {@link List} with all discovered {@link Date} instances. + * + * @param referenceDate date to use as a reference for the parsing. + */ + public List parse(String language, Date referenceDate) + { + language = words2numbers(language); - List result = new ArrayList<>(); - List groups = parser.parse(language, referenceDate); - for (com.joestelmach.natty.DateGroup group : groups) { - result.addAll(group.getDates()); - } - return result; + List result = new ArrayList<>(); + List groups = parser.parse(language, referenceDate); + for (com.joestelmach.natty.DateGroup group : groups) { + result.addAll(group.getDates()); + } + return result; } /** From c8b2d4044ae7ada66a26a541e6d6b150f3ba019f Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Mon, 12 Sep 2022 11:49:14 -0400 Subject: [PATCH 102/147] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f6294a4..2e4ca099 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Android ======= To use prettytime in android, first add the following dependency to your app level build.gradle - implementation 'org.ocpsoft.prettytime:prettytime:4.0.4.Final' + implementation 'org.ocpsoft.prettytime:prettytime:5.0.4.Final' ProGuard rules are automatically configured for you if you use the R8 shrinker (which is the default since version 3.4.0 of the Android Gradle Plugin). If you are using an older version of AGP, add the ProGuard rules from [this file](core/src/main/resources/META-INF/proguard/prettytime.pro) From ab7e2b5e70ef359b4d9083c215e8bca2166a81c4 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Thu, 1 Sep 2022 12:41:12 -0400 Subject: [PATCH 103/147] [maven-release-plugin] prepare release 5.0.4.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 78a70b31..09b9d9c8 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.4-SNAPSHOT + 5.0.4.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 7772433e..5ccdc42d 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.4-SNAPSHOT + 5.0.4.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 948b2cb7..dba7b012 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.4-SNAPSHOT + 5.0.4.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 4835a17f..05ac5640 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.4-SNAPSHOT + 5.0.4.Final ../pom.xml diff --git a/pom.xml b/pom.xml index b5b51109..8c0e6b86 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.4-SNAPSHOT + 5.0.4.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 5.0.4.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 4f771bc2..0a7b7ffa 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.4-SNAPSHOT + 5.0.4.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.4-SNAPSHOT + 5.0.4.Final diff --git a/samples/pom.xml b/samples/pom.xml index 3ab10b4a..5bdb33f1 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.4-SNAPSHOT + 5.0.4.Final 4.0.0 From c4314b1b18b3af84283ecb40e4bd2655433b62e4 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Thu, 1 Sep 2022 12:41:12 -0400 Subject: [PATCH 104/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 09b9d9c8..268f8d9e 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.4.Final + 5.0.5-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 5ccdc42d..4d2523d2 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.4.Final + 5.0.5-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index dba7b012..24d1d538 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.4.Final + 5.0.5-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 05ac5640..f93b3a42 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.4.Final + 5.0.5-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index 8c0e6b86..c5780e10 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.4.Final + 5.0.5-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 5.0.4.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 0a7b7ffa..ec6a6900 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.4.Final + 5.0.5-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.4.Final + 5.0.5-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index 5bdb33f1..2976d8ae 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.4.Final + 5.0.5-SNAPSHOT 4.0.0 From 09af5b1d41207e081568e1bdda414e41103bb1b4 Mon Sep 17 00:00:00 2001 From: Wninayyds <90488923+Wninayyds@users.noreply.github.com> Date: Thu, 29 Sep 2022 19:02:22 +0800 Subject: [PATCH 105/147] upgrade jetty-server to 11.0.10 --- samples/jstl/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index ec6a6900..e7ddf5ba 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -15,7 +15,7 @@ org.eclipse.jetty jetty-server - 10.0.10 + 11.0.10 org.eclipse.jetty From 6ab06f52e82cb5c14f2cd521192134080e76473d Mon Sep 17 00:00:00 2001 From: ShareASmile <60492161+ShareASmile@users.noreply.github.com> Date: Mon, 17 Oct 2022 07:06:17 +0530 Subject: [PATCH 106/147] translation in punjabi language Added Translation in Punjabi language --- .../ocpsoft/prettytime/i18n/Resources_pa.java | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_pa.java diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_pa.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_pa.java new file mode 100644 index 00000000..aa8b33e0 --- /dev/null +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_pa.java @@ -0,0 +1,122 @@ +/* + * Copyright 2012 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ocpsoft.prettytime.i18n; + +import java.util.ListResourceBundle; + +public class Resources_pa extends ListResourceBundle +{ + + private static final Object[][] OBJECTS = new Object[][] { + { "CenturyPattern", "%n %u" }, + { "CenturyFuturePrefix", "" }, + { "CenturyFutureSuffix", " ਬਾਅਦ" }, + { "CenturyPastPrefix", "" }, + { "CenturyPastSuffix", " ਪਹਿਲਾਂ" }, + { "CenturySingularName", "ਸਦੀ" }, + { "CenturyPluralName", "ਸਦੀਆਂ" }, + { "DayPattern", "%n %u" }, + { "DayFuturePrefix", "" }, + { "DayFutureSuffix", " ਬਾਅਦ" }, + { "DayPastPrefix", "" }, + { "DayPastSuffix", " ਪਹਿਲਾਂ" }, + { "DaySingularName", "ਦਿਨ" }, + { "DayPluralName", "ਦਿਨ" }, + { "DecadePattern", "%n %u" }, + { "DecadeFuturePrefix", "" }, + { "DecadeFutureSuffix", " ਬਾਅਦ" }, + { "DecadePastPrefix", "" }, + { "DecadePastSuffix", " ਪਹਿਲਾਂ" }, + { "DecadeSingularName", "ਦਹਾਕਾ" }, + { "DecadePluralName", "ਦਹਾਕੇ" }, + { "HourPattern", "%n %u" }, + { "HourFuturePrefix", "" }, + { "HourFutureSuffix", " ਬਾਅਦ" }, + { "HourPastPrefix", "" }, + { "HourPastSuffix", " ਪਹਿਲਾਂ" }, + { "HourSingularName", "ਘੰਟਾ" }, + { "HourPluralName", "ਘੰਟੇ" }, + { "JustNowPattern", "%u" }, + { "JustNowFuturePrefix", "" }, + { "JustNowFutureSuffix", "ਕੁਝ ਪਲ ਬਾਅਦ" }, + { "JustNowPastPrefix", "ਹੁਣੇ-ਹੁਣੇ" }, + { "JustNowPastSuffix", "" }, + { "JustNowSingularName", "" }, + { "JustNowPluralName", "" }, + { "MillenniumPattern", "%n %u" }, + { "MillenniumFuturePrefix", "" }, + { "MillenniumFutureSuffix", " ਬਾਅਦ" }, + { "MillenniumPastPrefix", "" }, + { "MillenniumPastSuffix", " ਪਹਿਲਾਂ" }, + { "MillenniumSingularName", "ਸ਼ਤਾਬਦੀ" }, + { "MillenniumPluralName", "ਸ਼ਤਾਬਦੀਆਂ" }, + { "MillisecondPattern", "%n %u" }, + { "MillisecondFuturePrefix", "" }, + { "MillisecondFutureSuffix", " ਬਾਅਦ" }, + { "MillisecondPastPrefix", "" }, + { "MillisecondPastSuffix", " ਪਹਿਲਾਂ" }, + { "MillisecondSingularName", "ਮਿਲੀਸਕਿੰਟ" }, + { "MillisecondPluralName", "ਮਿਲੀਸਕਿੰਟ" }, + { "MinutePattern", "%n %u" }, + { "MinuteFuturePrefix", "" }, + { "MinuteFutureSuffix", " ਬਾਅਦ" }, + { "MinutePastPrefix", "" }, + { "MinutePastSuffix", " ਪਹਿਲਾਂ" }, + { "MinuteSingularName", "ਮਿੰਟ" }, + { "MinutePluralName", "ਮਿੰਟ" }, + { "MonthPattern", "%n %u" }, + { "MonthFuturePrefix", "" }, + { "MonthFutureSuffix", " ਬਾਅਦ" }, + { "MonthPastPrefix", "" }, + { "MonthPastSuffix", " ਪਹਿਲਾਂ" }, + { "MonthSingularName", "ਮਹੀਨਾ" }, + { "MonthPluralName", "ਮਹੀਨੇ" }, + { "SecondPattern", "%n %u" }, + { "SecondFuturePrefix", "" }, + { "SecondFutureSuffix", " ਬਾਅਦ" }, + { "SecondPastPrefix", "" }, + { "SecondPastSuffix", " ਪਹਿਲਾਂ" }, + { "SecondSingularName", "ਸਕਿੰਟ" }, + { "SecondPluralName", "ਸਕਿੰਟ" }, + { "WeekPattern", "%n %u" }, + { "WeekFuturePrefix", "" }, + { "WeekFutureSuffix", " ਬਾਅਦ" }, + { "WeekPastPrefix", "" }, + { "WeekPastSuffix", " ਪਹਿਲਾਂ" }, + { "WeekSingularName", "ਹਫ਼ਤਾ" }, + { "WeekPluralName", "ਹਫ਼ਤੇ" }, + { "YearPattern", "%n %u" }, + { "YearFuturePrefix", "" }, + { "YearFutureSuffix", " ਬਾਅਦ" }, + { "YearPastPrefix", "" }, + { "YearPastSuffix", " ਪਹਿਲਾਂ" }, + { "YearSingularName", "ਸਾਲ" }, + { "YearPluralName", "ਸਾਲ" }, + { "AbstractTimeUnitPattern", "" }, + { "AbstractTimeUnitFuturePrefix", "" }, + { "AbstractTimeUnitFutureSuffix", "" }, + { "AbstractTimeUnitPastPrefix", "" }, + { "AbstractTimeUnitPastSuffix", "" }, + { "AbstractTimeUnitSingularName", "" }, + { "AbstractTimeUnitPluralName", "" } }; + + @Override + public Object[][] getContents() + { + return OBJECTS; + } + +} \ No newline at end of file From 24ccc6a09d32a9d2762f11c6eac95463bbf213f9 Mon Sep 17 00:00:00 2001 From: ShareASmile <60492161+ShareASmile@users.noreply.github.com> Date: Mon, 17 Oct 2022 08:08:59 +0530 Subject: [PATCH 107/147] improved hindi translation Improved/Corrected Hindi Translation & also added info about License, which i added from original en file. --- .../ocpsoft/prettytime/i18n/Resources_hi.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_hi.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_hi.java index 5b1467f4..dbb181ff 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_hi.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_hi.java @@ -1,3 +1,18 @@ +/* + * Copyright 2012 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.ocpsoft.prettytime.i18n; import java.util.ListResourceBundle; @@ -36,8 +51,8 @@ public class Resources_hi extends ListResourceBundle { "HourPluralName", "घंटे" }, { "JustNowPattern", "%u" }, { "JustNowFuturePrefix", "" }, - { "JustNowFutureSuffix", "अभी" }, - { "JustNowPastPrefix", "अभी" }, + { "JustNowFutureSuffix", "कुछ पल बाद" }, + { "JustNowPastPrefix", "अभी-अभी" }, { "JustNowPastSuffix", "" }, { "JustNowSingularName", "" }, { "JustNowPluralName", "" }, @@ -47,7 +62,7 @@ public class Resources_hi extends ListResourceBundle { "MillenniumPastPrefix", "" }, { "MillenniumPastSuffix", " पहले" }, { "MillenniumSingularName", "सहस्राब्दी" }, - { "MillenniumPluralName", "सदियों" }, + { "MillenniumPluralName", "सहस्राब्दी" }, { "MillisecondPattern", "%n %u" }, { "MillisecondFuturePrefix", "" }, { "MillisecondFutureSuffix", " बाद" }, From ee5d4c0e753e83c457fd99255dc9b0c431dfb067 Mon Sep 17 00:00:00 2001 From: Maqa <104249296+Nizami20052022@users.noreply.github.com> Date: Tue, 25 Oct 2022 08:50:44 +0400 Subject: [PATCH 108/147] Resources_az.java Added Azerbaijani language. --- .../i18n/Resources_az.java" | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 "\311\231sas/src/\311\231sas/java/org/ocpsoft/g\303\266z\311\231l vaxt/i18n/Resources_az.java" diff --git "a/\311\231sas/src/\311\231sas/java/org/ocpsoft/g\303\266z\311\231l vaxt/i18n/Resources_az.java" "b/\311\231sas/src/\311\231sas/java/org/ocpsoft/g\303\266z\311\231l vaxt/i18n/Resources_az.java" new file mode 100644 index 00000000..e38b9b62 --- /dev/null +++ "b/\311\231sas/src/\311\231sas/java/org/ocpsoft/g\303\266z\311\231l vaxt/i18n/Resources_az.java" @@ -0,0 +1,120 @@ +Copyright 2012 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ocpsoft.prettytime.i18n; + +import java.util.ListResourceBundle; + +public class Resources_az extends ListResourceBundle +{ + private static final Object[][] OBJECTS = new Object[][] { + { "CenturyPattern", "%n %u" }, + { "CenturyFuturePrefix", "" }, + { "CenturyFutureSuffix", " indi" }, + { "CenturyPastPrefix", "" }, + { "CenturyPastSuffix", " əvvəl" }, + { "CenturySingularName", "əsr" }, + { "CenturyPluralName", "əsr" }, + { "DayPattern", "%n %u" }, + { "DayFuturePrefix", "" }, + { "DayFutureSuffix", " indi" }, + { "DayPastPrefix", "" }, + { "DayPastSuffix", " əvvəl" }, + { "DaySingularName", "gün" }, + { "DayPluralName", "gün" }, + { "DecadePattern", "%n %u" }, + { "DecadeFuturePrefix", "" }, + { "DecadeFutureSuffix", " indi" }, + { "DecadePastPrefix", "" }, + { "DecadePastSuffix", " əvvəl" }, + { "DecadeSingularName", "onillik" }, + { "DecadePluralName", "onillik" }, + { "HourPattern", "%n %u" }, + { "HourFuturePrefix", "" }, + { "HourFutureSuffix", " indi" }, + { "HourPastPrefix", "" }, + { "HourPastSuffix", " əvvəl" }, + { "HourSingularName", "saat" }, + { "HourPluralName", "saat" }, + { "JustNowPattern", "%u" }, + { "JustNowFuturePrefix", "" }, + { "JustNowFutureSuffix", "daha sonra" }, + { "JustNowPastPrefix", "dəqiqə əvvəl" }, + { "JustNowPastSuffix", "" }, + { "JustNowSingularName", "" }, + { "JustNowPluralName", "" }, + { "MillenniumPattern", "%n %u" }, + { "MillenniumFuturePrefix", "" }, + { "MillenniumFutureSuffix", "indi" }, + { "MillenniumPastPrefix", "" }, + { "MillenniumPastSuffix", " əvvəl" }, + { "MillenniumSingularName", "minillik" }, + { "MillenniumPluralName", "minillik" }, + { "MillisecondPattern", "%n %u" }, + { "MillisecondFuturePrefix", "" }, + { "MillisecondFutureSuffix", " indi" }, + { "MillisecondPastPrefix", "" }, + { "MillisecondPastSuffix", " əvvəl" }, + { "MillisecondSingularName", "millisaniyə" }, + { "MillisecondPluralName", "millisaniyə" }, + { "MinutePattern", "%n %u" }, + { "MinuteFuturePrefix", "" }, + { "MinuteFutureSuffix", " indi" }, + { "MinutePastPrefix", "" }, + { "MinutePastSuffix", " əvvəl" }, + { "MinuteSingularName", "dəqiqə" }, + { "MinutePluralName", "dəqiqə" }, + { "MonthPattern", "%n %u" }, + { "MonthFuturePrefix", "" }, + { "MonthFutureSuffix", " indi" }, + { "MonthPastPrefix", "" }, + { "MonthPastSuffix", " əvvəl" }, + { "MonthSingularName", "ay" }, + { "MonthPluralName", "ay" }, + { "SecondPattern", "%n %u" }, + { "SecondFuturePrefix", "" }, + { "SecondFutureSuffix", " indi" }, + { "SecondPastPrefix", "" }, + { "SecondPastSuffix", " əvvəl" }, + { "SecondSingularName", "saniyə" }, + { "SecondPluralName", "saniyə" }, + { "WeekPattern", "%n %u" }, + { "WeekFuturePrefix", "" }, + { "WeekFutureSuffix", " indi" }, + { "WeekPastPrefix", "" }, + { "WeekPastSuffix", " əvvəl" }, + { "WeekSingularName", "həftə" }, + { "WeekPluralName", "həftə" }, + { "YearPattern", "%n %u" }, + { "YearFuturePrefix", "" }, + { "YearFutureSuffix", " indi" }, + { "YearPastPrefix", "" }, + { "YearPastSuffix", " əvvəl" }, + { "YearSingularName", "il" }, + { "YearPluralName", "il" }, + { "AbstractTimeUnitPattern", "" }, + { "AbstractTimeUnitFuturePrefix", "" }, + { "AbstractTimeUnitFutureSuffix", "" }, + { "AbstractTimeUnitPastPrefix", "" }, + { "AbstractTimeUnitPastSuffix", "" }, + { "AbstractTimeUnitSingularName", "" }, + { "AbstractTimeUnitPluralName", "" } }; + + @Override + public Object[][] getContents() + { + return OBJECTS; + } + +} From 3a8380f909622d3905e1e0450200726c540e9083 Mon Sep 17 00:00:00 2001 From: Maqa <104249296+Nizami20052022@users.noreply.github.com> Date: Wed, 26 Oct 2022 21:23:41 +0400 Subject: [PATCH 109/147] Resources_az.java --- .../i18n/Resources_az.java" | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git "a/\311\231sas/src/\311\231sas/java/org/ocpsoft/g\303\266z\311\231l vaxt/i18n/Resources_az.java" "b/\311\231sas/src/\311\231sas/java/org/ocpsoft/g\303\266z\311\231l vaxt/i18n/Resources_az.java" index e38b9b62..2e7e31d0 100644 --- "a/\311\231sas/src/\311\231sas/java/org/ocpsoft/g\303\266z\311\231l vaxt/i18n/Resources_az.java" +++ "b/\311\231sas/src/\311\231sas/java/org/ocpsoft/g\303\266z\311\231l vaxt/i18n/Resources_az.java" @@ -21,28 +21,28 @@ public class Resources_az extends ListResourceBundle private static final Object[][] OBJECTS = new Object[][] { { "CenturyPattern", "%n %u" }, { "CenturyFuturePrefix", "" }, - { "CenturyFutureSuffix", " indi" }, + { "CenturyFutureSuffix", " sonra" }, { "CenturyPastPrefix", "" }, { "CenturyPastSuffix", " əvvəl" }, { "CenturySingularName", "əsr" }, { "CenturyPluralName", "əsr" }, { "DayPattern", "%n %u" }, { "DayFuturePrefix", "" }, - { "DayFutureSuffix", " indi" }, + { "DayFutureSuffix", " sonra" }, { "DayPastPrefix", "" }, { "DayPastSuffix", " əvvəl" }, { "DaySingularName", "gün" }, { "DayPluralName", "gün" }, { "DecadePattern", "%n %u" }, { "DecadeFuturePrefix", "" }, - { "DecadeFutureSuffix", " indi" }, + { "DecadeFutureSuffix", " sonra" }, { "DecadePastPrefix", "" }, { "DecadePastSuffix", " əvvəl" }, { "DecadeSingularName", "onillik" }, { "DecadePluralName", "onillik" }, { "HourPattern", "%n %u" }, { "HourFuturePrefix", "" }, - { "HourFutureSuffix", " indi" }, + { "HourFutureSuffix", " sonra" }, { "HourPastPrefix", "" }, { "HourPastSuffix", " əvvəl" }, { "HourSingularName", "saat" }, @@ -56,49 +56,49 @@ public class Resources_az extends ListResourceBundle { "JustNowPluralName", "" }, { "MillenniumPattern", "%n %u" }, { "MillenniumFuturePrefix", "" }, - { "MillenniumFutureSuffix", "indi" }, + { "MillenniumFutureSuffix", "sonra" }, { "MillenniumPastPrefix", "" }, { "MillenniumPastSuffix", " əvvəl" }, { "MillenniumSingularName", "minillik" }, { "MillenniumPluralName", "minillik" }, { "MillisecondPattern", "%n %u" }, { "MillisecondFuturePrefix", "" }, - { "MillisecondFutureSuffix", " indi" }, + { "MillisecondFutureSuffix", " sonra" }, { "MillisecondPastPrefix", "" }, { "MillisecondPastSuffix", " əvvəl" }, { "MillisecondSingularName", "millisaniyə" }, { "MillisecondPluralName", "millisaniyə" }, { "MinutePattern", "%n %u" }, { "MinuteFuturePrefix", "" }, - { "MinuteFutureSuffix", " indi" }, + { "MinuteFutureSuffix", " sonra" }, { "MinutePastPrefix", "" }, { "MinutePastSuffix", " əvvəl" }, { "MinuteSingularName", "dəqiqə" }, { "MinutePluralName", "dəqiqə" }, { "MonthPattern", "%n %u" }, { "MonthFuturePrefix", "" }, - { "MonthFutureSuffix", " indi" }, + { "MonthFutureSuffix", " sonra" }, { "MonthPastPrefix", "" }, { "MonthPastSuffix", " əvvəl" }, { "MonthSingularName", "ay" }, { "MonthPluralName", "ay" }, { "SecondPattern", "%n %u" }, { "SecondFuturePrefix", "" }, - { "SecondFutureSuffix", " indi" }, + { "SecondFutureSuffix", " sonra" }, { "SecondPastPrefix", "" }, { "SecondPastSuffix", " əvvəl" }, { "SecondSingularName", "saniyə" }, { "SecondPluralName", "saniyə" }, { "WeekPattern", "%n %u" }, { "WeekFuturePrefix", "" }, - { "WeekFutureSuffix", " indi" }, + { "WeekFutureSuffix", " sonra" }, { "WeekPastPrefix", "" }, { "WeekPastSuffix", " əvvəl" }, { "WeekSingularName", "həftə" }, { "WeekPluralName", "həftə" }, { "YearPattern", "%n %u" }, { "YearFuturePrefix", "" }, - { "YearFutureSuffix", " indi" }, + { "YearFutureSuffix", " sonra" }, { "YearPastPrefix", "" }, { "YearPastSuffix", " əvvəl" }, { "YearSingularName", "il" }, From 8b3cb3faf678ac6da2e7536997764e1d8ef8d2a0 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Thu, 27 Oct 2022 13:17:53 -0400 Subject: [PATCH 110/147] Revert "upgrade jetty-server to 11.0.10" This reverts commit 09af5b1d41207e081568e1bdda414e41103bb1b4. --- samples/jstl/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index e7ddf5ba..ec6a6900 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -15,7 +15,7 @@ org.eclipse.jetty jetty-server - 11.0.10 + 10.0.10 org.eclipse.jetty From 70eac6e43b3fd230e0cc85abde7c33a3306ddb26 Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Thu, 27 Oct 2022 20:34:01 -0300 Subject: [PATCH 111/147] Fix class location - Fixes #245 --- .../main/java/org/ocpsoft/prettytime/i18n/Resources_az.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename "\311\231sas/src/\311\231sas/java/org/ocpsoft/g\303\266z\311\231l vaxt/i18n/Resources_az.java" => core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_az.java (98%) diff --git "a/\311\231sas/src/\311\231sas/java/org/ocpsoft/g\303\266z\311\231l vaxt/i18n/Resources_az.java" b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_az.java similarity index 98% rename from "\311\231sas/src/\311\231sas/java/org/ocpsoft/g\303\266z\311\231l vaxt/i18n/Resources_az.java" rename to core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_az.java index 2e7e31d0..c29f994d 100644 --- "a/\311\231sas/src/\311\231sas/java/org/ocpsoft/g\303\266z\311\231l vaxt/i18n/Resources_az.java" +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_az.java @@ -1,4 +1,5 @@ -Copyright 2012 Lincoln Baxter, III +/* + * Copyright 2022 Lincoln Baxter, III * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 4e6229f60884bcfd76cbb59920c896d263303686 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Thu, 27 Oct 2022 13:18:10 -0400 Subject: [PATCH 112/147] [maven-release-plugin] prepare release 5.0.5.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 268f8d9e..8f68a446 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.5-SNAPSHOT + 5.0.5.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 4d2523d2..56e9c5b4 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.5-SNAPSHOT + 5.0.5.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 24d1d538..f61c9314 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.5-SNAPSHOT + 5.0.5.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index f93b3a42..2ecf605d 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.5-SNAPSHOT + 5.0.5.Final ../pom.xml diff --git a/pom.xml b/pom.xml index c5780e10..f0757147 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.5-SNAPSHOT + 5.0.5.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 5.0.5.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index ec6a6900..4bddd210 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.5-SNAPSHOT + 5.0.5.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.5-SNAPSHOT + 5.0.5.Final diff --git a/samples/pom.xml b/samples/pom.xml index 2976d8ae..6cd64ccc 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.5-SNAPSHOT + 5.0.5.Final 4.0.0 From 1b1e469ae656e4c14d922bcf5d3ae85e4f6d5b11 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Thu, 27 Oct 2022 13:18:10 -0400 Subject: [PATCH 113/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 8f68a446..a3fcdeea 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.5.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 56e9c5b4..6a54bfd6 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.5.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index f61c9314..46a4a311 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.5.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 2ecf605d..93a03b5e 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.5.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index f0757147..1c99ccfb 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.5.Final + 5.0.0-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 5.0.5.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 4bddd210..08e4006e 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.5.Final + 5.0.0-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.5.Final + 5.0.0-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index 6cd64ccc..09445864 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.5.Final + 5.0.0-SNAPSHOT 4.0.0 From 93d95e79848c6ce71d34c7763882a82181d4a9ee Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Fri, 28 Oct 2022 11:55:29 -0400 Subject: [PATCH 114/147] [maven-release-plugin] prepare release 5.0.6.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index a3fcdeea..6515d60a 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.0-SNAPSHOT + 5.0.6.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 6a54bfd6..b331158b 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.0-SNAPSHOT + 5.0.6.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 46a4a311..1acc0d69 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.6.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 93a03b5e..e4e4eb86 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.6.Final ../pom.xml diff --git a/pom.xml b/pom.xml index 1c99ccfb..db77e840 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.0-SNAPSHOT + 5.0.6.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 5.0.6.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 08e4006e..98974015 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.6.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.0-SNAPSHOT + 5.0.6.Final diff --git a/samples/pom.xml b/samples/pom.xml index 09445864..4e7c2625 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.6.Final 4.0.0 From be2eaa7f07d47a134466117c05cb2b639a35aeee Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Fri, 28 Oct 2022 11:55:29 -0400 Subject: [PATCH 115/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 6515d60a..a3fcdeea 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.6.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index b331158b..6a54bfd6 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.6.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 1acc0d69..46a4a311 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.6.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index e4e4eb86..93a03b5e 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.6.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index db77e840..1c99ccfb 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.6.Final + 5.0.0-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 5.0.6.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 98974015..08e4006e 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.6.Final + 5.0.0-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.6.Final + 5.0.0-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index 4e7c2625..09445864 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.6.Final + 5.0.0-SNAPSHOT 4.0.0 From d015ad416aeb3e9ca826e35867d64c8f41db76ed Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Fri, 28 Oct 2022 11:57:39 -0400 Subject: [PATCH 116/147] [maven-release-plugin] prepare release 5.0.5.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index a3fcdeea..8f68a446 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.0-SNAPSHOT + 5.0.5.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 6a54bfd6..56e9c5b4 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.0-SNAPSHOT + 5.0.5.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 46a4a311..f61c9314 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.5.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 93a03b5e..2ecf605d 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.5.Final ../pom.xml diff --git a/pom.xml b/pom.xml index 1c99ccfb..f0757147 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.0-SNAPSHOT + 5.0.5.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 5.0.5.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 08e4006e..4bddd210 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.5.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.0-SNAPSHOT + 5.0.5.Final diff --git a/samples/pom.xml b/samples/pom.xml index 09445864..6cd64ccc 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.5.Final 4.0.0 From 19a7f3e3c3cb12b5c9507774ea9d5828de8c742d Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Fri, 28 Oct 2022 11:57:50 -0400 Subject: [PATCH 117/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 8f68a446..a3fcdeea 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.5.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 56e9c5b4..6a54bfd6 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.5.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index f61c9314..46a4a311 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.5.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 2ecf605d..93a03b5e 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.5.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index f0757147..1c99ccfb 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.5.Final + 5.0.0-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 5.0.5.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 4bddd210..08e4006e 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.5.Final + 5.0.0-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.5.Final + 5.0.0-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index 6cd64ccc..09445864 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.5.Final + 5.0.0-SNAPSHOT 4.0.0 From 27b1ef59deca95c234e7bcf91713d138e7de8ab5 Mon Sep 17 00:00:00 2001 From: SanghitaBhaumik Date: Thu, 10 Nov 2022 15:58:44 +0530 Subject: [PATCH 118/147] Correcting bengali texts in Resources_bn.java file --- .../ocpsoft/prettytime/i18n/Resources_bn.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_bn.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_bn.java index 75ba2495..30278080 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_bn.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_bn.java @@ -26,7 +26,7 @@ public class Resources_bn extends ListResourceBundle { "CenturyPastPrefix", "" }, { "CenturyPastSuffix", " আগে" }, { "CenturySingularName", "শতাব্দী" }, - { "CenturyPluralName", "শতাব্দীর পর শতাব্দী" }, + { "CenturyPluralName", "শতাব্দী" }, { "DayPattern", "%n %u" }, { "DayFuturePrefix", "" }, { "DayFutureSuffix", " এখন থেকে" }, @@ -40,14 +40,14 @@ public class Resources_bn extends ListResourceBundle { "DecadePastPrefix", "" }, { "DecadePastSuffix", " আগে" }, { "DecadeSingularName", "দশক" }, - { "DecadePluralName", "কয়েক দশক ধরে" }, + { "DecadePluralName", "দশক" }, { "HourPattern", "%n %u" }, { "HourFuturePrefix", "" }, { "HourFutureSuffix", " এখন থেকে" }, { "HourPastPrefix", "" }, { "HourPastSuffix", " আগে" }, { "HourSingularName", "ঘন্টা" }, - { "HourPluralName", "ঘন্টার" }, + { "HourPluralName", "ঘন্টা" }, { "JustNowPattern", "%u" }, { "JustNowFuturePrefix", "" }, { "JustNowFutureSuffix", "" }, @@ -75,20 +75,20 @@ public class Resources_bn extends ListResourceBundle { "MinutePastPrefix", "" }, { "MinutePastSuffix", " আগে" }, { "MinuteSingularName", "মিনিট" }, - { "MinutePluralName", "কয়েক মিনিট" }, + { "MinutePluralName", "মিনিট" }, { "MonthPattern", "%n %u" }, { "MonthFuturePrefix", "" }, { "MonthFutureSuffix", " এখন থেকে" }, { "MonthPastPrefix", "" }, { "MonthPastSuffix", " আগে" }, { "MonthSingularName", "মাস" }, - { "MonthPluralName", "কয়েক মাস" }, + { "MonthPluralName", "মাস" }, { "SecondPattern", "%n %u" }, { "SecondFuturePrefix", " এখন থেকে" }, { "SecondFutureSuffix", "" }, { "SecondPastPrefix", "" }, { "SecondPastSuffix", " আগে" }, - { "SecondSingularName", "দ্বিতীয়" }, + { "SecondSingularName", "সেকেন্ড" }, { "SecondPluralName", "সেকেন্ড" }, { "WeekPattern", "%n %u" }, { "WeekFuturePrefix", "" }, @@ -96,14 +96,14 @@ public class Resources_bn extends ListResourceBundle { "WeekPastPrefix", "" }, { "WeekPastSuffix", " আগে" }, { "WeekSingularName", "সপ্তাহ" }, - { "WeekPluralName", "কয়েক সপ্তাহ" }, + { "WeekPluralName", "সপ্তাহ" }, { "YearPattern", "%n %u" }, { "YearFuturePrefix", "" }, { "YearFutureSuffix", " এখন থেকে" }, { "YearPastPrefix", "" }, { "YearPastSuffix", " আগে" }, { "YearSingularName", "বছর" }, - { "YearPluralName", "কয়েক বছর" }, + { "YearPluralName", "বছর" }, { "AbstractTimeUnitPattern", "" }, { "AbstractTimeUnitFuturePrefix", "" }, { "AbstractTimeUnitFutureSuffix", "" }, From 847847f64719dd447e6e6e440298191da3be740b Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 20 Nov 2022 07:48:22 +0530 Subject: [PATCH 119/147] Add methods that make use of java.time's ChronoUnit. --- .../org/ocpsoft/prettytime/PrettyTime.java | 74 ++++++++++++------- .../java/org/ocpsoft/prettytime/TimeUnit.java | 74 +++++++++++++++++++ .../PrettyTimeAPIManipulationTest.java | 20 ++--- 3 files changed, 129 insertions(+), 39 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index 93b97eb4..9a5506c3 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -15,38 +15,17 @@ */ package org.ocpsoft.prettytime; -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.OffsetDateTime; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; - import org.ocpsoft.prettytime.impl.DurationImpl; import org.ocpsoft.prettytime.impl.ResourcesTimeFormat; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; -import org.ocpsoft.prettytime.units.Century; -import org.ocpsoft.prettytime.units.Day; -import org.ocpsoft.prettytime.units.Decade; -import org.ocpsoft.prettytime.units.Hour; -import org.ocpsoft.prettytime.units.JustNow; -import org.ocpsoft.prettytime.units.Millennium; -import org.ocpsoft.prettytime.units.Millisecond; -import org.ocpsoft.prettytime.units.Minute; import org.ocpsoft.prettytime.units.Month; -import org.ocpsoft.prettytime.units.Second; -import org.ocpsoft.prettytime.units.Week; import org.ocpsoft.prettytime.units.Year; +import org.ocpsoft.prettytime.units.*; + +import java.time.*; +import java.time.temporal.ChronoUnit; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; /** * A utility for creating social-networking style timestamps. (e.g. "just now", "moments ago", "3 days ago", "within 2 @@ -1464,6 +1443,20 @@ public UNIT getUnit(final Class unitType) return null; } + /** + * 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} + */ + public TimeUnit getUnit(final ChronoUnit unit) + { + return getUnit(TimeUnit.of(unit).getClass()); + } + /** * Register the given {@link TimeUnit} and corresponding {@link TimeFormat} instance to be used in calculations. If * an entry already exists for the given {@link TimeUnit}, its {@link TimeFormat} will be overwritten with the given @@ -1482,6 +1475,19 @@ public PrettyTime registerUnit(final TimeUnit unit, TimeFormat format) return this; } + /** + * 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} + */ + public PrettyTime registerUnit(final ChronoUnit unit, final TimeFormat format) + { + return registerUnit(TimeUnit.of(unit), format); + } + public PrettyTime setUnits(final ResourcesTimeUnit... units) { if (units == null || units.length == 0) @@ -1545,6 +1551,20 @@ public TimeFormat removeUnit(final TimeUnit unit) return units.remove(unit); } + /** + * 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. + */ + public TimeFormat removeUnit(final ChronoUnit unit) + { + return removeUnit(TimeUnit.of(unit)); + } + /** * Get the currently configured {@link Locale} for this {@link PrettyTime} object. */ diff --git a/core/src/main/java/org/ocpsoft/prettytime/TimeUnit.java b/core/src/main/java/org/ocpsoft/prettytime/TimeUnit.java index d33bae10..d0d2af39 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/TimeUnit.java +++ b/core/src/main/java/org/ocpsoft/prettytime/TimeUnit.java @@ -15,6 +15,10 @@ */ package org.ocpsoft.prettytime; +import org.ocpsoft.prettytime.units.*; + +import java.time.temporal.ChronoUnit; + /** * Defines a Unit of time (e.g. seconds, minutes, hours) and its conversion to milliseconds. * @@ -47,4 +51,74 @@ public interface TimeUnit * "minute" as opposed to "moment". */ public boolean isPrecise(); + + /** + * Converts the given {@link ChronoUnit} to a {@link TimeUnit}, if possible. + * @param chronoUnit The {@code ChronoUnit} to be converted + * @return the corresponding {@code TimeUnit} + * @throws IllegalArgumentException if there is no corresponding {@code TimeUnit} + */ + public static TimeUnit of(final ChronoUnit chronoUnit) { + switch (chronoUnit) { + case MILLIS: + return new Millisecond(); + case SECONDS: + return new Second(); + case MINUTES: + return new Minute(); + case HOURS: + return new Hour(); + case DAYS: + return new Day(); + case WEEKS: + return new Week(); + case MONTHS: + return new Month(); + case YEARS: + return new Year(); + case DECADES: + return new Decade(); + case CENTURIES: + return new Century(); + case MILLENNIA: + return new Millennium(); + default: + throw new IllegalArgumentException("No corresponding TimeUnit for given ChronoUnit"); + } + } + + /** + * Converts the given {@link TimeUnit} to a {@link ChronoUnit}, if possible. + * + * @param timeUnit The {@code TimeUnit} to be converted + * @return the corresponding {@code ChronoUnit} + * @throws IllegalArgumentException if there is no corresponding {@code ChronoUnit}. + */ + public static ChronoUnit toChronoUnit(final TimeUnit timeUnit) { + if (timeUnit instanceof Millisecond) { + return ChronoUnit.MILLIS; + } else if (timeUnit instanceof Second) { + return ChronoUnit.SECONDS; + } else if (timeUnit instanceof Minute) { + return ChronoUnit.MINUTES; + } else if (timeUnit instanceof Hour) { + return ChronoUnit.HOURS; + } else if (timeUnit instanceof Day) { + return ChronoUnit.DAYS; + } else if (timeUnit instanceof Week) { + return ChronoUnit.WEEKS; + } else if (timeUnit instanceof Month) { + return ChronoUnit.MONTHS; + } else if (timeUnit instanceof Year) { + return ChronoUnit.YEARS; + } else if (timeUnit instanceof Decade) { + return ChronoUnit.DECADES; + } else if (timeUnit instanceof Century) { + return ChronoUnit.CENTURIES; + } else if (timeUnit instanceof Millennium) { + return ChronoUnit.MILLENNIA; + } else { + throw new IllegalArgumentException("No corresponding ChronoUnit for given TimeUnit"); + } + } } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java index 27a4169e..d5a78723 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java @@ -15,21 +15,17 @@ */ package org.ocpsoft.prettytime; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import org.junit.Assert; +import org.junit.Test; +import org.ocpsoft.prettytime.units.JustNow; -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.OffsetDateTime; -import java.time.ZonedDateTime; +import java.time.*; import java.util.Calendar; import java.util.Date; import java.util.List; -import org.junit.Assert; -import org.junit.Test; -import org.ocpsoft.prettytime.units.JustNow; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; public class PrettyTimeAPIManipulationTest { @@ -244,7 +240,7 @@ public void testApiMisuse13() throws Exception @Test(expected = NullPointerException.class) public void testApiMisuse14() throws Exception { - t.registerUnit(null, null); + t.registerUnit((TimeUnit) null, null); } @Test @@ -268,7 +264,7 @@ public void testApiMisuse17() throws Exception @Test public void testApiMisuse18() throws Exception { - Assert.assertNull(t.getUnit(null)); + Assert.assertNull(t.getUnit((Class) null)); } @Test From d7a4043664ce7ba7f88223ce527a5d926b7a87d5 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 26 Nov 2022 10:22:50 +0530 Subject: [PATCH 120/147] Apply code review suggestions. --- .../org/ocpsoft/prettytime/PrettyTime.java | 34 +++++++++++++++---- .../java/org/ocpsoft/prettytime/TimeUnit.java | 12 ++++++- .../PrettyTimeAPIManipulationTest.java | 25 ++++++++++---- 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index 9a5506c3..87b4edeb 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -15,17 +15,39 @@ */ package org.ocpsoft.prettytime; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; + import org.ocpsoft.prettytime.impl.DurationImpl; import org.ocpsoft.prettytime.impl.ResourcesTimeFormat; import org.ocpsoft.prettytime.impl.ResourcesTimeUnit; +import org.ocpsoft.prettytime.units.Century; +import org.ocpsoft.prettytime.units.Day; +import org.ocpsoft.prettytime.units.Decade; +import org.ocpsoft.prettytime.units.Hour; +import org.ocpsoft.prettytime.units.JustNow; +import org.ocpsoft.prettytime.units.Millennium; +import org.ocpsoft.prettytime.units.Millisecond; +import org.ocpsoft.prettytime.units.Minute; import org.ocpsoft.prettytime.units.Month; +import org.ocpsoft.prettytime.units.Second; +import org.ocpsoft.prettytime.units.Week; import org.ocpsoft.prettytime.units.Year; -import org.ocpsoft.prettytime.units.*; - -import java.time.*; -import java.time.temporal.ChronoUnit; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; /** * A utility for creating social-networking style timestamps. (e.g. "just now", "moments ago", "3 days ago", "within 2 diff --git a/core/src/main/java/org/ocpsoft/prettytime/TimeUnit.java b/core/src/main/java/org/ocpsoft/prettytime/TimeUnit.java index d0d2af39..66b2419a 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/TimeUnit.java +++ b/core/src/main/java/org/ocpsoft/prettytime/TimeUnit.java @@ -15,7 +15,17 @@ */ package org.ocpsoft.prettytime; -import org.ocpsoft.prettytime.units.*; +import org.ocpsoft.prettytime.units.Century; +import org.ocpsoft.prettytime.units.Day; +import org.ocpsoft.prettytime.units.Decade; +import org.ocpsoft.prettytime.units.Hour; +import org.ocpsoft.prettytime.units.Millennium; +import org.ocpsoft.prettytime.units.Millisecond; +import org.ocpsoft.prettytime.units.Minute; +import org.ocpsoft.prettytime.units.Month; +import org.ocpsoft.prettytime.units.Second; +import org.ocpsoft.prettytime.units.Week; +import org.ocpsoft.prettytime.units.Year; import java.time.temporal.ChronoUnit; diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java index d5a78723..72c4216b 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java @@ -15,17 +15,22 @@ */ package org.ocpsoft.prettytime; -import org.junit.Assert; -import org.junit.Test; -import org.ocpsoft.prettytime.units.JustNow; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; -import java.time.*; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; import java.util.Calendar; import java.util.Date; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import org.junit.Assert; +import org.junit.Test; +import org.ocpsoft.prettytime.units.JustNow; public class PrettyTimeAPIManipulationTest { @@ -238,11 +243,17 @@ public void testApiMisuse13() throws Exception } @Test(expected = NullPointerException.class) - public void testApiMisuse14() throws Exception + public void testApiMisuse14_TimeUnit() throws Exception { t.registerUnit((TimeUnit) null, null); } + @Test(expected = NullPointerException.class) + public void testApiMisuse14_ChronoUnit() + { + t.registerUnit((ChronoUnit) null, null); + } + @Test public void testApiMisuse15() throws Exception { From 6c2fbc097f09260d1558ecc3be10cad7b0f65b93 Mon Sep 17 00:00:00 2001 From: Dertyiula <119277871+Dertyiula@users.noreply.github.com> Date: Mon, 28 Nov 2022 09:00:57 +0400 Subject: [PATCH 121/147] Resources_az.java Translation error fixed. --- .../main/java/org/ocpsoft/prettytime/i18n/Resources_az.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_az.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_az.java index c29f994d..57fc0290 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_az.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_az.java @@ -50,8 +50,8 @@ public class Resources_az extends ListResourceBundle { "HourPluralName", "saat" }, { "JustNowPattern", "%u" }, { "JustNowFuturePrefix", "" }, - { "JustNowFutureSuffix", "daha sonra" }, - { "JustNowPastPrefix", "dəqiqə əvvəl" }, + { "JustNowFutureSuffix", "az sonra" }, + { "JustNowPastPrefix", "az öncə" }, { "JustNowPastSuffix", "" }, { "JustNowSingularName", "" }, { "JustNowPluralName", "" }, From 67dc71654fed175d3357f55a3388a2a8fee145a8 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 23 Feb 2023 05:45:05 +0530 Subject: [PATCH 122/147] Use the ZoneId parameter in one approximateDuration() overload. --- core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index 93b97eb4..55297c6d 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -358,7 +358,7 @@ public Duration approximateDuration(Instant then) */ public Duration approximateDuration(LocalDate then) { - return approximateDuration(then != null ? then.atStartOfDay(ZoneId.systemDefault()).toInstant() : null); + return approximateDuration(then, ZoneId.systemDefault()); } /** @@ -373,7 +373,7 @@ public Duration approximateDuration(LocalDate then) */ public Duration approximateDuration(LocalDate then, final ZoneId zoneId) { - return approximateDuration(then != null ? then.atStartOfDay(ZoneId.systemDefault()).toInstant() : null); + return approximateDuration(then != null ? then.atStartOfDay(zoneId).toInstant() : null); } /** From 9d02027716317e518c7a1d4c577483bd807dd337 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 23 Feb 2023 06:35:52 +0530 Subject: [PATCH 123/147] Reuse overloaded approximateDuration() method. --- core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java index 55297c6d..6c2d1d80 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java +++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java @@ -387,7 +387,7 @@ public Duration approximateDuration(LocalDate then, final ZoneId zoneId) */ public Duration approximateDuration(LocalDateTime then) { - return approximateDuration(then != null ? then.atZone(ZoneId.systemDefault()).toInstant() : null); + return approximateDuration(then, ZoneId.systemDefault()); } /** From 9766aebe61163c4576512900c621a40792b54169 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Mon, 31 Oct 2022 11:03:06 -0400 Subject: [PATCH 124/147] [maven-release-plugin] prepare release 5.0.6.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index a3fcdeea..6515d60a 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.0-SNAPSHOT + 5.0.6.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 6a54bfd6..b331158b 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.0-SNAPSHOT + 5.0.6.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 46a4a311..1acc0d69 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.6.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 93a03b5e..e4e4eb86 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.6.Final ../pom.xml diff --git a/pom.xml b/pom.xml index 1c99ccfb..db77e840 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.0-SNAPSHOT + 5.0.6.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 5.0.6.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 08e4006e..98974015 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.6.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.0-SNAPSHOT + 5.0.6.Final diff --git a/samples/pom.xml b/samples/pom.xml index 09445864..4e7c2625 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.6.Final 4.0.0 From d02f6dc9e426de790c17b27d492982909077fa4c Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Mon, 31 Oct 2022 11:03:06 -0400 Subject: [PATCH 125/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 6515d60a..a3fcdeea 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.6.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index b331158b..6a54bfd6 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.6.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 1acc0d69..46a4a311 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.6.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index e4e4eb86..93a03b5e 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.6.Final + 5.0.0-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index db77e840..1c99ccfb 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.6.Final + 5.0.0-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 5.0.6.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 98974015..08e4006e 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.6.Final + 5.0.0-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.6.Final + 5.0.0-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index 4e7c2625..09445864 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.6.Final + 5.0.0-SNAPSHOT 4.0.0 From 3fdf4368ed103f2f362e54a07384b2545dc1359d Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Tue, 28 Feb 2023 17:07:29 -0500 Subject: [PATCH 126/147] fix(tests): fix failing test --- core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java index c9747ee0..b9cdbc23 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java @@ -97,8 +97,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 millennium 9 centuries 1 month 1 day 8 hours 34 minutes ago", t.format(durations)); - Assert.assertEquals("1 millennium 9 centuries 1 month 1 day 8 hours 34 minutes", t.formatDuration(durations)); + Assert.assertEquals("1 millennium 9 centuries 1 month 1 day 9 hours 19 minutes ago", t.format(durations)); + Assert.assertEquals("1 millennium 9 centuries 1 month 1 day 9 hours 19 minutes", t.formatDuration(durations)); } @Test From 28787d05ed0a7679589bcad057ae3c0d04bb11af Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Wed, 1 Mar 2023 10:47:07 -0500 Subject: [PATCH 127/147] 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 From 5e7ff5a0a006092b9c8c004ef40621cdc5623a25 Mon Sep 17 00:00:00 2001 From: snow4dv Date: Thu, 22 Jun 2023 16:36:51 +0300 Subject: [PATCH 128/147] Fix for formatDuration method for russian locale --- .../ocpsoft/prettytime/i18n/Resources_ru.java | 128 ++++++++++-------- .../prettytime/PrettyTimeI18n_RU_Test.java | 64 ++++++++- 2 files changed, 131 insertions(+), 61 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ru.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ru.java index b2cd707b..01936859 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ru.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ru.java @@ -6,6 +6,7 @@ import org.ocpsoft.prettytime.impl.TimeFormatProvider; import org.ocpsoft.prettytime.units.*; +import java.util.Arrays; import java.util.ListResourceBundle; /** @@ -18,83 +19,92 @@ public class Resources_ru extends ListResourceBundle implements TimeFormatProvid private static final int tolerance = 50; // see http://translate.sourceforge.net/wiki/l10n/pluralforms - private static final int russianPluralForms = 3; + private static final int russianPluralForms = 4; - private static class TimeFormatAided implements TimeFormat - { + private class TimeFormatAided implements TimeFormat { private final String[] pluarls; - public TimeFormatAided(String... plurals) - { + public TimeFormatAided(String... plurals) { if (plurals.length != russianPluralForms) { - throw new IllegalArgumentException("Wrong plural forms number for russian language!"); + throw new IllegalArgumentException(String.format("Wrong plural forms number for russian language! " + + "Expected %s, got %s\nPlurals: %s", russianPluralForms, plurals.length, Arrays.toString(plurals))); } this.pluarls = plurals; } @Override - public String format(Duration duration) - { - long quantity = duration.getQuantityRounded(tolerance); - return String.valueOf(quantity); - } - - @Override - public String formatUnrounded(Duration duration) - { - long quantity = Math.abs(duration.getQuantity()); - return String.valueOf(quantity); - } - - @Override - public String decorate(Duration duration, String time) - { - return performDecoration( - duration.isInPast(), - duration.isInFuture(), - duration.getQuantityRounded(tolerance), - time); + public String format(Duration duration) { + String time = String.valueOf(Math.abs(duration.getQuantityRounded(tolerance))); + return performFormat(duration, time, true); } @Override - public String decorateUnrounded(Duration duration, String time) - { - return performDecoration( - duration.isInPast(), - duration.isInFuture(), - Math.abs(duration.getQuantity()), - time); + public String formatUnrounded(Duration duration) { + String time = String.valueOf(Math.abs(duration.getQuantity())); + return performFormat(duration, time, true); } - private String performDecoration(boolean past, boolean future, long n, String time) - { + public String performFormat(Duration duration, String time, boolean isDuration) { // a bit cryptic, yet well-tested // consider http://translate.sourceforge.net/wiki/l10n/pluralforms + long n = Math.abs(duration.getQuantity()); int pluralIdx = (n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2); + if (pluralIdx > russianPluralForms) { // impossible happening throw new IllegalStateException("Wrong plural index was calculated somehow for russian language"); } - StringBuilder result = new StringBuilder(); + String result = time + + ' ' + + pluarls[isDuration && pluralIdx == 0 ? pluralIdx : pluralIdx + 1]; - if (future) { - result.append("через "); - } + return result; + } - result.append(time); - result.append(' '); - result.append(pluarls[pluralIdx]); + @Override + public String decorate(Duration duration, String time) { + if(requiresReformatting(duration, true)) { + time = String.valueOf(Math.abs(duration.getQuantityRounded(tolerance))); + return performDecoration(duration, performFormat(duration, time, false)); + } + return performDecoration(duration, time); + } - if (past) { - result.append(" назад"); + @Override + public String decorateUnrounded(Duration duration, String time) { + if(requiresReformatting(duration, false)) { + time = String.valueOf(Math.abs(duration.getQuantity())); + return performDecoration(duration, performFormat(duration, time, false)); } + return performDecoration(duration, time); + } - return result.toString(); + public String performDecoration(Duration duration, String time) { + if (duration.isInFuture()) { + return "через " + time; + } + if (duration.isInPast()) { + return time + " назад"; + } + return time; + } + + /** + * While in English format can be achieved by simply adding " ago" to formatDuration result, + * in Russian there's difference: "1 minute" is "1 минута" but "1 minute ago" is "1 минуту назад" + * see here: article about russian grammatical cases + * This hacky method checks if it's the case when result of format method should be corrected. + * @param duration The original {@link Duration} instance from which the time string should be decorated. + * @param isRounded Determines whether rounded quantity be checked or plain one + * @return Is reformatting required (is case "1 минута" - "1 минуту назад" - "через 1 минуту" reached) + */ + public boolean requiresReformatting(Duration duration, boolean isRounded) { + long quantity = isRounded ? Math.abs(duration.getQuantityRounded(tolerance)) : Math.abs(duration.getQuantity()); + return quantity == 1; } } - @Override public Object[][] getContents() { @@ -129,6 +139,8 @@ private String performFormat(Duration duration) return null; } + + @Override public String decorate(Duration duration, String time) { @@ -143,37 +155,37 @@ public String decorateUnrounded(Duration duration, String time) }; } else if (t instanceof Century) { - return new TimeFormatAided("век", "века", "веков"); + return new TimeFormatAided("век", "век", "века", "веков"); } else if (t instanceof Day) { - return new TimeFormatAided("день", "дня", "дней"); + return new TimeFormatAided("день", "день", "дня", "дней"); } else if (t instanceof Decade) { - return new TimeFormatAided("десятилетие", "десятилетия", "десятилетий"); + return new TimeFormatAided("десятилетие", "десятилетие", "десятилетия", "десятилетий"); } else if (t instanceof Hour) { - return new TimeFormatAided("час", "часа", "часов"); + return new TimeFormatAided("час", "час", "часа", "часов"); } else if (t instanceof Millennium) { - return new TimeFormatAided("тысячелетие", "тысячелетия", "тысячелетий"); + return new TimeFormatAided("тысячелетие", "тысячелетие", "тысячелетия", "тысячелетий"); } else if (t instanceof Millisecond) { - return new TimeFormatAided("миллисекунду", "миллисекунды", "миллисекунд"); + return new TimeFormatAided("миллисекунда", "миллисекунду", "миллисекунды", "миллисекунд"); } else if (t instanceof Minute) { - return new TimeFormatAided("минуту", "минуты", "минут"); + return new TimeFormatAided("минута", "минуту", "минуты", "минут"); } else if (t instanceof Month) { - return new TimeFormatAided("месяц", "месяца", "месяцев"); + return new TimeFormatAided("месяц", "месяц", "месяца", "месяцев"); } else if (t instanceof Second) { - return new TimeFormatAided("секунду", "секунды", "секунд"); + return new TimeFormatAided("секунда", "секунду", "секунды", "секунд"); } else if (t instanceof Week) { - return new TimeFormatAided("неделю", "недели", "недель"); + return new TimeFormatAided("неделя", "неделю", "недели", "недель"); } else if (t instanceof Year) { - return new TimeFormatAided("год", "года", "лет"); + return new TimeFormatAided("год", "год", "года", "лет"); } return null; // error } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_RU_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_RU_Test.java index fa9486db..624ae76f 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_RU_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_RU_Test.java @@ -1,10 +1,10 @@ package org.ocpsoft.prettytime; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; +import java.util.*; import org.junit.After; import org.junit.Before; @@ -29,7 +29,8 @@ public void setUp() throws Exception public void testPrettyTime() { PrettyTime p = new PrettyTime(locale); - assertEquals("сейчас", p.format(new Date())); + List values = Arrays.asList("сейчас", "только что"); + assertTrue(values.contains(p.format(new Date()))); } @Test @@ -37,9 +38,11 @@ public void testPrettyTimeCenturies() { PrettyTime p = new PrettyTime(new Date(3155692597470L * 3L), locale); assertEquals("3 века назад", p.format(new Date(0))); + assertEquals("3 века", p.formatDuration(new Date(0))); p = new PrettyTime(new Date(0), locale); assertEquals("через 3 века", p.format(new Date(3155692597470L * 3L))); + assertEquals("3 века", p.formatDuration(new Date(3155692597470L * 3L))); } @Test @@ -49,6 +52,7 @@ public void testCeilingInterval() throws Exception Date ref = format.parse("17/6/2009"); PrettyTime t = new PrettyTime(ref, locale); assertEquals("1 месяц назад", t.format(then)); + assertEquals("1 месяц", t.formatDuration(then)); } @Test @@ -57,6 +61,7 @@ public void testNullDate() throws Exception PrettyTime t = new PrettyTime(locale); Date date = null; assertEquals("сейчас", t.format(date)); + assertEquals("сейчас", t.formatDuration(date)); } @Test @@ -64,6 +69,7 @@ public void testRightNow() throws Exception { PrettyTime t = new PrettyTime(locale); assertEquals("сейчас", t.format(new Date())); + assertEquals("сейчас", t.formatDuration(new Date())); } @Test @@ -71,6 +77,7 @@ public void testRightNowVariance() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); assertEquals("сейчас", t.format(new Date(600))); + assertEquals("сейчас", t.formatDuration(new Date(600))); } @Test @@ -78,6 +85,7 @@ public void testMinutesFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); assertEquals("через 12 минут", t.format(new Date(1000 * 60 * 12))); + assertEquals("12 минут", t.formatDuration(new Date(1000 * 60 * 12))); } @Test @@ -85,6 +93,7 @@ public void testHoursFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); assertEquals("через 3 часа", t.format(new Date(1000 * 60 * 60 * 3))); + assertEquals("3 часа", t.formatDuration(new Date(1000 * 60 * 60 * 3))); } @Test @@ -92,6 +101,7 @@ public void testDaysFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); assertEquals("через 3 дня", t.format(new Date(1000 * 60 * 60 * 24 * 3))); + assertEquals("3 дня", t.formatDurationUnrounded(new Date(1000 * 60 * 60 * 24 * 3))); } @Test @@ -99,6 +109,7 @@ public void testWeeksFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); assertEquals("через 3 недели", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); + assertEquals("3 недели", t.formatDuration(new Date(1000 * 60 * 60 * 24 * 7 * 3))); } @Test @@ -106,6 +117,7 @@ public void testMonthsFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); assertEquals("через 3 месяца", t.format(new Date(2629743830L * 3L))); + assertEquals("3 месяца", t.formatDuration(new Date(2629743830L * 3L))); } @Test @@ -113,6 +125,7 @@ public void testYearsFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); assertEquals("через 3 года", t.format(new Date(2629743830L * 12L * 3L))); + assertEquals("3 года", t.formatDuration(new Date(2629743830L * 12L * 3L))); } @Test @@ -120,6 +133,7 @@ public void testDecadesFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); assertEquals("через 3 десятилетия", t.format(new Date(315569259747L * 3L))); + assertEquals("3 десятилетия", t.formatDuration(new Date(315569259747L * 3L))); } @Test @@ -127,6 +141,7 @@ public void testCenturiesFromNow() throws Exception { PrettyTime t = new PrettyTime(new Date(0), locale); assertEquals("через 3 века", t.format(new Date(3155692597470L * 3L))); + assertEquals("3 века", t.formatDuration(new Date(3155692597470L * 3L))); } /* @@ -137,6 +152,7 @@ public void testMomentsAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(6000), locale); assertEquals("только что", t.format(new Date(0))); + assertEquals("только что", t.formatDuration(new Date(0))); } @Test @@ -145,6 +161,8 @@ public void testMinutesAgo1() throws Exception PrettyTime t = new PrettyTime(new Date(1000 * 60), locale); assertEquals("1 минуту назад", t.formatUnrounded(new Date(0))); assertEquals("1 минуту назад", t.format(new Date(0))); + assertEquals("1 минута", t.formatDuration(new Date(0))); + assertEquals("1 минута", t.formatDuration(new Date(0))); } @Test @@ -161,6 +179,8 @@ public void testMinutesAgo3() throws Exception PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale); assertEquals("12 минут назад", t.formatUnrounded(new Date(0))); assertEquals("12 минут назад", t.format(new Date(0))); + assertEquals("12 минут", t.formatDuration(new Date(0))); + assertEquals("12 минут", t.formatDuration(new Date(0))); } @Test @@ -169,6 +189,8 @@ public void testHoursAgo1() throws Exception PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60), locale); assertEquals("1 час назад", t.formatUnrounded(new Date(0))); assertEquals("1 час назад", t.format(new Date(0))); + assertEquals("1 час", t.formatDuration(new Date(0))); + assertEquals("1 час", t.formatDurationUnrounded(new Date(0))); } @Test @@ -177,6 +199,8 @@ public void testHoursAgo2() throws Exception PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale); assertEquals("3 часа назад", t.formatUnrounded(new Date(0))); assertEquals("3 часа назад", t.format(new Date(0))); + assertEquals("3 часа", t.formatDuration(new Date(0))); + assertEquals("3 часа", t.formatDurationUnrounded(new Date(0))); } @Test @@ -185,6 +209,8 @@ public void testHoursAgo3() throws Exception PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 5), locale); assertEquals("5 часов назад", t.formatUnrounded(new Date(0))); assertEquals("5 часов назад", t.format(new Date(0))); + assertEquals("5 часов", t.formatDurationUnrounded(new Date(0))); + assertEquals("5 часов", t.formatDuration(new Date(0))); } @Test @@ -193,6 +219,8 @@ public void testDaysAgo1() throws Exception PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24), locale); assertEquals("1 день назад", t.formatUnrounded(new Date(0))); assertEquals("1 день назад", t.format(new Date(0))); + assertEquals("1 день", t.formatDurationUnrounded(new Date(0))); + assertEquals("1 день", t.formatDuration(new Date(0))); } @Test @@ -201,6 +229,8 @@ public void testDaysAgo2() throws Exception PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale); assertEquals("3 дня назад", t.formatUnrounded(new Date(0))); assertEquals("3 дня назад", t.format(new Date(0))); + assertEquals("3 дня", t.formatDurationUnrounded(new Date(0))); + assertEquals("3 дня", t.formatDuration(new Date(0))); } @Test @@ -209,6 +239,8 @@ public void testDaysAgo3() throws Exception PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 5), locale); assertEquals("5 дней назад", t.formatUnrounded(new Date(0))); assertEquals("5 дней назад", t.format(new Date(0))); + assertEquals("5 дней", t.formatDurationUnrounded(new Date(0))); + assertEquals("5 дней", t.formatDuration(new Date(0))); } @Test @@ -217,6 +249,8 @@ public void testWeeksAgo() throws Exception PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7), locale); assertEquals("1 неделю назад", t.formatUnrounded(new Date(0))); assertEquals("1 неделю назад", t.format(new Date(0))); + assertEquals("1 неделя", t.formatDurationUnrounded(new Date(0))); + assertEquals("1 неделя", t.formatDuration(new Date(0))); } @Test @@ -225,6 +259,8 @@ public void testWeeksAgo2() throws Exception PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale); assertEquals("3 недели назад", t.formatUnrounded(new Date(0))); assertEquals("3 недели назад", t.format(new Date(0))); + assertEquals("3 недели", t.formatDurationUnrounded(new Date(0))); + assertEquals("3 недели", t.formatDuration(new Date(0))); } @Test @@ -233,6 +269,8 @@ public void testMonthsAgo1() throws Exception PrettyTime t = new PrettyTime(new Date(2629743830L), locale); assertEquals("1 месяц назад", t.formatUnrounded(new Date(0))); assertEquals("1 месяц назад", t.format(new Date(0))); + assertEquals("1 месяц", t.formatDurationUnrounded(new Date(0))); + assertEquals("1 месяц", t.formatDuration(new Date(0))); } @Test @@ -241,6 +279,8 @@ public void testMonthsAgo2() throws Exception PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale); assertEquals("3 месяца назад", t.formatUnrounded(new Date(0))); assertEquals("3 месяца назад", t.format(new Date(0))); + assertEquals("3 месяца", t.formatDurationUnrounded(new Date(0))); + assertEquals("3 месяца", t.formatDuration(new Date(0))); } @Test @@ -249,6 +289,8 @@ public void testMonthsAgo3() throws Exception PrettyTime t = new PrettyTime(new Date(2629743830L * 5L), locale); assertEquals("5 месяцев назад", t.formatUnrounded(new Date(0))); assertEquals("5 месяцев назад", t.format(new Date(0))); + assertEquals("5 месяцев", t.formatDurationUnrounded(new Date(0))); + assertEquals("5 месяцев", t.formatDuration(new Date(0))); } @Test @@ -257,6 +299,8 @@ public void testYearsAgo1() throws Exception PrettyTime t = new PrettyTime(new Date(2629743830L * 12L), locale); assertEquals("1 год назад", t.formatUnrounded(new Date(0))); assertEquals("1 год назад", t.format(new Date(0))); + assertEquals("1 год", t.formatDurationUnrounded(new Date(0))); + assertEquals("1 год", t.formatDuration(new Date(0))); } @Test @@ -265,6 +309,8 @@ public void testYearsAgo2() throws Exception PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale); assertEquals("3 года назад", t.formatUnrounded(new Date(0))); assertEquals("3 года назад", t.format(new Date(0))); + assertEquals("3 года", t.formatDurationUnrounded(new Date(0))); + assertEquals("3 года", t.formatDuration(new Date(0))); } @Test @@ -273,6 +319,8 @@ public void testYearsAgo3() throws Exception PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 5L), locale); assertEquals("5 лет назад", t.formatUnrounded(new Date(0))); assertEquals("5 лет назад", t.format(new Date(0))); + assertEquals("5 лет", t.formatDuration(new Date(0))); + assertEquals("5 лет", t.formatDurationUnrounded(new Date(0))); } @Test @@ -289,6 +337,8 @@ public void testDecadesAgo2() throws Exception PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale); assertEquals("3 десятилетия назад", t.formatUnrounded(new Date(0))); assertEquals("3 десятилетия назад", t.format(new Date(0))); + assertEquals("3 десятилетия", t.formatDurationUnrounded(new Date(0))); + assertEquals("3 десятилетия", t.formatDuration(new Date(0))); } @Test @@ -297,6 +347,8 @@ public void testDecadesAgo3() throws Exception PrettyTime t = new PrettyTime(new Date(315569259747L * 5L), locale); assertEquals("5 десятилетий назад", t.formatUnrounded(new Date(0))); assertEquals("5 десятилетий назад", t.format(new Date(0))); + assertEquals("5 десятилетий", t.formatDurationUnrounded(new Date(0))); + assertEquals("5 десятилетий", t.formatDuration(new Date(0))); } @Test @@ -305,6 +357,8 @@ public void testCenturiesAgo1() throws Exception PrettyTime t = new PrettyTime(new Date(3155692597470L), locale); assertEquals("1 век назад", t.formatUnrounded(new Date(0))); assertEquals("1 век назад", t.format(new Date(0))); + assertEquals("1 век", t.formatDurationUnrounded(new Date(0))); + assertEquals("1 век", t.formatDuration(new Date(0))); } @Test @@ -313,6 +367,8 @@ public void testCenturiesAgo2() throws Exception PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale); assertEquals("3 века назад", t.formatUnrounded(new Date(0))); assertEquals("3 века назад", t.format(new Date(0))); + assertEquals("3 века", t.formatDurationUnrounded(new Date(0))); + assertEquals("3 века", t.formatDuration(new Date(0))); } @Test @@ -321,6 +377,8 @@ public void testCenturiesAgo3() throws Exception PrettyTime t = new PrettyTime(new Date(3155692597470L * 5L), locale); assertEquals("5 веков назад", t.formatUnrounded(new Date(0))); assertEquals("5 веков назад", t.format(new Date(0))); + assertEquals("5 веков", t.formatDurationUnrounded(new Date(0))); + assertEquals("5 веков", t.formatDuration(new Date(0))); } @After From 17142ba32beb35ab41e28a2b6263d12db3dfdbaf Mon Sep 17 00:00:00 2001 From: snow4dv Date: Thu, 22 Jun 2023 17:45:27 +0300 Subject: [PATCH 129/147] Fixed usage of wrong quantity --- .../ocpsoft/prettytime/i18n/Resources_ru.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ru.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ru.java index 01936859..5643febf 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ru.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ru.java @@ -34,20 +34,19 @@ public TimeFormatAided(String... plurals) { @Override public String format(Duration duration) { - String time = String.valueOf(Math.abs(duration.getQuantityRounded(tolerance))); - return performFormat(duration, time, true); + long roundedQuantity = Math.abs(duration.getQuantityRounded(tolerance)); + return performFormat(roundedQuantity, true); } @Override public String formatUnrounded(Duration duration) { - String time = String.valueOf(Math.abs(duration.getQuantity())); - return performFormat(duration, time, true); + long unroundedQuantity = Math.abs(duration.getQuantity()); + return performFormat(unroundedQuantity, true); } - public String performFormat(Duration duration, String time, boolean isDuration) { + public String performFormat(long n, boolean isDuration) { // a bit cryptic, yet well-tested // consider http://translate.sourceforge.net/wiki/l10n/pluralforms - long n = Math.abs(duration.getQuantity()); int pluralIdx = (n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2); @@ -56,7 +55,7 @@ public String performFormat(Duration duration, String time, boolean isDuration) throw new IllegalStateException("Wrong plural index was calculated somehow for russian language"); } - String result = time + + String result = String.valueOf(n) + ' ' + pluarls[isDuration && pluralIdx == 0 ? pluralIdx : pluralIdx + 1]; @@ -66,8 +65,8 @@ public String performFormat(Duration duration, String time, boolean isDuration) @Override public String decorate(Duration duration, String time) { if(requiresReformatting(duration, true)) { - time = String.valueOf(Math.abs(duration.getQuantityRounded(tolerance))); - return performDecoration(duration, performFormat(duration, time, false)); + long roundedQuantity = Math.abs(duration.getQuantityRounded(tolerance)); + return performDecoration(duration, performFormat(roundedQuantity, false)); } return performDecoration(duration, time); } @@ -75,8 +74,8 @@ public String decorate(Duration duration, String time) { @Override public String decorateUnrounded(Duration duration, String time) { if(requiresReformatting(duration, false)) { - time = String.valueOf(Math.abs(duration.getQuantity())); - return performDecoration(duration, performFormat(duration, time, false)); + long unroundedQuantity = Math.abs(duration.getQuantity()); + return performDecoration(duration, performFormat(unroundedQuantity, false)); } return performDecoration(duration, time); } From 2e761db7cc3b8aeed99822675a3de644a488d730 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Fri, 23 Jun 2023 12:30:14 -0400 Subject: [PATCH 130/147] [maven-release-plugin] prepare release 5.0.7.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index a3fcdeea..8f2a424f 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.0-SNAPSHOT + 5.0.7.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 6a54bfd6..0bfad3f0 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.0-SNAPSHOT + 5.0.7.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 46a4a311..fd39e673 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.7.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 93a03b5e..345eb783 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.7.Final ../pom.xml diff --git a/pom.xml b/pom.xml index 1c99ccfb..03b94087 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.0-SNAPSHOT + 5.0.7.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 5.0.7.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 08e4006e..94d5dd8d 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.7.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.0-SNAPSHOT + 5.0.7.Final diff --git a/samples/pom.xml b/samples/pom.xml index 09445864..9ec6bd0f 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.0-SNAPSHOT + 5.0.7.Final 4.0.0 From 5eafbbaa3b15e20d095b973fe20e8b9bf72f9a87 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Fri, 23 Jun 2023 12:30:14 -0400 Subject: [PATCH 131/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 8f2a424f..dbd6def4 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.7.Final + 5.0.8-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 0bfad3f0..e57f33c0 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.7.Final + 5.0.8-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index fd39e673..e53256a2 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.7.Final + 5.0.8-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 345eb783..9371d331 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.7.Final + 5.0.8-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index 03b94087..bf18548e 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.7.Final + 5.0.8-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 5.0.7.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 94d5dd8d..ee0cc5ab 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.7.Final + 5.0.8-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.7.Final + 5.0.8-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index 9ec6bd0f..054c6493 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.7.Final + 5.0.8-SNAPSHOT 4.0.0 From 5d571f70570696a66a4fd6fe41bb1a985f28fd7d Mon Sep 17 00:00:00 2001 From: NEXI <117938502+nexiRS@users.noreply.github.com> Date: Sat, 2 Sep 2023 23:39:24 +0200 Subject: [PATCH 132/147] Added Serbian (Cyrillic) language --- .../org/ocpsoft/prettytime/i18n/Resources_sr | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sr diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sr b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sr new file mode 100644 index 00000000..c30d3233 --- /dev/null +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sr @@ -0,0 +1,121 @@ +/* + * Copyright 2012 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ocpsoft.prettytime.i18n; + +import java.util.ListResourceBundle; + +public class Resources_sr extends ListResourceBundle +{ + private static final Object[][] OBJECTS = new Object[][] { + { "CenturyPattern", "%n %u" }, + { "CenturyFuturePrefix", "за " }, + { "CenturyFutureSuffix", "" }, + { "CenturyPastPrefix", "пре " }, + { "CenturyPastSuffix", "" }, + { "CenturySingularName", "века" }, + { "CenturyPluralName", "векова" }, + { "DayPattern", "%n %u" }, + { "DayFuturePrefix", "за " }, + { "DayFutureSuffix", "" }, + { "DayPastPrefix", "пре " }, + { "DayPastSuffix", "" }, + { "DaySingularName", "дан" }, + { "DayPluralName", "дана" }, + { "DecadePattern", "%n %u" }, + { "DecadeFuturePrefix", "за " }, + { "DecadeFutureSuffix", "" }, + { "DecadePastPrefix", "пре " }, + { "DecadePastSuffix", "" }, + { "DecadeSingularName", "деценију" }, + { "DecadePluralName", "деценија" }, + { "HourPattern", "%n %u" }, + { "HourFuturePrefix", "за " }, + { "HourFutureSuffix", "" }, + { "HourPastPrefix", "пре " }, + { "HourPastSuffix", "" }, + { "HourSingularName", "сат" }, + { "HourPluralName", "сати" }, + { "JustNowPattern", "%u" }, + { "JustNowFuturePrefix", "за неколико тренутака" }, + { "JustNowFutureSuffix", "" }, + { "JustNowPastPrefix", "пре неколико тренутака" }, + { "JustNowPastSuffix", "" }, + { "JustNowSingularName", "" }, + { "JustNowPluralName", "" }, + { "MillenniumPattern", "%n %u" }, + { "MillenniumFuturePrefix", "за " }, + { "MillenniumFutureSuffix", "" }, + { "MillenniumPastPrefix", "пре " }, + { "MillenniumPastSuffix", "" }, + { "MillenniumSingularName", "миленијума" }, + { "MillenniumPluralName", "миленијума" }, + { "MillisecondPattern", "%n %u" }, + { "MillisecondFuturePrefix", "за " }, + { "MillisecondFutureSuffix", "" }, + { "MillisecondPastPrefix", "пре " }, + { "MillisecondPastSuffix", "" }, + { "MillisecondSingularName", "милисекунде" }, + { "MillisecondPluralName", "милисекунди" }, + { "MinutePattern", "%n %u" }, + { "MinuteFuturePrefix", "за " }, + { "MinuteFutureSuffix", "" }, + { "MinutePastPrefix", "пре " }, + { "MinutePastSuffix", "" }, + { "MinuteSingularName", "минут" }, + { "MinutePluralName", "минута" }, + { "MonthPattern", "%n %u" }, + { "MonthFuturePrefix", "за " }, + { "MonthFutureSuffix", "" }, + { "MonthPastPrefix", "пре " }, + { "MonthPastSuffix", "" }, + { "MonthSingularName", "месец" }, + { "MonthPluralName", "месеца" }, + { "SecondPattern", "%n %u" }, + { "SecondFuturePrefix", "за " }, + { "SecondFutureSuffix", "" }, + { "SecondPastPrefix", "пре " }, + { "SecondPastSuffix", "" }, + { "SecondSingularName", "секунду" }, + { "SecondPluralName", "секунди" }, + { "WeekPattern", "%n %u" }, + { "WeekFuturePrefix", "за " }, + { "WeekFutureSuffix", "" }, + { "WeekPastPrefix", "за " }, + { "WeekPastSuffix", "" }, + { "WeekSingularName", "недељу" }, + { "WeekPluralName", "недеље" }, + { "YearPattern", "%n %u" }, + { "YearFuturePrefix", "за " }, + { "YearFutureSuffix", " " }, + { "YearPastPrefix", "пре " }, + { "YearPastSuffix", "" }, + { "YearSingularName", "годину" }, + { "YearPluralName", "године" }, + { "AbstractTimeUnitPattern", "" }, + { "AbstractTimeUnitFuturePrefix", "" }, + { "AbstractTimeUnitFutureSuffix", "" }, + { "AbstractTimeUnitPastPrefix", "" }, + { "AbstractTimeUnitPastSuffix", "" }, + { "AbstractTimeUnitSingularName", "" }, + { "AbstractTimeUnitPluralName", "" } }; + + @Override + public Object[][] getContents() + { + return OBJECTS; + } + +} From a539316e78a02fedb8053d73ab5e375f29e1a086 Mon Sep 17 00:00:00 2001 From: NEXI <117938502+nexiRS@users.noreply.github.com> Date: Sat, 2 Sep 2023 23:55:31 +0200 Subject: [PATCH 133/147] Create PrettyTimeI18n_SR_Test.java --- .../prettytime/PrettyTimeI18n_SR_Test.java | 507 ++++++++++++++++++ 1 file changed, 507 insertions(+) create mode 100644 core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SR_Test.java diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SR_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SR_Test.java new file mode 100644 index 00000000..e6ca5694 --- /dev/null +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SR_Test.java @@ -0,0 +1,507 @@ +/* +* Copyright 2012 Lincoln Baxter, III +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +*     http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.ocpsoft.prettytime; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.Calendar; +import java.util.Date; +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_SR_Test +{ +   private Locale locale; +   private LocalDateTime now; + +   @Before +   public void setUp() throws Exception +   { +      locale = Locale.getDefault(); +      Locale.setDefault(Locale.ROOT); +      now = LocalDateTime.now(); +   } + +   @Test +   public void testCeilingInterval() throws Exception +   { +      PrettyTime prettyTime = new PrettyTime(LocalDate.of(2009, 6, 17)); +      Assert.assertEquals("пре 1 месец", prettyTime.format(LocalDate.of(2009, 5, 20))); +   } + +   @Test +   public void testNullDate() throws Exception +   { +      PrettyTime t = new PrettyTime(); +      Date date = null; +      Assert.assertEquals("за неколико тренутака", t.format(date)); +   } + +   @Test +   public void testRightNow() throws Exception +   { +      PrettyTime t = new PrettyTime(); +      Assert.assertEquals("за неколико тренутака", t.format(new Date())); +   } + +   @Test +   public void testRightNowWithReference() throws Exception +   { +      Date now = new Date(); +      Date ref = new Date(); +      PrettyTime t = new PrettyTime(ref); +      String formatted = t.format(now); +      Assert.assertEquals("за неколико тренутака", formatted); +   } + +   @Test +   public void testCalculatePreciceDuration() throws Exception +   { +      PrettyTime t = new PrettyTime(); +      List preciseDuration = t.calculatePreciseDuration( +               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(new Date().getTime() - 10)))); + +      preciseDuration = t.calculatePreciseDuration(now.minusHours(2).minusMinutes(2)); +      Assert.assertEquals("пре 2 сата 2 минута", t.format(preciseDuration)); +      Assert.assertEquals("2 сата 2 минута", t.formatDuration(preciseDuration)); +      Assert.assertEquals("за неколико тренутака", t.format(t.calculatePreciseDuration(LocalDateTime.now().plusSeconds(1)))); +   } + +   @Test +   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 дан 9 сати 19 минута", t.format(durations)); +      Assert.assertEquals("1 миленијум 9 векова 1 месец 1 дан 9 сати 19 минута", t.formatDuration(durations)); +   } + +   @Test +   public void testCalculatePreciseDurationSingleUnit() +   { +      PrettyTime prettyTime = new PrettyTime(); +      Minute minutes = new Minute(); +      prettyTime.setUnits(minutes); +      Assert.assertEquals("пре 40 минута", prettyTime.formatUnrounded(prettyTime +               .calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); +   } + +   @Test +   public void testCalculatePreciseDurationSingleUnitWithFormat() +   { +      PrettyTime prettyTime = new PrettyTime(); +      Minute minutes = new Minute(); +      TimeFormat format = new SimpleTimeFormat().setPluralName("минута").setPattern("%n %u"); +      prettyTime.setUnits(format, minutes); +      Assert.assertEquals("40 минута", prettyTime.formatUnrounded(prettyTime +               .calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); +   } + +   @Test +   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(now.minusSeconds(40).minusMinutes(40)))); +   } + +   @Test +   public void testRightNowVariance() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("за неколико тренутака", t.format(now.plus(600, ChronoUnit.MILLIS))); +   } + +   @Test +   public void testMinutesFromNow() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("за 12 минута", t.format(now.plusMinutes(12))); +   } + +   @Test +   public void testHoursFromNow() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("за 3 сата", t.format(now.plusHours(3))); +   } + +   @Test +   public void testDaysFromNow() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("за 3 дана", t.format(now.plusDays(3))); +   } + +   @Test +   public void testWeeksFromNow() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("за 3 недеље", t.format(now.plusWeeks(3))); +   } + +   @Test +   public void testMonthsFromNow() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("за 3 месеца", t.format(now.plusMonths(3))); +   } + +   @Test +   public void testYearsFromNow() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("за 3 године", t.format(now.plusYears(3))); +   } + +   @Test +   public void testDecadesFromNow() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("за 3 деценије", t.format(now.plus(3, ChronoUnit.DECADES))); +   } + +   @Test +   public void testCenturiesFromNow() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("за 3 века", t.format(now.plus(3, ChronoUnit.CENTURIES))); +   } + +   /* +    * Past +    */ +   @Test +   public void testMomentsAgo() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("пре неколико тренутака", t.format(now.minusSeconds(6))); +   } + +   @Test +   public void testMinutesAgo() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("пре 12 минута", t.format(now.minusMinutes(12))); +   } + +   @Test +   public void testMinutesFromNowDefaultReference() throws Exception +   { +      PrettyTime t = new PrettyTime(); +      Assert.assertEquals("пре 12 минута", t.format(now.plusMinutes(12))); +   } + +   @Test +   public void testHoursAgo() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("пре 3 сата", t.format(now.minusHours(3))); +   } + +   @Test +   public void testHoursAgoDefaultReference() throws Exception +   { +      PrettyTime t = new PrettyTime(); +      Assert.assertEquals("пре 3 сата", t.format(now.minusHours(3))); +   } + +   @Test +   public void testDaysAgo() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("пре 3 дана", t.format(now.minusDays(3))); +   } + +   @Test +   public void testWeeksAgo() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("пре 3 недеље", t.format(now.minusWeeks(3))); +   } + +   @Test +   public void testMonthsAgo() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("пре 3 месеца", t.format(now.minusMonths(3))); +   } + +   @Test +   public void testCustomFormat() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      TimeUnit unit = new TimeUnit() { +         @Override +         public long getMaxQuantity() +         { +            return 0; +         } + +         @Override +         public long getMillisPerUnit() +         { +            return 5000; +         } + +         @Override +         public boolean isPrecise() +         { +            return false; +         } +      }; +      t.clearUnits(); +      t.registerUnit(unit, new SimpleTimeFormat() +               .setSingularName("откуцај").setPluralName("откуцаја") +               .setPattern("%n %u").setRoundingTolerance(20) +               .setFutureSuffix("... ТРЧИ!") +               .setFuturePrefix("самоуништење је за: ").setPastPrefix("самоуништење је било: ").setPastSuffix( +                        "пре ...")); + +      final LocalDateTime fiveTicks = now.plusSeconds(25); +      Assert.assertEquals("самоуништење је за: 5 откуцаја... ТРЧИ!", t.format(fiveTicks)); +      t.setReference(fiveTicks); +      Assert.assertEquals("самоуништење је било: пре 5 откуцаја...", t.format(now)); +   } + +   @Test +   public void testYearsAgo() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("пре 3 године", t.format(now.minusYears(3))); +   } + +   @Test +   public void testDecadesAgo() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("пре 3 деценије", t.format(now.minus(3, ChronoUnit.DECADES))); +   } + +   @Test +   public void testCenturiesAgo() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("пре 3 века", t.format(now.minus(3, ChronoUnit.CENTURIES))); +   } + +   @Test +   public void testWithinTwoHoursRounding() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      Assert.assertEquals("пре 2 сата", t.format(now.minusHours(1).minusMinutes(45))); +   } + +   @Test +   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); +      Assert.assertEquals(5, durations.get(0).getQuantity()); +      Assert.assertEquals(10, durations.get(1).getQuantity()); +   } + +   @Test +   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); +      Assert.assertEquals(-5, durations.get(0).getQuantity()); +      Assert.assertEquals(-10, durations.get(1).getQuantity()); +   } + +   @Test +   public void testFormattingDurationListInThePast() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      List durations = t.calculatePreciseDuration(now.minusDays(3).minusHours(15).minusMinutes(38)); +      Assert.assertEquals("пре 3 дана 15 сати 38 минута", t.format(durations)); +   } + +   @Test +   public void testFormattingDurationListInTheFuture() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      List durations = t.calculatePreciseDuration(now.plusDays(3).plusHours(15).plusMinutes(38)); +      Assert.assertEquals("за 3 дана 15 сати 38 минута", t.format(durations)); +   } + +   @Test +   public void testSetLocale() throws Exception +   { +      PrettyTime t = new PrettyTime(now); +      final LocalDateTime threeDecadesAgo = now.minus(3, ChronoUnit.DECADES); +      Assert.assertEquals("пре 3 деценије", t.format(threeDecadesAgo)); +      t.setLocale(Locale.GERMAN); +      Assert.assertEquals("пре 3 деценије", t.format(threeDecadesAgo)); +   } + +   /** +    * 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 +   { +      Calendar c = Calendar.getInstance(); +      Date r = c.getTime(); +      PrettyTime t = new PrettyTime(); +      t.setLocale(Locale.ENGLISH); +      t.setReference(r); +      c.add(Calendar.YEAR, -1); +      Assert.assertEquals("пре 1 годину", t.format(c)); +   } + +   /** +    * Tests formatApproximateDuration and by proxy, formatDuration. +    * +    * @throws Exception +    */ +   @Test +   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(); +      String result = t.formatDuration(tenMinAgo); +      Assert.assertEquals("10 минута", result); + +      result = t.formatDuration(now.minusMinutes(10)); +      Assert.assertEquals("10 минута", result); +   } + +   @Test +   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(); +      String result = t.formatDuration(tenMinAgo); +      Assert.assertEquals("11 минута", result); + +      result = t.formatDuration(now.minusMinutes(10).minusSeconds(40)); +      Assert.assertEquals("11 минута", result); +   } + +   @Test +   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(); +      String result = t.formatDurationUnrounded(tenMinAgo); +      Assert.assertEquals("10 минута", result); + +      result = t.formatDurationUnrounded(now.minusMinutes(10).minusSeconds(40)); +      Assert.assertEquals("10 минута", result); +   } + +   @Test +   public void testFormatList() throws Exception +   { +      PrettyTime prettyTime = new PrettyTime(); +      prettyTime.clearUnits(); +      Minute minutes = new Minute(); +      prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); +      Assert.assertEquals("пре 41 минут", +               prettyTime.format(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); +   } + +   @Test +   public void testFormatListUnrounded() throws Exception +   { +      PrettyTime prettyTime = new PrettyTime(); +      prettyTime.clearUnits(); +      Minute minutes = new Minute(); +      prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); +      Assert.assertEquals("пре 40 минута", +               prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); +   } + +   @Test +   public void testFormatDurationList() throws Exception +   { +      PrettyTime prettyTime = new PrettyTime(); +      prettyTime.clearUnits(); +      Minute minutes = new Minute(); +      prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); +      Assert.assertEquals("41 минут", +               prettyTime.formatDuration(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); +   } + +   @Test +   public void testFormatDurationListUnrounded() throws Exception +   { +      PrettyTime prettyTime = new PrettyTime(); +      prettyTime.clearUnits(); +      Minute minutes = new Minute(); +      prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); +      Assert.assertEquals("40 минута", +               prettyTime.formatDurationUnrounded(prettyTime.calculatePreciseDuration( +                        now.minusMinutes(40).minusSeconds(40)))); +   } + +   @Test +   public void testCalculatePreciseDuration() +   { +      PrettyTime prettyTime = new PrettyTime(); +      prettyTime.clearUnits(); +      Minute minutes = new Minute(); +      prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); +      Assert.assertEquals("пре 41 минут", +               prettyTime.format(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); +   } + +   @Test +   public void testCalculatePreciseDurationUnrounded() +   { +      PrettyTime prettyTime = new PrettyTime(); +      prettyTime.clearUnits(); +      Minute minutes = new Minute(); +      prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); +      Assert.assertEquals("пре 40 минута", +               prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); +   } + +   @After +   public void tearDown() throws Exception +   { +      Locale.setDefault(locale); +   } + + } From 8266b0c643cce09e04211c61b408f70db64bde1e Mon Sep 17 00:00:00 2001 From: Siarhiej Bahdaniec Date: Sun, 1 Oct 2023 23:59:26 +0400 Subject: [PATCH 134/147] Adding Belarusian language --- .../ocpsoft/prettytime/i18n/Resources_be.java | 184 ++++++++++++ .../prettytime/PrettyTimeI18n_be_Test.java | 274 ++++++++++++++++++ 2 files changed, 458 insertions(+) create mode 100644 core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_be.java create mode 100644 core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_be_Test.java diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_be.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_be.java new file mode 100644 index 00000000..43fe52e3 --- /dev/null +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_be.java @@ -0,0 +1,184 @@ +package org.ocpsoft.prettytime.i18n; + +import org.ocpsoft.prettytime.Duration; +import org.ocpsoft.prettytime.TimeFormat; +import org.ocpsoft.prettytime.TimeUnit; +import org.ocpsoft.prettytime.impl.TimeFormatProvider; +import org.ocpsoft.prettytime.units.*; + +import java.util.ListResourceBundle; + +/** + * Created with IntelliJ IDEA. User: Tumin Alexander Date: 2012-12-13 Time: 03:33 + * + * reedit to Ukrainian with Eclipse). User: Ihor Lavrynuk Date: 2013-01-06 Time: 15:04 + * + * reedit to Belarusian with IntelliJ IDEA. User: Siarhiej Bahdaniec Date: 2023-10-01 Time: 11:02 PM + */ +public class Resources_be extends ListResourceBundle implements TimeFormatProvider +{ + private static final Object[][] OBJECTS = new Object[0][0]; + + private static final int tolerance = 50; + + // see http://translate.sourceforge.net/wiki/l10n/pluralforms + private static final int slavicPluralForms = 3; + + private static class TimeFormatAided implements TimeFormat + { + private final String[] pluarls; + + public TimeFormatAided(String... plurals) + { + if (plurals.length != slavicPluralForms) { + throw new IllegalArgumentException("Wrong plural forms number for slavic language!"); + } + this.pluarls = plurals; + } + + @Override + public String format(Duration duration) + { + long quantity = duration.getQuantityRounded(tolerance); + return String.valueOf(quantity); + } + + @Override + public String formatUnrounded(Duration duration) + { + long quantity = duration.getQuantity(); + return String.valueOf(quantity); + } + + @Override + public String decorate(Duration duration, String time) + { + return performDecoration( + duration.isInPast(), + duration.isInFuture(), + duration.getQuantityRounded(tolerance), + time); + } + + @Override + public String decorateUnrounded(Duration duration, String time) + { + return performDecoration( + duration.isInPast(), + duration.isInFuture(), + duration.getQuantity(), + time); + } + + private String performDecoration(boolean past, boolean future, long n, String time) + { + // a bit cryptic, yet well-tested + // consider http://translate.sourceforge.net/wiki/l10n/pluralforms + int pluralIdx = (n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 + && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2); + if (pluralIdx > slavicPluralForms) { + // impossible happening + throw new IllegalStateException("Wrong plural index was calculated somehow for slavic language"); + } + + StringBuilder result = new StringBuilder(); + + if (future) { + result.append("праз "); + } + + result.append(time); + result.append(' '); + result.append(pluarls[pluralIdx]); + + if (past) { + result.append(" таму"); + } + + return result.toString(); + } + } + + @Override + public Object[][] getContents() + { + return OBJECTS; + } + + @Override + public TimeFormat getFormatFor(TimeUnit t) + { + if (t instanceof JustNow) { + return new TimeFormat() { + @Override + public String format(Duration duration) + { + return performFormat(duration); + } + + @Override + public String formatUnrounded(Duration duration) + { + return performFormat(duration); + } + + private String performFormat(Duration duration) + { + if (duration.isInFuture()) { + return "зараз"; + } + if (duration.isInPast()) { + return "толькі што"; + } + return null; + } + + @Override + public String decorate(Duration duration, String time) + { + return time; + } + + @Override + public String decorateUnrounded(Duration duration, String time) + { + return time; + } + }; + } + else if (t instanceof Century) { + return new TimeFormatAided("стагоддзе", "стагоддзі", "стагоддзяў"); + } + else if (t instanceof Day) { + return new TimeFormatAided("дзень", "дні", "дзён"); + } + else if (t instanceof Decade) { + return new TimeFormatAided("дзесяцігоддзе", "дзесяцігоддзі", "дзесяцігоддзяў"); + } + else if (t instanceof Hour) { + return new TimeFormatAided("гадзіну", "гадзіны", "гадзін"); + } + else if (t instanceof Millennium) { + return new TimeFormatAided("тысячагоддзе", "тысячагоддзі", "тысячагоддзяў"); + } + else if (t instanceof Millisecond) { + return new TimeFormatAided("мілісекунду", "мілісекунды", "мілісекунд"); + } + else if (t instanceof Minute) { + return new TimeFormatAided("хвіліну", "хвіліны", "хвілін"); + } + else if (t instanceof Month) { + return new TimeFormatAided("месяц", "месяцы", "месяцаў"); + } + else if (t instanceof Second) { + return new TimeFormatAided("секунду", "секунды", "секунд"); + } + else if (t instanceof Week) { + return new TimeFormatAided("тыдзень", "тыдні", "тыдняў"); + } + else if (t instanceof Year) { + return new TimeFormatAided("год", "гады", "гадоў"); + } + return null; // error + } +} \ No newline at end of file diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_be_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_be_Test.java new file mode 100644 index 00000000..ab06bf96 --- /dev/null +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_be_Test.java @@ -0,0 +1,274 @@ +package org.ocpsoft.prettytime; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +import static org.junit.Assert.assertEquals; + +/** + * User: Ihor Lavrynuk Date: 2013-01-05 Time: 16:57 + * reedit to Belarusian with IntelliJ IDEA. User: Siarhiej Bahdaniec Date: 2023-10-01 Time: 11:33 PM + */ +public class PrettyTimeI18n_be_Test +{ + private final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); + private Locale locale; + + @Before + public void setUp() throws Exception + { + locale = new Locale("be"); + Locale.setDefault(locale); + } + + @Test + public void testPrettyTime() + { + PrettyTime p = new PrettyTime(locale); + assertEquals("зараз", p.format(new Date())); + } + + @Test + public void testPrettyTimeCenturies() + { + PrettyTime p = new PrettyTime(new Date(3155692597470L * 3L), locale); + assertEquals("3 стагоддзі таму", p.format(new Date(0))); + + p = new PrettyTime(new Date(0), locale); + assertEquals("праз 3 стагоддзі", p.format(new Date(3155692597470L * 3L))); + } + + @Test + public void testCeilingInterval() throws Exception + { + Date then = format.parse("20/5/2009"); + Date ref = format.parse("17/6/2009"); + PrettyTime t = new PrettyTime(ref, locale); + assertEquals("1 месяц таму", t.format(then)); + } + + @Test + public void testNullDate() throws Exception + { + PrettyTime t = new PrettyTime(locale); + Date date = null; + assertEquals("зараз", t.format(date)); + } + + @Test + public void testRightNow() throws Exception + { + PrettyTime t = new PrettyTime(locale); + assertEquals("зараз", t.format(new Date())); + } + + @Test + public void testRightNowVariance() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("зараз", t.format(new Date(600))); + } + + @Test + public void test1MinutesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("праз 1 хвіліну", t.format(new Date(1000 * 60))); + } + + @Test + public void test2MinutesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("праз 2 хвіліны", t.format(new Date(1000 * 60 * 2))); + } + + @Test + public void test5MinutesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("праз 5 хвілін", t.format(new Date(1000 * 60 * 5))); + } + + @Test + public void test12MinutesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("праз 12 хвілін", t.format(new Date(1000 * 60 * 12))); + } + + @Test + public void test21MinutesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("праз 21 хвіліну", t.format(new Date(1000 * 60 * 21))); + } + + @Test + public void test23MinutesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("праз 23 хвіліны", t.format(new Date(1000 * 60 * 23))); + } + + @Test + public void test25MinutesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("праз 25 хвілін", t.format(new Date(1000 * 60 * 25))); + } + + @Test + public void testHoursFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("праз 3 гадзіны", t.format(new Date(1000 * 60 * 60 * 3))); + } + + @Test + public void testDaysFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("праз 3 дні", t.format(new Date(1000 * 60 * 60 * 24 * 3))); + } + + @Test + public void testWeeksFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("праз 3 тыдні", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); + } + + @Test + public void testMonthsFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("праз 3 месяцы", t.format(new Date(2629743830L * 3L))); + } + + @Test + public void testYearsFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("праз 3 гады", t.format(new Date(2629743830L * 12L * 3L))); + } + + @Test + public void testDecadesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("праз 3 дзесяцігоддзі", t.format(new Date(315569259747L * 3L))); + } + + @Test + public void testCenturiesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("праз 3 стагоддзі", t.format(new Date(3155692597470L * 3L))); + } + + /* + * Past + */ + @Test + public void testMomentsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(6000), locale); + assertEquals("толькі што", t.format(new Date(0))); + } + + @Test + public void testMinutesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale); + assertEquals("12 хвілін таму", t.format(new Date(0))); + } + + @Test + public void test1HourAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 1), locale); + assertEquals("1 гадзіну таму", t.format(new Date(0))); + } + + @Test + public void test3HoursAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale); + assertEquals("3 гадзіны таму", t.format(new Date(0))); + } + + @Test + public void test6HoursAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 6), locale); + assertEquals("6 гадзін таму", t.format(new Date(0))); + } + + @Test + public void testDaysAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale); + assertEquals("3 дні таму", t.format(new Date(0))); + } + + @Test + public void testWeeksAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale); + assertEquals("3 тыдні таму", t.format(new Date(0))); + } + + @Test + public void testMonthsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale); + assertEquals("3 месяцы таму", t.format(new Date(0))); + } + + @Test + public void testYearsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale); + assertEquals("3 гады таму", t.format(new Date(0))); + } + + @Test + public void test8YearsAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 8L), locale); + assertEquals("8 гадоў таму", t.format(new Date(0))); + } + + @Test + public void testDecadesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale); + assertEquals("3 дзесяцігоддзі таму", t.format(new Date(0))); + } + + @Test + public void test8DecadesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(315569259747L * 8L), locale); + assertEquals("8 дзесяцігоддзяў таму", t.format(new Date(0))); + } + + @Test + public void testCenturiesAgo() throws Exception + { + PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale); + assertEquals("3 стагоддзі таму", t.format(new Date(0))); + } + + @After + public void tearDown() throws Exception + { + Locale.setDefault(locale); + } +} From 89aa86e10446c0b4f43007c9077e3ae57b7f520d Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Thu, 25 Apr 2024 12:36:48 -0400 Subject: [PATCH 135/147] fix(android): Update prettytime.pro to keep TimeUnit implementations --- core/src/main/resources/META-INF/proguard/prettytime.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/resources/META-INF/proguard/prettytime.pro b/core/src/main/resources/META-INF/proguard/prettytime.pro index 0b40554e..07c96803 100644 --- a/core/src/main/resources/META-INF/proguard/prettytime.pro +++ b/core/src/main/resources/META-INF/proguard/prettytime.pro @@ -1 +1,2 @@ -keep class org.ocpsoft.prettytime.i18n** +-keep public class * implements org.ocpsoft.prettytime.TimeUnit From 0bc655fe8955933ed1dbd602973cac000172ee7b Mon Sep 17 00:00:00 2001 From: moontoaster <74986506+moontoaster@users.noreply.github.com> Date: Fri, 26 Apr 2024 19:57:38 +0300 Subject: [PATCH 136/147] Add format unrounded testcases for Ukrainian --- .../prettytime/PrettyTimeI18n_uk_Test.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_uk_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_uk_Test.java index 8fb72ebe..0f2a4819 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_uk_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_uk_Test.java @@ -238,6 +238,77 @@ public void testCenturiesAgo() throws Exception assertEquals("3 століття тому", t.format(new Date(0))); } + @Test + public void testUnroundedNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("зараз", t.formatUnrounded(new Date(0))); + } + + @Test + public void testUnroundedSlightlyAfterNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals("зараз", t.formatUnrounded(new Date(600))); + } + + @Test + public void testUnroundedFuture() throws Exception + { + Object[][] datesAndExpectedResults = { + {new Date(1000 * 60 * 12), "через 12 хвилин"}, + {new Date(1000 * 60 * 60 * 3), "через 3 години"}, + {new Date(1000 * 60 * 60 * 24 * 3), "через 3 дні"}, + {new Date(1000 * 60 * 60 * 24 * 7 * 3), "через 3 тижні"}, + {new Date(2629743830L * 3L), "через 3 місяці"}, + {new Date(2629743830L * 12L * 3L), "через 3 роки"}, + {new Date(315569259747L * 3L), "через 3 десятиліття"}, + {new Date(3155692597470L * 3L), "через 3 століття"}, + }; + + for (Object[] dateAndExpectedResult : datesAndExpectedResults) { + Date date = (Date) dateAndExpectedResult[0]; + String expectedResult = (String) dateAndExpectedResult[1]; + + PrettyTime t = new PrettyTime(new Date(0), locale); + assertEquals(expectedResult, t.formatUnrounded(date)); + } + } + + @Test + public void testUnroundedSlightlyBeforeNow() throws Exception + { + PrettyTime t = new PrettyTime(new Date(600), locale); + assertEquals("щойно", t.formatUnrounded(new Date(0))); + } + + @Test + public void testUnroundedPast() throws Exception + { + Object[][] referenceDatesAndExpectedResults = { + {new Date(1000 * 60 * 12), "12 хвилин тому"}, + {new Date(1000 * 60 * 60 * 1), "1 годину тому"}, + {new Date(1000 * 60 * 60 * 3), "3 години тому"}, + {new Date(1000 * 60 * 60 * 6), "6 годин тому"}, + {new Date(1000 * 60 * 60 * 24 * 3), "3 дні тому"}, + {new Date(1000 * 60 * 60 * 24 * 7 * 3), "3 тижні тому"}, + {new Date(2629743830L * 3L), "3 місяці тому"}, + {new Date(2629743830L * 12L * 3L), "3 роки тому"}, + {new Date(2629743830L * 12L * 8L), "8 років тому"}, + {new Date(315569259747L * 3L), "3 десятиліття тому"}, + {new Date(315569259747L * 8L), "8 десятиліть тому"}, + {new Date(3155692597470L * 3L), "3 століття тому"}, + }; + + for (Object[] referenceDateAndExpectedResult : referenceDatesAndExpectedResults) { + Date referenceDate = (Date) referenceDateAndExpectedResult[0]; + String expectedResult = (String) referenceDateAndExpectedResult[1]; + + PrettyTime t = new PrettyTime(referenceDate, locale); + assertEquals(expectedResult, t.formatUnrounded(new Date(0))); + } + } + @After public void tearDown() throws Exception { From d201e26838425f3ca4932e9d4bd87bf8ff8dc81c Mon Sep 17 00:00:00 2001 From: moontoaster <74986506+moontoaster@users.noreply.github.com> Date: Fri, 26 Apr 2024 20:06:37 +0300 Subject: [PATCH 137/147] Fix unrounded methods with date in the past for Ukrainian --- .../main/java/org/ocpsoft/prettytime/i18n/Resources_uk.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_uk.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_uk.java index 24e2cbb8..f032bbf6 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_uk.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_uk.java @@ -62,7 +62,7 @@ public String format(Duration duration) @Override public String formatUnrounded(Duration duration) { - long quantity = duration.getQuantity(); + long quantity = Math.abs(duration.getQuantity()); StringBuilder result = new StringBuilder(); result.append(quantity); return result.toString(); @@ -84,7 +84,7 @@ public String decorateUnrounded(Duration duration, String time) return performDecoration( duration.isInPast(), duration.isInFuture(), - duration.getQuantity(), + Math.abs(duration.getQuantity()), time); } From c9e58ce736270e3de27f0c13b2776ebbea47b120 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Wed, 8 May 2024 10:53:42 -0400 Subject: [PATCH 138/147] [maven-release-plugin] prepare release 5.0.8.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index dbd6def4..28c0bb8e 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.8-SNAPSHOT + 5.0.8.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index e57f33c0..7af42713 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.8-SNAPSHOT + 5.0.8.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index e53256a2..66d90239 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.8-SNAPSHOT + 5.0.8.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 9371d331..8ceb803c 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.8-SNAPSHOT + 5.0.8.Final ../pom.xml diff --git a/pom.xml b/pom.xml index bf18548e..614981df 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.8-SNAPSHOT + 5.0.8.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 5.0.8.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index ee0cc5ab..8f5b0104 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.8-SNAPSHOT + 5.0.8.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.8-SNAPSHOT + 5.0.8.Final diff --git a/samples/pom.xml b/samples/pom.xml index 054c6493..d756773f 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.8-SNAPSHOT + 5.0.8.Final 4.0.0 From 47e76d587af8315f87c0443986f4bccafb3ece41 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Wed, 8 May 2024 10:53:42 -0400 Subject: [PATCH 139/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 28c0bb8e..0c59dd0b 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.8.Final + 5.0.9-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 7af42713..98e90be4 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.8.Final + 5.0.9-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 66d90239..9e15c512 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.8.Final + 5.0.9-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 8ceb803c..71de7120 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.8.Final + 5.0.9-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index 614981df..0e7810ec 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.8.Final + 5.0.9-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 5.0.8.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 8f5b0104..700c902f 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.8.Final + 5.0.9-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.8.Final + 5.0.9-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index d756773f..f02f5bde 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.8.Final + 5.0.9-SNAPSHOT 4.0.0 From fc37c10e502c63310d061ae37032e7b751a4c2d8 Mon Sep 17 00:00:00 2001 From: "Ruiz, Javier" Date: Tue, 11 Jun 2024 17:10:26 +0200 Subject: [PATCH 140/147] Moving slf4j to shade plugin --- nlp/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/nlp/pom.xml b/nlp/pom.xml index 71de7120..0cb27cee 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -62,6 +62,7 @@ com.joestelmach.** + org.slf4j.** edu.emory.** net.fortuna.** org.antlr.** From 4fc2671ec1471d507a5e81c6c8863f7bb78372ee Mon Sep 17 00:00:00 2001 From: Zongle Wang Date: Mon, 17 Jun 2024 15:36:28 +0800 Subject: [PATCH 141/147] Add Maven Central badge [![Maven Central](https://img.shields.io/maven-central/v/org.ocpsoft.prettytime/prettytime)](https://central.sonatype.com/artifact/org.ocpsoft.prettytime/prettytime) --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2e4ca099..a5213987 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ prettytime ========== + +[![Maven Central](https://img.shields.io/maven-central/v/org.ocpsoft.prettytime/prettytime)](https://central.sonatype.com/artifact/org.ocpsoft.prettytime/prettytime) + Social Style Date and Time Formatting for Java Learn more at https://www.ocpsoft.org/prettytime/ @@ -20,8 +23,6 @@ To use prettytime in android, first add the following dependency to your app lev ProGuard rules are automatically configured for you if you use the R8 shrinker (which is the default since version 3.4.0 of the Android Gradle Plugin). If you are using an older version of AGP, add the ProGuard rules from [this file](core/src/main/resources/META-INF/proguard/prettytime.pro) -Be sure to check maven central for the latest version: https://repo1.maven.org/maven2/org/ocpsoft/prettytime/prettytime/ - **Note**: To use prettytime in projects with a `minSdkVersion` below 26, [API desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) is required. DEVELOPMENT From f76749e2c76429f72c8596ceac7bfbc11ee98550 Mon Sep 17 00:00:00 2001 From: Zongle Wang Date: Mon, 17 Jun 2024 15:40:49 +0800 Subject: [PATCH 142/147] Update the version in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a5213987..103ad0a1 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Android ======= To use prettytime in android, first add the following dependency to your app level build.gradle - implementation 'org.ocpsoft.prettytime:prettytime:5.0.4.Final' + implementation 'org.ocpsoft.prettytime:prettytime:5.0.8.Final' ProGuard rules are automatically configured for you if you use the R8 shrinker (which is the default since version 3.4.0 of the Android Gradle Plugin). If you are using an older version of AGP, add the ProGuard rules from [this file](core/src/main/resources/META-INF/proguard/prettytime.pro) From 0d662e6896051cb64f9b5b8b8456b708964c208c Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Fri, 28 Jun 2024 12:58:24 -0400 Subject: [PATCH 143/147] [maven-release-plugin] prepare release 5.0.9.Final --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 0c59dd0b..f74bccce 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.9-SNAPSHOT + 5.0.9.Final ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index 98e90be4..f7576cb4 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.9-SNAPSHOT + 5.0.9.Final ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 9e15c512..3903706f 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.9-SNAPSHOT + 5.0.9.Final ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index 0cb27cee..ea8457d7 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.9-SNAPSHOT + 5.0.9.Final ../pom.xml diff --git a/pom.xml b/pom.xml index 0e7810ec..546e87b9 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.9-SNAPSHOT + 5.0.9.Final PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - HEAD + 5.0.9.Final diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index 700c902f..fdfd847d 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.9-SNAPSHOT + 5.0.9.Final 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.9-SNAPSHOT + 5.0.9.Final diff --git a/samples/pom.xml b/samples/pom.xml index f02f5bde..f027735b 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.9-SNAPSHOT + 5.0.9.Final 4.0.0 From 1893f6ffac52f7c53f1eeb9e051ac7f329f73ac3 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Fri, 28 Jun 2024 12:58:24 -0400 Subject: [PATCH 144/147] [maven-release-plugin] prepare for next development iteration --- core/pom.xml | 2 +- jsf/pom.xml | 2 +- jstl/pom.xml | 2 +- nlp/pom.xml | 2 +- pom.xml | 4 ++-- samples/jstl/pom.xml | 4 ++-- samples/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index f74bccce..87c2594f 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.9.Final + 5.0.10-SNAPSHOT ../pom.xml diff --git a/jsf/pom.xml b/jsf/pom.xml index f7576cb4..a8fd18df 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,7 +4,7 @@ org.ocpsoft.prettytime prettytime-parent - 5.0.9.Final + 5.0.10-SNAPSHOT ../pom.xml diff --git a/jstl/pom.xml b/jstl/pom.xml index 3903706f..6b147196 100644 --- a/jstl/pom.xml +++ b/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.9.Final + 5.0.10-SNAPSHOT ../pom.xml diff --git a/nlp/pom.xml b/nlp/pom.xml index ea8457d7..044e018f 100644 --- a/nlp/pom.xml +++ b/nlp/pom.xml @@ -3,7 +3,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.9.Final + 5.0.10-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index 546e87b9..b988f346 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ prettytime-parent pom - 5.0.9.Final + 5.0.10-SNAPSHOT PrettyTime - Parent Social style time-formatting utilities and web-framework integrations. @@ -48,7 +48,7 @@ scm:git:git://github.com/ocpsoft/prettytime.git scm:git:git@github.com:ocpsoft/prettytime.git http://github.com/ocpsoft/prettytime - 5.0.9.Final + HEAD diff --git a/samples/jstl/pom.xml b/samples/jstl/pom.xml index fdfd847d..a4e3ca16 100644 --- a/samples/jstl/pom.xml +++ b/samples/jstl/pom.xml @@ -3,7 +3,7 @@ prettytime-samples org.ocpsoft.prettytime - 5.0.9.Final + 5.0.10-SNAPSHOT 4.0.0 @@ -37,7 +37,7 @@ org.ocpsoft.prettytime prettytime-integration-jstl - 5.0.9.Final + 5.0.10-SNAPSHOT diff --git a/samples/pom.xml b/samples/pom.xml index f027735b..96f55211 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -4,7 +4,7 @@ prettytime-parent org.ocpsoft.prettytime - 5.0.9.Final + 5.0.10-SNAPSHOT 4.0.0 From 3cb9a93ef2408844c27ccf6146af7d0ab8ff091a Mon Sep 17 00:00:00 2001 From: Spiros Vita Date: Sat, 19 Jul 2025 16:25:36 +0300 Subject: [PATCH 145/147] Fix bad Greek translations and update the tests accordingly --- .../ocpsoft/prettytime/i18n/Resources_el.java | 48 +++++++++---------- .../prettytime/PrettyTimeI18n_EL_Test.java | 26 +++++----- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_el.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_el.java index 89e96139..6203bdd0 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_el.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_el.java @@ -8,29 +8,29 @@ public class Resources_el extends ListResourceBundle { {"CenturyPattern", "%n %u"}, {"CenturyFuturePrefix", ""}, {"CenturyFutureSuffix", "από τώρα "}, - {"CenturyPastPrefix", ""}, - {"CenturyPastSuffix", "Πριν από "}, - {"CenturySingularName", "αιώνας"}, + {"CenturyPastPrefix", "Πριν από "}, + {"CenturyPastSuffix", ""}, + {"CenturySingularName", "αιώνα"}, {"CenturyPluralName", "αιώνες"}, {"DayPattern", "%n %u"}, {"DayFuturePrefix", ""}, {"DayFutureSuffix", "από τώρα "}, - {"DayPastPrefix", ""}, - {"DayPastSuffix", "Πριν από "}, + {"DayPastPrefix", "Πριν από "}, + {"DayPastSuffix", ""}, {"DaySingularName", "ημέρα"}, {"DayPluralName", "ημέρες"}, {"DecadePattern", "%n %u"}, {"DecadeFuturePrefix", ""}, {"DecadeFutureSuffix", "από τώρα "}, - {"DecadePastPrefix", ""}, - {"DecadePastSuffix", "Πριν από "}, + {"DecadePastPrefix", "Πριν από "}, + {"DecadePastSuffix", ""}, {"DecadeSingularName", "δεκαετία"}, {"DecadePluralName", "δεκαετίες"}, {"HourPattern", "%n %u"}, {"HourFuturePrefix", ""}, {"HourFutureSuffix", "από τώρα "}, - {"HourPastPrefix", ""}, - {"HourPastSuffix", "Πριν από "}, + {"HourPastPrefix", "Πριν από "}, + {"HourPastSuffix", ""}, {"HourSingularName", "ώρα"}, {"HourPluralName", "ώρες"}, {"JustNowPattern", "%u"}, @@ -43,50 +43,50 @@ public class Resources_el extends ListResourceBundle { {"MillenniumPattern", "%n %u"}, {"MillenniumFuturePrefix", ""}, {"MillenniumFutureSuffix", "από τώρα "}, - {"MillenniumPastPrefix", ""}, - {"MillenniumPastSuffix", "Πριν από "}, + {"MillenniumPastPrefix", "Πριν από "}, + {"MillenniumPastSuffix", ""}, {"MillenniumSingularName", "χιλιετία"}, {"MillenniumPluralName", "χιλιετίες"}, {"MillisecondPattern", "%n %u"}, {"MillisecondFuturePrefix", ""}, {"MillisecondFutureSuffix", "από τώρα "}, - {"MillisecondPastPrefix", ""}, - {"MillisecondPastSuffix", "Πριν από "}, + {"MillisecondPastPrefix", "Πριν από "}, + {"MillisecondPastSuffix", ""}, {"MillisecondSingularName", "Χιλιοστό του δευτερολέπτου"}, {"MillisecondPluralName", "Χιλιοστά του δευτερολέπτου"}, {"MinutePattern", "%n %u"}, {"MinuteFuturePrefix", ""}, {"MinuteFutureSuffix", "από τώρα "}, - {"MinutePastPrefix", ""}, - {"MinutePastSuffix", "Πριν από "}, + {"MinutePastPrefix", "Πριν από "}, + {"MinutePastSuffix", ""}, {"MinuteSingularName", "λεπτό"}, {"MinutePluralName", "λεπτά"}, {"MonthPattern", "%n %u"}, {"MonthFuturePrefix", ""}, {"MonthFutureSuffix", "από τώρα "}, - {"MonthPastPrefix", ""}, - {"MonthPastSuffix", "Πριν από "}, - {"MonthSingularName", "μήνας"}, + {"MonthPastPrefix", "Πριν από "}, + {"MonthPastSuffix", ""}, + {"MonthSingularName", "μήνα"}, {"MonthPluralName", "μήνες"}, {"SecondPattern", "%n %u"}, {"SecondFuturePrefix", ""}, {"SecondFutureSuffix", "από τώρα "}, - {"SecondPastPrefix", ""}, - {"SecondPastSuffix", "Πριν από "}, + {"SecondPastPrefix", "Πριν από "}, + {"SecondPastSuffix", ""}, {"SecondSingularName", "δευτερόλεπτο"}, {"SecondPluralName", "δευτερόλεπτα"}, {"WeekPattern", "%n %u"}, {"WeekFuturePrefix", ""}, {"WeekFutureSuffix", "από τώρα "}, - {"WeekPastPrefix", ""}, - {"WeekPastSuffix", "Πριν από "}, + {"WeekPastPrefix", "Πριν από "}, + {"WeekPastSuffix", ""}, {"WeekSingularName", "εβδομάδα"}, {"WeekPluralName", "εβδομάδες"}, {"YearPattern", "%n %u"}, {"YearFuturePrefix", ""}, {"YearFutureSuffix", "από τώρα "}, - {"YearPastPrefix", ""}, - {"YearPastSuffix", "Πριν από "}, + {"YearPastPrefix", "Πριν από "}, + {"YearPastSuffix", ""}, {"YearSingularName", "έτος"}, {"YearPluralName", "έτη"}, {"AbstractTimeUnitPattern", ""}, 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 1dd66e3f..5b707e71 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 @@ -31,7 +31,7 @@ public void testCeilingInterval() throws Exception Date then = format.parse("5/20/2009"); Date ref = format.parse("6/17/2009"); PrettyTime t = new PrettyTime(ref); - Assert.assertEquals("1 μήνας Πριν από", t.format(then)); + Assert.assertEquals("Πριν από 1 μήνα", t.format(then)); } @Test @@ -56,7 +56,7 @@ public void testCalculatePreciceDuration() throws Exception PrettyTime t = new PrettyTime(now); List preciseDuration = t.calculatePreciseDuration( new Date(System.currentTimeMillis() - (2 * 60 * 60 * 1000) - (2 * 60 * 1000))); - Assert.assertEquals("2 ώρες 2 λεπτά Πριν από", t.format(preciseDuration)); + Assert.assertEquals("Πριν από 2 ώρες 2 λεπτά", t.format(preciseDuration)); Assert.assertEquals("2 ώρες 2 λεπτά", t.formatDuration(preciseDuration)); Assert.assertEquals("στιγμές από τώρα", t.format(t.calculatePreciseDuration(now))); } @@ -68,7 +68,7 @@ public void testCalculatePreciseDuration2() prettyTime.clearUnits(); Minute minutes = new Minute(); prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); - Assert.assertEquals("40 λεπτά Πριν από", prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( + Assert.assertEquals("Πριν από 40 λεπτά", prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration( new Date(new Date().getTime() - 40 * 60 * 1000 - 40 * 1000)))); } @@ -149,7 +149,7 @@ public void testMomentsAgo() throws Exception public void testMinutesAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12)); - Assert.assertEquals("12 λεπτά Πριν από", t.format(new Date(0))); + Assert.assertEquals("Πριν από 12 λεπτά", t.format(new Date(0))); } @Test @@ -163,63 +163,63 @@ public void testMinutesFromNowDefaultReference() 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))); + Assert.assertEquals("Πριν από 3 ώρες", t.format(new Date(0))); } @Test public void testHoursAgoDefaultReference() throws Exception { PrettyTime t = new PrettyTime(); - Assert.assertEquals("3 ώρες Πριν από", t.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 3))); + Assert.assertEquals("Πριν από 3 ώρες", t.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 3))); } @Test public void testDaysAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3)); - Assert.assertEquals("3 ημέρες Πριν από", t.format(new Date(0))); + Assert.assertEquals("Πριν από 3 ημέρες", t.format(new Date(0))); } @Test 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))); + Assert.assertEquals("Πριν από 3 εβδομάδες", t.format(new Date(0))); } @Test public void testMonthsAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(2629743830L * 3L)); - Assert.assertEquals("3 μήνες Πριν από", t.format(new Date(0))); + Assert.assertEquals("Πριν από 3 μήνες", t.format(new Date(0))); } @Test public void testYearsAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L)); - Assert.assertEquals("3 έτη Πριν από", t.format(new Date(0))); + Assert.assertEquals("Πριν από 3 έτη", t.format(new Date(0))); } @Test public void testDecadesAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(315569259747L * 3L)); - Assert.assertEquals("3 δεκαετίες Πριν από", t.format(new Date(0))); + Assert.assertEquals("Πριν από 3 δεκαετίες", t.format(new Date(0))); } @Test public void testCenturiesAgo() throws Exception { PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L)); - Assert.assertEquals("3 αιώνες Πριν από", t.format(new Date(0))); + Assert.assertEquals("Πριν από 3 αιώνες", t.format(new Date(0))); } @Test public void testWithinTwoHoursRounding() throws Exception { PrettyTime t = new PrettyTime(); - Assert.assertEquals("2 ώρες Πριν από", t.format(new Date(new Date().getTime() - 6543990))); + Assert.assertEquals("Πριν από 2 ώρες", t.format(new Date(new Date().getTime() - 6543990))); } @After From bbc0c21b6688505d21a2eb920a4d37345c4f1698 Mon Sep 17 00:00:00 2001 From: svrzii Date: Wed, 9 Apr 2025 14:31:01 +0200 Subject: [PATCH 146/147] Resources_sl: update Slovenian translations --- .../ocpsoft/prettytime/i18n/Resources_sl.java | 222 ++++- .../prettytime/PrettyTimeI18n_SR_Test.java | 940 +++++++++--------- 2 files changed, 691 insertions(+), 471 deletions(-) diff --git a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sl.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sl.java index 115b3609..3588b032 100644 --- a/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sl.java +++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sl.java @@ -15,9 +15,28 @@ */ package org.ocpsoft.prettytime.i18n; +import org.ocpsoft.prettytime.Duration; +import org.ocpsoft.prettytime.TimeFormat; +import org.ocpsoft.prettytime.TimeUnit; +import org.ocpsoft.prettytime.format.SimpleTimeFormat; +import org.ocpsoft.prettytime.impl.TimeFormatProvider; +import org.ocpsoft.prettytime.units.Day; +import org.ocpsoft.prettytime.units.Hour; +import org.ocpsoft.prettytime.units.Millennium; +import org.ocpsoft.prettytime.units.Minute; +import org.ocpsoft.prettytime.units.Week; +import org.ocpsoft.prettytime.units.Month; +import org.ocpsoft.prettytime.units.Year; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.ListResourceBundle; +import java.util.Objects; +import java.util.ResourceBundle; -public class Resources_sl extends ListResourceBundle +public class Resources_sl extends ListResourceBundle implements TimeFormatProvider { private static final Object[][] OBJECTS = new Object[][] { @@ -118,4 +137,205 @@ protected Object[][] getContents() { return OBJECTS; } + + @Override + public TimeFormat getFormatFor(final TimeUnit t) + { + if (t instanceof Minute) { + return new SlTimeFormatBuilder("Minute") + .addNames("minuto", 1) + .addNames("minuti", 2) + .addNames("minute", 4) + .addNames("minut", Long.MAX_VALUE) + .build(this); + } + else if (t instanceof Hour) { + return new SlTimeFormatBuilder("Hour") + .addNames("uro", 1) + .addNames("uri", 2) + .addNames("ure", 4) + .addNames("ur", Long.MAX_VALUE) + .build(this); + } + else if (t instanceof Day) { + return new SlTimeFormatBuilder("Day") + .addNames("dan", 1) + .addNames("dni", Long.MAX_VALUE) + .build(this); + } + else if (t instanceof Week) { + return new SlTimeFormatBuilder("Week") + .addNames("teden", 1) + .addNames("tedna", 2) + .addNames("tedne", 4) + .addNames("tednov", Long.MAX_VALUE) + .build(this); + } + else if (t instanceof Month) { + return new SlTimeFormatBuilder("Month") + .addNames("mesec", 1) + .addNames("meseca", 2) + .addNames("mesece", 4) + .addNames("mesecev", Long.MAX_VALUE) + .build(this); + } + else if (t instanceof Year) { + return new SlTimeFormatBuilder("Year") + .addNames("leto", 1) + .addNames("leti", 2) + .addNames("leta", 4) + .addNames("let", Long.MAX_VALUE) + .build(this); + } + else if (t instanceof Millennium) { + return new SlTimeFormatBuilder("Millennium") + .addNames("tisočletje", 1) + .addNames("tisočletji", 2) + .addNames("tisočletja", 4) + .addNames("tisočletij", Long.MAX_VALUE) + .build(this); + } + // Don't override format for other time units + return null; + } + + private static class SlName implements Comparable + { + + private final boolean isFuture; + + private final Long threshold; + + private final String value; + + public SlName(final boolean isFuture, final String value, final Long threshold) + { + this.isFuture = isFuture; + this.value = value; + this.threshold = threshold; + } + + @Override + public int compareTo(final SlName o) + { + return threshold.compareTo(o.getThreshold()); + } + + public String get() + { + return value; + } + + public long getThreshold() + { + return threshold; + } + + public boolean isFuture() + { + return isFuture; + } + } + + private static class SlTimeFormat extends SimpleTimeFormat + { + + private final List futureNames = new ArrayList(); + + private final List pastNames = new ArrayList(); + + public SlTimeFormat(final String resourceKeyPrefix, final ResourceBundle bundle, final Collection names) + { + setPattern(bundle.getString(resourceKeyPrefix + "Pattern")); + setFuturePrefix(bundle.getString(resourceKeyPrefix + "FuturePrefix")); + setFutureSuffix(bundle.getString(resourceKeyPrefix + "FutureSuffix")); + setPastPrefix(bundle.getString(resourceKeyPrefix + "PastPrefix")); + setPastSuffix(bundle.getString(resourceKeyPrefix + "PastSuffix")); + setSingularName(bundle.getString(resourceKeyPrefix + "SingularName")); + setPluralName(bundle.getString(resourceKeyPrefix + "PluralName")); + + try { + setFuturePluralName(bundle.getString(resourceKeyPrefix + "FuturePluralName")); + } + catch (final Exception e) { + } + try { + setFutureSingularName(bundle.getString(resourceKeyPrefix + "FutureSingularName")); + } + catch (final Exception e) { + } + try { + setPastPluralName(bundle.getString(resourceKeyPrefix + "PastPluralName")); + } + catch (final Exception e) { + } + try { + setPastSingularName(bundle.getString(resourceKeyPrefix + "PastSingularName")); + } + catch (final Exception e) { + } + + for (final SlName name : names) { + if (name.isFuture()) { + futureNames.add(name); + } + else { + pastNames.add(name); + } + } + Collections.sort(futureNames); + Collections.sort(pastNames); + } + + private String getGramaticallyCorrectName(final long quantity, final List names) + { + for (final SlName name : names) { + if (name.getThreshold() >= quantity) { + return name.get(); + } + } + throw new IllegalStateException("Invalid resource bundle configuration"); + } + + @Override + protected String getGramaticallyCorrectName(final Duration d, final boolean round) + { + final long quantity = Math.abs(getQuantity(d, round)); + if (d.isInFuture()) { + return getGramaticallyCorrectName(quantity, futureNames); + } + return getGramaticallyCorrectName(quantity, pastNames); + } + + } + + private static class SlTimeFormatBuilder + { + + private final List names = new ArrayList(); + + private final String resourceKeyPrefix; + + SlTimeFormatBuilder(final String resourceKeyPrefix) + { + this.resourceKeyPrefix = resourceKeyPrefix; + } + + private SlTimeFormatBuilder addName(final boolean isFuture, final String name, final long limit) + { + names.add(new SlName(isFuture, Objects.requireNonNull(name), limit)); + return this; + } + + SlTimeFormatBuilder addNames(final String name, final long limit) + { + return addName(true, name, limit).addName(false, name, limit); + } + + SlTimeFormat build(final ResourceBundle bundle) + { + return new SlTimeFormat(resourceKeyPrefix, bundle, names); + } + + } } diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SR_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SR_Test.java index e6ca5694..8a7e3846 100644 --- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SR_Test.java +++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SR_Test.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * -*     http://www.apache.org/licenses/LICENSE-2.0 +* http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -34,474 +34,474 @@ public class PrettyTimeI18n_SR_Test { -   private Locale locale; -   private LocalDateTime now; - -   @Before -   public void setUp() throws Exception -   { -      locale = Locale.getDefault(); -      Locale.setDefault(Locale.ROOT); -      now = LocalDateTime.now(); -   } - -   @Test -   public void testCeilingInterval() throws Exception -   { -      PrettyTime prettyTime = new PrettyTime(LocalDate.of(2009, 6, 17)); -      Assert.assertEquals("пре 1 месец", prettyTime.format(LocalDate.of(2009, 5, 20))); -   } - -   @Test -   public void testNullDate() throws Exception -   { -      PrettyTime t = new PrettyTime(); -      Date date = null; -      Assert.assertEquals("за неколико тренутака", t.format(date)); -   } - -   @Test -   public void testRightNow() throws Exception -   { -      PrettyTime t = new PrettyTime(); -      Assert.assertEquals("за неколико тренутака", t.format(new Date())); -   } - -   @Test -   public void testRightNowWithReference() throws Exception -   { -      Date now = new Date(); -      Date ref = new Date(); -      PrettyTime t = new PrettyTime(ref); -      String formatted = t.format(now); -      Assert.assertEquals("за неколико тренутака", formatted); -   } - -   @Test -   public void testCalculatePreciceDuration() throws Exception -   { -      PrettyTime t = new PrettyTime(); -      List preciseDuration = t.calculatePreciseDuration( -               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(new Date().getTime() - 10)))); - -      preciseDuration = t.calculatePreciseDuration(now.minusHours(2).minusMinutes(2)); -      Assert.assertEquals("пре 2 сата 2 минута", t.format(preciseDuration)); -      Assert.assertEquals("2 сата 2 минута", t.formatDuration(preciseDuration)); -      Assert.assertEquals("за неколико тренутака", t.format(t.calculatePreciseDuration(LocalDateTime.now().plusSeconds(1)))); -   } - -   @Test -   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 дан 9 сати 19 минута", t.format(durations)); -      Assert.assertEquals("1 миленијум 9 векова 1 месец 1 дан 9 сати 19 минута", t.formatDuration(durations)); -   } - -   @Test -   public void testCalculatePreciseDurationSingleUnit() -   { -      PrettyTime prettyTime = new PrettyTime(); -      Minute minutes = new Minute(); -      prettyTime.setUnits(minutes); -      Assert.assertEquals("пре 40 минута", prettyTime.formatUnrounded(prettyTime -               .calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); -   } - -   @Test -   public void testCalculatePreciseDurationSingleUnitWithFormat() -   { -      PrettyTime prettyTime = new PrettyTime(); -      Minute minutes = new Minute(); -      TimeFormat format = new SimpleTimeFormat().setPluralName("минута").setPattern("%n %u"); -      prettyTime.setUnits(format, minutes); -      Assert.assertEquals("40 минута", prettyTime.formatUnrounded(prettyTime -               .calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); -   } - -   @Test -   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(now.minusSeconds(40).minusMinutes(40)))); -   } - -   @Test -   public void testRightNowVariance() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("за неколико тренутака", t.format(now.plus(600, ChronoUnit.MILLIS))); -   } - -   @Test -   public void testMinutesFromNow() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("за 12 минута", t.format(now.plusMinutes(12))); -   } - -   @Test -   public void testHoursFromNow() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("за 3 сата", t.format(now.plusHours(3))); -   } - -   @Test -   public void testDaysFromNow() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("за 3 дана", t.format(now.plusDays(3))); -   } - -   @Test -   public void testWeeksFromNow() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("за 3 недеље", t.format(now.plusWeeks(3))); -   } - -   @Test -   public void testMonthsFromNow() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("за 3 месеца", t.format(now.plusMonths(3))); -   } - -   @Test -   public void testYearsFromNow() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("за 3 године", t.format(now.plusYears(3))); -   } - -   @Test -   public void testDecadesFromNow() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("за 3 деценије", t.format(now.plus(3, ChronoUnit.DECADES))); -   } - -   @Test -   public void testCenturiesFromNow() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("за 3 века", t.format(now.plus(3, ChronoUnit.CENTURIES))); -   } - -   /* -    * Past -    */ -   @Test -   public void testMomentsAgo() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("пре неколико тренутака", t.format(now.minusSeconds(6))); -   } - -   @Test -   public void testMinutesAgo() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("пре 12 минута", t.format(now.minusMinutes(12))); -   } - -   @Test -   public void testMinutesFromNowDefaultReference() throws Exception -   { -      PrettyTime t = new PrettyTime(); -      Assert.assertEquals("пре 12 минута", t.format(now.plusMinutes(12))); -   } - -   @Test -   public void testHoursAgo() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("пре 3 сата", t.format(now.minusHours(3))); -   } - -   @Test -   public void testHoursAgoDefaultReference() throws Exception -   { -      PrettyTime t = new PrettyTime(); -      Assert.assertEquals("пре 3 сата", t.format(now.minusHours(3))); -   } - -   @Test -   public void testDaysAgo() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("пре 3 дана", t.format(now.minusDays(3))); -   } - -   @Test -   public void testWeeksAgo() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("пре 3 недеље", t.format(now.minusWeeks(3))); -   } - -   @Test -   public void testMonthsAgo() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("пре 3 месеца", t.format(now.minusMonths(3))); -   } - -   @Test -   public void testCustomFormat() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      TimeUnit unit = new TimeUnit() { -         @Override -         public long getMaxQuantity() -         { -            return 0; -         } - -         @Override -         public long getMillisPerUnit() -         { -            return 5000; -         } - -         @Override -         public boolean isPrecise() -         { -            return false; -         } -      }; -      t.clearUnits(); -      t.registerUnit(unit, new SimpleTimeFormat() -               .setSingularName("откуцај").setPluralName("откуцаја") -               .setPattern("%n %u").setRoundingTolerance(20) -               .setFutureSuffix("... ТРЧИ!") -               .setFuturePrefix("самоуништење је за: ").setPastPrefix("самоуништење је било: ").setPastSuffix( -                        "пре ...")); - -      final LocalDateTime fiveTicks = now.plusSeconds(25); -      Assert.assertEquals("самоуништење је за: 5 откуцаја... ТРЧИ!", t.format(fiveTicks)); -      t.setReference(fiveTicks); -      Assert.assertEquals("самоуништење је било: пре 5 откуцаја...", t.format(now)); -   } - -   @Test -   public void testYearsAgo() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("пре 3 године", t.format(now.minusYears(3))); -   } - -   @Test -   public void testDecadesAgo() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("пре 3 деценије", t.format(now.minus(3, ChronoUnit.DECADES))); -   } - -   @Test -   public void testCenturiesAgo() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("пре 3 века", t.format(now.minus(3, ChronoUnit.CENTURIES))); -   } - -   @Test -   public void testWithinTwoHoursRounding() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      Assert.assertEquals("пре 2 сата", t.format(now.minusHours(1).minusMinutes(45))); -   } - -   @Test -   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); -      Assert.assertEquals(5, durations.get(0).getQuantity()); -      Assert.assertEquals(10, durations.get(1).getQuantity()); -   } - -   @Test -   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); -      Assert.assertEquals(-5, durations.get(0).getQuantity()); -      Assert.assertEquals(-10, durations.get(1).getQuantity()); -   } - -   @Test -   public void testFormattingDurationListInThePast() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      List durations = t.calculatePreciseDuration(now.minusDays(3).minusHours(15).minusMinutes(38)); -      Assert.assertEquals("пре 3 дана 15 сати 38 минута", t.format(durations)); -   } - -   @Test -   public void testFormattingDurationListInTheFuture() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      List durations = t.calculatePreciseDuration(now.plusDays(3).plusHours(15).plusMinutes(38)); -      Assert.assertEquals("за 3 дана 15 сати 38 минута", t.format(durations)); -   } - -   @Test -   public void testSetLocale() throws Exception -   { -      PrettyTime t = new PrettyTime(now); -      final LocalDateTime threeDecadesAgo = now.minus(3, ChronoUnit.DECADES); -      Assert.assertEquals("пре 3 деценије", t.format(threeDecadesAgo)); -      t.setLocale(Locale.GERMAN); -      Assert.assertEquals("пре 3 деценије", t.format(threeDecadesAgo)); -   } - -   /** -    * 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 -   { -      Calendar c = Calendar.getInstance(); -      Date r = c.getTime(); -      PrettyTime t = new PrettyTime(); -      t.setLocale(Locale.ENGLISH); -      t.setReference(r); -      c.add(Calendar.YEAR, -1); -      Assert.assertEquals("пре 1 годину", t.format(c)); -   } - -   /** -    * Tests formatApproximateDuration and by proxy, formatDuration. -    * -    * @throws Exception -    */ -   @Test -   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(); -      String result = t.formatDuration(tenMinAgo); -      Assert.assertEquals("10 минута", result); - -      result = t.formatDuration(now.minusMinutes(10)); -      Assert.assertEquals("10 минута", result); -   } - -   @Test -   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(); -      String result = t.formatDuration(tenMinAgo); -      Assert.assertEquals("11 минута", result); - -      result = t.formatDuration(now.minusMinutes(10).minusSeconds(40)); -      Assert.assertEquals("11 минута", result); -   } - -   @Test -   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(); -      String result = t.formatDurationUnrounded(tenMinAgo); -      Assert.assertEquals("10 минута", result); - -      result = t.formatDurationUnrounded(now.minusMinutes(10).minusSeconds(40)); -      Assert.assertEquals("10 минута", result); -   } - -   @Test -   public void testFormatList() throws Exception -   { -      PrettyTime prettyTime = new PrettyTime(); -      prettyTime.clearUnits(); -      Minute minutes = new Minute(); -      prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); -      Assert.assertEquals("пре 41 минут", -               prettyTime.format(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); -   } - -   @Test -   public void testFormatListUnrounded() throws Exception -   { -      PrettyTime prettyTime = new PrettyTime(); -      prettyTime.clearUnits(); -      Minute minutes = new Minute(); -      prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); -      Assert.assertEquals("пре 40 минута", -               prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); -   } - -   @Test -   public void testFormatDurationList() throws Exception -   { -      PrettyTime prettyTime = new PrettyTime(); -      prettyTime.clearUnits(); -      Minute minutes = new Minute(); -      prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); -      Assert.assertEquals("41 минут", -               prettyTime.formatDuration(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); -   } - -   @Test -   public void testFormatDurationListUnrounded() throws Exception -   { -      PrettyTime prettyTime = new PrettyTime(); -      prettyTime.clearUnits(); -      Minute minutes = new Minute(); -      prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); -      Assert.assertEquals("40 минута", -               prettyTime.formatDurationUnrounded(prettyTime.calculatePreciseDuration( -                        now.minusMinutes(40).minusSeconds(40)))); -   } - -   @Test -   public void testCalculatePreciseDuration() -   { -      PrettyTime prettyTime = new PrettyTime(); -      prettyTime.clearUnits(); -      Minute minutes = new Minute(); -      prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); -      Assert.assertEquals("пре 41 минут", -               prettyTime.format(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); -   } - -   @Test -   public void testCalculatePreciseDurationUnrounded() -   { -      PrettyTime prettyTime = new PrettyTime(); -      prettyTime.clearUnits(); -      Minute minutes = new Minute(); -      prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); -      Assert.assertEquals("пре 40 минута", -               prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); -   } - -   @After -   public void tearDown() throws Exception -   { -      Locale.setDefault(locale); -   } + private Locale locale; + private LocalDateTime now; + + @Before + public void setUp() throws Exception + { + locale = Locale.getDefault(); + Locale.setDefault(Locale.ROOT); + now = LocalDateTime.now(); + } + + @Test + public void testCeilingInterval() throws Exception + { + PrettyTime prettyTime = new PrettyTime(LocalDate.of(2009, 6, 17)); + Assert.assertEquals("пре 1 месец", prettyTime.format(LocalDate.of(2009, 5, 20))); + } + + @Test + public void testNullDate() throws Exception + { + PrettyTime t = new PrettyTime(); + Date date = null; + Assert.assertEquals("за неколико тренутака", t.format(date)); + } + + @Test + public void testRightNow() throws Exception + { + PrettyTime t = new PrettyTime(); + Assert.assertEquals("за неколико тренутака", t.format(new Date())); + } + + @Test + public void testRightNowWithReference() throws Exception + { + Date now = new Date(); + Date ref = new Date(); + PrettyTime t = new PrettyTime(ref); + String formatted = t.format(now); + Assert.assertEquals("за неколико тренутака", formatted); + } + + @Test + public void testCalculatePreciceDuration() throws Exception + { + PrettyTime t = new PrettyTime(); + List preciseDuration = t.calculatePreciseDuration( + 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(new Date().getTime() - 10)))); + + preciseDuration = t.calculatePreciseDuration(now.minusHours(2).minusMinutes(2)); + Assert.assertEquals("пре 2 сата 2 минута", t.format(preciseDuration)); + Assert.assertEquals("2 сата 2 минута", t.formatDuration(preciseDuration)); + Assert.assertEquals("за неколико тренутака", t.format(t.calculatePreciseDuration(LocalDateTime.now().plusSeconds(1)))); + } + + @Test + 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 дан 9 сати 19 минута", t.format(durations)); + Assert.assertEquals("1 миленијум 9 векова 1 месец 1 дан 9 сати 19 минута", t.formatDuration(durations)); + } + + @Test + public void testCalculatePreciseDurationSingleUnit() + { + PrettyTime prettyTime = new PrettyTime(); + Minute minutes = new Minute(); + prettyTime.setUnits(minutes); + Assert.assertEquals("пре 40 минута", prettyTime.formatUnrounded(prettyTime + .calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); + } + + @Test + public void testCalculatePreciseDurationSingleUnitWithFormat() + { + PrettyTime prettyTime = new PrettyTime(); + Minute minutes = new Minute(); + TimeFormat format = new SimpleTimeFormat().setPluralName("минута").setPattern("%n %u"); + prettyTime.setUnits(format, minutes); + Assert.assertEquals("40 минута", prettyTime.formatUnrounded(prettyTime + .calculatePreciseDuration(now.minusSeconds(40).minusMinutes(40)))); + } + + @Test + 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(now.minusSeconds(40).minusMinutes(40)))); + } + + @Test + public void testRightNowVariance() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("за неколико тренутака", t.format(now.plus(600, ChronoUnit.MILLIS))); + } + + @Test + public void testMinutesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("за 12 минута", t.format(now.plusMinutes(12))); + } + + @Test + public void testHoursFromNow() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("за 3 сата", t.format(now.plusHours(3))); + } + + @Test + public void testDaysFromNow() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("за 3 дана", t.format(now.plusDays(3))); + } + + @Test + public void testWeeksFromNow() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("за 3 недеље", t.format(now.plusWeeks(3))); + } + + @Test + public void testMonthsFromNow() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("за 3 месеца", t.format(now.plusMonths(3))); + } + + @Test + public void testYearsFromNow() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("за 3 године", t.format(now.plusYears(3))); + } + + @Test + public void testDecadesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("за 3 деценије", t.format(now.plus(3, ChronoUnit.DECADES))); + } + + @Test + public void testCenturiesFromNow() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("за 3 века", t.format(now.plus(3, ChronoUnit.CENTURIES))); + } + + /* + * Past + */ + @Test + public void testMomentsAgo() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("пре неколико тренутака", t.format(now.minusSeconds(6))); + } + + @Test + public void testMinutesAgo() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("пре 12 минута", t.format(now.minusMinutes(12))); + } + + @Test + public void testMinutesFromNowDefaultReference() throws Exception + { + PrettyTime t = new PrettyTime(); + Assert.assertEquals("пре 12 минута", t.format(now.plusMinutes(12))); + } + + @Test + public void testHoursAgo() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("пре 3 сата", t.format(now.minusHours(3))); + } + + @Test + public void testHoursAgoDefaultReference() throws Exception + { + PrettyTime t = new PrettyTime(); + Assert.assertEquals("пре 3 сата", t.format(now.minusHours(3))); + } + + @Test + public void testDaysAgo() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("пре 3 дана", t.format(now.minusDays(3))); + } + + @Test + public void testWeeksAgo() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("пре 3 недеље", t.format(now.minusWeeks(3))); + } + + @Test + public void testMonthsAgo() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("пре 3 месеца", t.format(now.minusMonths(3))); + } + + @Test + public void testCustomFormat() throws Exception + { + PrettyTime t = new PrettyTime(now); + TimeUnit unit = new TimeUnit() { + @Override + public long getMaxQuantity() + { + return 0; + } + + @Override + public long getMillisPerUnit() + { + return 5000; + } + + @Override + public boolean isPrecise() + { + return false; + } + }; + t.clearUnits(); + t.registerUnit(unit, new SimpleTimeFormat() + .setSingularName("откуцај").setPluralName("откуцаја") + .setPattern("%n %u").setRoundingTolerance(20) + .setFutureSuffix("... ТРЧИ!") + .setFuturePrefix("самоуништење је за: ").setPastPrefix("самоуништење је било: ").setPastSuffix( + "пре ...")); + + final LocalDateTime fiveTicks = now.plusSeconds(25); + Assert.assertEquals("самоуништење је за: 5 откуцаја... ТРЧИ!", t.format(fiveTicks)); + t.setReference(fiveTicks); + Assert.assertEquals("самоуништење је било: пре 5 откуцаја...", t.format(now)); + } + + @Test + public void testYearsAgo() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("пре 3 године", t.format(now.minusYears(3))); + } + + @Test + public void testDecadesAgo() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("пре 3 деценије", t.format(now.minus(3, ChronoUnit.DECADES))); + } + + @Test + public void testCenturiesAgo() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("пре 3 века", t.format(now.minus(3, ChronoUnit.CENTURIES))); + } + + @Test + public void testWithinTwoHoursRounding() throws Exception + { + PrettyTime t = new PrettyTime(now); + Assert.assertEquals("пре 2 сата", t.format(now.minusHours(1).minusMinutes(45))); + } + + @Test + 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); + Assert.assertEquals(5, durations.get(0).getQuantity()); + Assert.assertEquals(10, durations.get(1).getQuantity()); + } + + @Test + 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); + Assert.assertEquals(-5, durations.get(0).getQuantity()); + Assert.assertEquals(-10, durations.get(1).getQuantity()); + } + + @Test + public void testFormattingDurationListInThePast() throws Exception + { + PrettyTime t = new PrettyTime(now); + List durations = t.calculatePreciseDuration(now.minusDays(3).minusHours(15).minusMinutes(38)); + Assert.assertEquals("пре 3 дана 15 сати 38 минута", t.format(durations)); + } + + @Test + public void testFormattingDurationListInTheFuture() throws Exception + { + PrettyTime t = new PrettyTime(now); + List durations = t.calculatePreciseDuration(now.plusDays(3).plusHours(15).plusMinutes(38)); + Assert.assertEquals("за 3 дана 15 сати 38 минута", t.format(durations)); + } + + @Test + public void testSetLocale() throws Exception + { + PrettyTime t = new PrettyTime(now); + final LocalDateTime threeDecadesAgo = now.minus(3, ChronoUnit.DECADES); + Assert.assertEquals("пре 3 деценије", t.format(threeDecadesAgo)); + t.setLocale(Locale.GERMAN); + Assert.assertEquals("пре 3 деценије", t.format(threeDecadesAgo)); + } + + /** + * 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 + { + Calendar c = Calendar.getInstance(); + Date r = c.getTime(); + PrettyTime t = new PrettyTime(); + t.setLocale(Locale.ENGLISH); + t.setReference(r); + c.add(Calendar.YEAR, -1); + Assert.assertEquals("пре 1 годину", t.format(c)); + } + + /** + * Tests formatApproximateDuration and by proxy, formatDuration. + * + * @throws Exception + */ + @Test + 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(); + String result = t.formatDuration(tenMinAgo); + Assert.assertEquals("10 минута", result); + + result = t.formatDuration(now.minusMinutes(10)); + Assert.assertEquals("10 минута", result); + } + + @Test + 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(); + String result = t.formatDuration(tenMinAgo); + Assert.assertEquals("11 минута", result); + + result = t.formatDuration(now.minusMinutes(10).minusSeconds(40)); + Assert.assertEquals("11 минута", result); + } + + @Test + 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(); + String result = t.formatDurationUnrounded(tenMinAgo); + Assert.assertEquals("10 минута", result); + + result = t.formatDurationUnrounded(now.minusMinutes(10).minusSeconds(40)); + Assert.assertEquals("10 минута", result); + } + + @Test + public void testFormatList() throws Exception + { + PrettyTime prettyTime = new PrettyTime(); + prettyTime.clearUnits(); + Minute minutes = new Minute(); + prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); + Assert.assertEquals("пре 41 минут", + prettyTime.format(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); + } + + @Test + public void testFormatListUnrounded() throws Exception + { + PrettyTime prettyTime = new PrettyTime(); + prettyTime.clearUnits(); + Minute minutes = new Minute(); + prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); + Assert.assertEquals("пре 40 минута", + prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); + } + + @Test + public void testFormatDurationList() throws Exception + { + PrettyTime prettyTime = new PrettyTime(); + prettyTime.clearUnits(); + Minute minutes = new Minute(); + prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); + Assert.assertEquals("41 минут", + prettyTime.formatDuration(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); + } + + @Test + public void testFormatDurationListUnrounded() throws Exception + { + PrettyTime prettyTime = new PrettyTime(); + prettyTime.clearUnits(); + Minute minutes = new Minute(); + prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); + Assert.assertEquals("40 минута", + prettyTime.formatDurationUnrounded(prettyTime.calculatePreciseDuration( + now.minusMinutes(40).minusSeconds(40)))); + } + + @Test + public void testCalculatePreciseDuration() + { + PrettyTime prettyTime = new PrettyTime(); + prettyTime.clearUnits(); + Minute minutes = new Minute(); + prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); + Assert.assertEquals("пре 41 минут", + prettyTime.format(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); + } + + @Test + public void testCalculatePreciseDurationUnrounded() + { + PrettyTime prettyTime = new PrettyTime(); + prettyTime.clearUnits(); + Minute minutes = new Minute(); + prettyTime.registerUnit(minutes, new ResourcesTimeFormat(minutes)); + Assert.assertEquals("пре 40 минута", + prettyTime.formatUnrounded(prettyTime.calculatePreciseDuration(now.minusMinutes(40).minusSeconds(40)))); + } + + @After + public void tearDown() throws Exception + { + Locale.setDefault(locale); + } } From ac1e994588e351af1f84e859a3c6110b1e740ce8 Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Mon, 29 Sep 2025 11:26:58 -0400 Subject: [PATCH 147/147] feat(build): add mise.toml to manage environment --- mise.toml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 mise.toml diff --git a/mise.toml b/mise.toml new file mode 100644 index 00000000..8adce707 --- /dev/null +++ b/mise.toml @@ -0,0 +1,14 @@ +[tools] +# Java 8 is the minimum required version for PrettyTime 5.x +# Using the latest Amazon Corretto 8 for exact compatibility with project requirements +java = "microsoft-11.0.28" + +# Maven for building the project +maven = "3.9" + +[env] +# Set JAVA_HOME for Maven and other tools +JAVA_HOME = "{{exec(command='mise where java')}}" + +# Maven configuration +MAVEN_OPTS = "-Xmx1024m -XX:MaxPermSize=256m"