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/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
diff --git a/README.md b/README.md
index 7bdc699e..103ad0a1 100644
--- a/README.md
+++ b/README.md
@@ -1,17 +1,39 @@
prettytime
==========
-[](http://www.libtastic.com/technology/152/)
+
+[](https://central.sonatype.com/artifact/org.ocpsoft.prettytime/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)
+=======
+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
+To use prettytime in android, first add the following dependency to your app level build.gradle
+
+ 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)
+
+**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
+===========
+export RELEASE_VERSION="5.x.x.Final"
+export SNAPSHOT_VERSION="5.x.x-SNAPSHOT"
- compile 'org.ocpsoft.prettytime:prettytime:4.0.1.Final'
+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"
-When using Android with ProGuard, you must add the following to your ProGuard configuration script:
+CODE FORMAT DEFINITIONS/CONFIG
+==============================
+Please use the following eclipse-style code formatter settings when submitting PRs:
- -keep class org.ocpsoft.prettytime.i18n.**
+https://github.com/ocpsoft/common/blob/master/ocpsoft-eclipse-code-format.xml
diff --git a/core/pom.xml b/core/pom.xml
index 76ae3b4d..87c2594f 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -4,7 +4,7 @@
org.ocpsoft.prettytimeprettytime-parent
- 4.0.1-SNAPSHOT
+ 5.0.10-SNAPSHOT../pom.xml
@@ -22,8 +22,8 @@
Pretty Time Coreorg.ocpsoft.prettytime.core
-
-
+
+
<_exportcontents>org.ocpsoft.prettytime*
diff --git a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java
index 3517ff80..668f3c37 100644
--- a/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java
+++ b/core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java
@@ -15,14 +15,23 @@
*/
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.LinkedHashMap;
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;
@@ -37,13 +46,12 @@
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;
/**
- * 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:
*
@@ -63,9 +71,9 @@
*/
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 ConcurrentHashMap<>();
private volatile List cachedUnits;
private String overrideResourceBundle;
@@ -76,19 +84,19 @@ public class PrettyTime
*/
public PrettyTime()
{
- initTimeUnits();
+ this((String) null);
}
/**
* 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(String overrideResourceBundle)
+ public PrettyTime(final String overrideResourceBundle)
{
this.overrideResourceBundle = overrideResourceBundle;
- initTimeUnits();
+ this.initTimeUnits();
}
/**
@@ -96,10 +104,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)
{
@@ -113,17 +117,150 @@ 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 Date reference, String overrideResourceBundle)
+ 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 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
@@ -132,22 +269,21 @@ public PrettyTime(final Date reference, String overrideResourceBundle)
*/
public PrettyTime(final Locale locale)
{
+ this();
setLocale(locale);
- initTimeUnits();
}
/**
* 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)
{
- this.overrideResourceBundle = overrideResourceBundle;
+ this(overrideResourceBundle);
setLocale(locale);
- initTimeUnits();
}
/**
@@ -172,8 +308,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)}.
*/
@@ -186,25 +322,93 @@ 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)
{
if (then == null)
then = now();
- Date ref = reference;
- if (null == ref)
- ref = now();
-
- long difference = then.getTime() - ref.getTime();
+ final Instant ref = reference != null ? reference : Instant.now();
+ long difference = then.getTime() - ref.toEpochMilli();
+ if (difference == 0) {
+ difference = 1;
+ }
return calculateDuration(difference);
}
+ /**
+ * 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()
+ */
+ 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, ZoneId.systemDefault());
+ }
+
+ /**
+ * 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).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, ZoneId.systemDefault());
+ }
+
+ /**
+ * 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 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
@@ -217,27 +421,42 @@ public Duration approximateDuration(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(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();
- 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();
+ List result = new ArrayList<>();
+ long difference = then.toEpochMilli() - reference.toEpochMilli();
Duration duration = calculateDuration(difference);
result.add(duration);
- while (0 != duration.getDelta())
- {
+ 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()))
- {
+ if (last.getUnit().equals(duration.getUnit())) {
break;
}
}
@@ -248,6 +467,92 @@ 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 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.
@@ -317,6 +622,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
@@ -330,6 +638,101 @@ 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.
@@ -408,9 +811,107 @@ 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
+ * 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.
*
*
@@ -425,7 +926,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.
*
@@ -444,7 +945,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.
*
@@ -462,11 +963,11 @@ 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.
*
- * @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)
@@ -495,11 +996,124 @@ public String formatDuration(final List durations)
}
/**
- * 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
+ * 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
+ * @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 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
+ * @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 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
+ * @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 Instant}. 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 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 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.
+ *
+ *
+ * @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 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
* @return A formatted string of the given {@link Date}
@@ -512,11 +1126,11 @@ 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.
*
- *
+ *
* @param then the date to be formatted
* @return A formatted string of the given {@link Date}
*/
@@ -531,8 +1145,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
@@ -549,11 +1163,11 @@ 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 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)
@@ -576,50 +1190,260 @@ 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 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
+ * @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 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 {@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 Instant}. 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 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
+ * @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.
*/
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);
}
- return null;
+ 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());
+ }
}
/**
- * 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.
*/
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);
}
@@ -636,14 +1460,25 @@ 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;
}
}
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
@@ -651,14 +1486,10 @@ 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.");
- if (format == null)
- throw new IllegalArgumentException("Format 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)
@@ -666,6 +1497,47 @@ 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)
+ throw new IllegalArgumentException("TimeUnit instance(s) to register must be provided.");
+
+ this.clearUnits();
+ for (ResourcesTimeUnit unit : units) {
+ TimeFormat format = new ResourcesTimeFormat(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.");
+ Objects.requireNonNull(format, "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
@@ -677,8 +1549,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);
@@ -702,6 +1573,18 @@ 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.
*/
@@ -712,7 +1595,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)
{
@@ -728,6 +1611,7 @@ public PrettyTime setLocale(Locale locale)
if (format instanceof LocaleAware)
((LocaleAware>) format).setLocale(locale);
}
+ cachedUnits = null;
return this;
}
@@ -788,32 +1672,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);
}
@@ -826,12 +1705,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/TimeUnit.java b/core/src/main/java/org/ocpsoft/prettytime/TimeUnit.java
index d33bae10..66b2419a 100644
--- a/core/src/main/java/org/ocpsoft/prettytime/TimeUnit.java
+++ b/core/src/main/java/org/ocpsoft/prettytime/TimeUnit.java
@@ -15,6 +15,20 @@
*/
package org.ocpsoft.prettytime;
+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;
+
/**
* Defines a Unit of time (e.g. seconds, minutes, hours) and its conversion to milliseconds.
*
@@ -47,4 +61,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/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java b/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java
index 8ea553ca..88b837f5 100644
--- a/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java
+++ b/core/src/main/java/org/ocpsoft/prettytime/format/SimpleTimeFormat.java
@@ -15,7 +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;
@@ -24,13 +28,17 @@
*
* @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";
public static final String QUANTITY = "%n";
public static final String UNIT = "%u";
+ private static final Pattern PATTERN_MULTIPLE_WHITESPACES = Pattern.compile("\\s{2,}");
+
+ private Locale locale;
+
private String singularName = "";
private String pluralName = "";
private String futureSingularName = "";
@@ -45,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)
{
@@ -61,15 +76,13 @@ 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 result.toString().replaceAll("\\s+", " ").trim();
+ return PATTERN_MULTIPLE_WHITESPACES.matcher(result).replaceAll(" ").trim();
}
@Override
@@ -90,9 +103,13 @@ 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);
+ 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;
}
@@ -111,20 +128,24 @@ 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 ((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, final boolean round)
+ {
+ final long quantity = Math.abs(getQuantity(d, round));
+ return (quantity == 0) || (quantity > 1);
+ }
+
private String getSign(final Duration d)
{
- if (d.getQuantity() < 0)
- {
+ if (d.getQuantity() < 0) {
return NEGATIVE;
}
return "";
@@ -153,6 +174,7 @@ else if (duration.isInPast() && pastPluralName != null && pastSingularName.lengt
/*
* Builder Setters
*/
+
public SimpleTimeFormat setPattern(final String pattern)
{
this.pattern = pattern;
@@ -185,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_az.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_az.java
new file mode 100644
index 00000000..57fc0290
--- /dev/null
+++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_az.java
@@ -0,0 +1,121 @@
+/*
+ * 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.
+ * 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", " sonra" },
+ { "CenturyPastPrefix", "" },
+ { "CenturyPastSuffix", " əvvəl" },
+ { "CenturySingularName", "əsr" },
+ { "CenturyPluralName", "əsr" },
+ { "DayPattern", "%n %u" },
+ { "DayFuturePrefix", "" },
+ { "DayFutureSuffix", " sonra" },
+ { "DayPastPrefix", "" },
+ { "DayPastSuffix", " əvvəl" },
+ { "DaySingularName", "gün" },
+ { "DayPluralName", "gün" },
+ { "DecadePattern", "%n %u" },
+ { "DecadeFuturePrefix", "" },
+ { "DecadeFutureSuffix", " sonra" },
+ { "DecadePastPrefix", "" },
+ { "DecadePastSuffix", " əvvəl" },
+ { "DecadeSingularName", "onillik" },
+ { "DecadePluralName", "onillik" },
+ { "HourPattern", "%n %u" },
+ { "HourFuturePrefix", "" },
+ { "HourFutureSuffix", " sonra" },
+ { "HourPastPrefix", "" },
+ { "HourPastSuffix", " əvvəl" },
+ { "HourSingularName", "saat" },
+ { "HourPluralName", "saat" },
+ { "JustNowPattern", "%u" },
+ { "JustNowFuturePrefix", "" },
+ { "JustNowFutureSuffix", "az sonra" },
+ { "JustNowPastPrefix", "az öncə" },
+ { "JustNowPastSuffix", "" },
+ { "JustNowSingularName", "" },
+ { "JustNowPluralName", "" },
+ { "MillenniumPattern", "%n %u" },
+ { "MillenniumFuturePrefix", "" },
+ { "MillenniumFutureSuffix", "sonra" },
+ { "MillenniumPastPrefix", "" },
+ { "MillenniumPastSuffix", " əvvəl" },
+ { "MillenniumSingularName", "minillik" },
+ { "MillenniumPluralName", "minillik" },
+ { "MillisecondPattern", "%n %u" },
+ { "MillisecondFuturePrefix", "" },
+ { "MillisecondFutureSuffix", " sonra" },
+ { "MillisecondPastPrefix", "" },
+ { "MillisecondPastSuffix", " əvvəl" },
+ { "MillisecondSingularName", "millisaniyə" },
+ { "MillisecondPluralName", "millisaniyə" },
+ { "MinutePattern", "%n %u" },
+ { "MinuteFuturePrefix", "" },
+ { "MinuteFutureSuffix", " sonra" },
+ { "MinutePastPrefix", "" },
+ { "MinutePastSuffix", " əvvəl" },
+ { "MinuteSingularName", "dəqiqə" },
+ { "MinutePluralName", "dəqiqə" },
+ { "MonthPattern", "%n %u" },
+ { "MonthFuturePrefix", "" },
+ { "MonthFutureSuffix", " sonra" },
+ { "MonthPastPrefix", "" },
+ { "MonthPastSuffix", " əvvəl" },
+ { "MonthSingularName", "ay" },
+ { "MonthPluralName", "ay" },
+ { "SecondPattern", "%n %u" },
+ { "SecondFuturePrefix", "" },
+ { "SecondFutureSuffix", " sonra" },
+ { "SecondPastPrefix", "" },
+ { "SecondPastSuffix", " əvvəl" },
+ { "SecondSingularName", "saniyə" },
+ { "SecondPluralName", "saniyə" },
+ { "WeekPattern", "%n %u" },
+ { "WeekFuturePrefix", "" },
+ { "WeekFutureSuffix", " sonra" },
+ { "WeekPastPrefix", "" },
+ { "WeekPastSuffix", " əvvəl" },
+ { "WeekSingularName", "həftə" },
+ { "WeekPluralName", "həftə" },
+ { "YearPattern", "%n %u" },
+ { "YearFuturePrefix", "" },
+ { "YearFutureSuffix", " sonra" },
+ { "YearPastPrefix", "" },
+ { "YearPastSuffix", " əvvəl" },
+ { "YearSingularName", "il" },
+ { "YearPluralName", "il" },
+ { "AbstractTimeUnitPattern", "" },
+ { "AbstractTimeUnitFuturePrefix", "" },
+ { "AbstractTimeUnitFutureSuffix", "" },
+ { "AbstractTimeUnitPastPrefix", "" },
+ { "AbstractTimeUnitPastSuffix", "" },
+ { "AbstractTimeUnitSingularName", "" },
+ { "AbstractTimeUnitPluralName", "" } };
+
+ @Override
+ public Object[][] getContents()
+ {
+ return OBJECTS;
+ }
+
+}
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/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..30278080
--- /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_bn 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;
+ }
+}
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..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;
}
@@ -263,7 +259,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 +279,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_de.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_de.java
index 2ae2c7fb..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
@@ -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,173 @@
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;
-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);
+ }
+
+ 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"));
+
+ 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"));
+ 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)
+ {
+ return super.decorate(duration, adjustGrammar(time));
+ }
- };
+ @Override
+ public String decorateUnrounded(Duration duration, String time)
+ {
+ return super.decorateUnrounded(duration, adjustGrammar(time));
+ }
- @Override
- protected Object[][] getContents()
- {
- return OBJECTS;
- }
+ 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)));
+ }
+ matcher.appendTail(sb);
+ return sb.toString();
+ }
+ }
}
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..6203bdd0
--- /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/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/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", "" },
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_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_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;
+ }
+}
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", " बाद" },
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..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;
@@ -37,263 +38,285 @@
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)
+ {
+ names.add(new HrName(isFuture, Objects.requireNonNull(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 539da9e5..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,9 +1,9 @@
package org.ocpsoft.prettytime.i18n;
import java.util.ListResourceBundle;
+import java.util.Map;
import java.util.ResourceBundle;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
import org.ocpsoft.prettytime.Duration;
import org.ocpsoft.prettytime.TimeFormat;
@@ -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
@@ -132,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 = "";
@@ -150,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"));
@@ -164,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)
@@ -201,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);
}
@@ -221,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());
@@ -326,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_ms.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.java
new file mode 100644
index 00000000..79fc13f1
--- /dev/null
+++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ms.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_ms extends ListResourceBundle
+{
+
+ 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", "kemudian" },
+ { "MillenniumPastPrefix", "" },
+ { "MillenniumPastSuffix", "yang lalu" },
+ { "MillenniumSingularName", "millennium" },
+ { "MillenniumPluralName", "millennium" },
+ { "MillisecondPattern", "%n %u" },
+ { "MillisecondFuturePrefix", "" },
+ { "MillisecondFutureSuffix", "kemudian" },
+ { "MillisecondPastPrefix", "" },
+ { "MillisecondPastSuffix", "yang lalu" },
+ { "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", "kemudian" },
+ { "SecondPastPrefix", "" },
+ { "SecondPastSuffix", "yang lalu" },
+ { "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;
+ }
+}
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
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/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", "" },
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..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
@@ -6,6 +6,7 @@
import org.ocpsoft.prettytime.impl.TimeFormatProvider;
import org.ocpsoft.prettytime.units.*;
+import java.util.Arrays;
import java.util.ListResourceBundle;
/**
@@ -18,87 +19,91 @@ 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);
- StringBuilder result = new StringBuilder();
- result.append(quantity);
- return result.toString();
- }
-
- @Override
- public String formatUnrounded(Duration duration)
- {
- long quantity = duration.getQuantity();
- StringBuilder result = new StringBuilder();
- result.append(quantity);
- return result.toString();
- }
-
- @Override
- public String decorate(Duration duration, String time)
- {
- return performDecoration(
- duration.isInPast(),
- duration.isInFuture(),
- duration.getQuantityRounded(tolerance),
- time);
+ public String format(Duration duration) {
+ long roundedQuantity = Math.abs(duration.getQuantityRounded(tolerance));
+ return performFormat(roundedQuantity, true);
}
@Override
- public String decorateUnrounded(Duration duration, String time)
- {
- return performDecoration(
- duration.isInPast(),
- duration.isInFuture(),
- duration.getQuantity(),
- time);
+ public String formatUnrounded(Duration duration) {
+ long unroundedQuantity = Math.abs(duration.getQuantity());
+ return performFormat(unroundedQuantity, true);
}
- private String performDecoration(boolean past, boolean future, long n, String time)
- {
+ public String performFormat(long n, boolean isDuration) {
// 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 > russianPluralForms) {
// impossible happening
throw new IllegalStateException("Wrong plural index was calculated somehow for russian language");
}
- StringBuilder result = new StringBuilder();
+ String result = String.valueOf(n) +
+ ' ' +
+ 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)) {
+ long roundedQuantity = Math.abs(duration.getQuantityRounded(tolerance));
+ return performDecoration(duration, performFormat(roundedQuantity, false));
+ }
+ return performDecoration(duration, time);
+ }
- if (past) {
- result.append(" назад");
+ @Override
+ public String decorateUnrounded(Duration duration, String time) {
+ if(requiresReformatting(duration, false)) {
+ long unroundedQuantity = Math.abs(duration.getQuantity());
+ return performDecoration(duration, performFormat(unroundedQuantity, 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()
{
@@ -133,6 +138,8 @@ private String performFormat(Duration duration)
return null;
}
+
+
@Override
public String decorate(Duration duration, String time)
{
@@ -147,37 +154,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/main/java/org/ocpsoft/prettytime/i18n/Resources_sk.java b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_sk.java
index 134cfe5a..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;
}
@@ -263,7 +261,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 +281,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_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/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..6af63cdf
--- /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_so 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", " kahor" },
+ { "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;
+ }
+
+}
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..7f790abf
--- /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_sq 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/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;
+ }
+
+}
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;
+ }
+}
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);
}
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..81ee329b
--- /dev/null
+++ b/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ur.java
@@ -0,0 +1,123 @@
+/*
+ * 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_ur 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;
+ }
+
+}
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..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
@@ -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" },
@@ -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" },
@@ -118,4 +118,4 @@ public Object[][] getContents()
return OBJECTS;
}
-}
\ No newline at end of file
+}
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/ResourcesTimeFormat.java b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java
index 2e8a0106..48488b05 100644
--- a/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java
+++ b/core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeFormat.java
@@ -1,21 +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
{
- private ResourceBundle bundle;
private final ResourcesTimeUnit unit;
private TimeFormat override;
private String overrideResourceBundle; // If used this bundle will override the included bundle
@@ -34,11 +32,13 @@ 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
bundle = ResourceBundle.getBundle(overrideResourceBundle, locale);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
// Throw away if the bundle doesn't contain this local
}
}
@@ -48,21 +48,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 +71,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) {
+ }
}
@@ -117,4 +117,4 @@ public String formatUnrounded(Duration duration)
{
return override == null ? super.formatUnrounded(duration) : override.formatUnrounded(duration);
}
-}
\ No newline at end of file
+}
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..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,15 +22,25 @@
*/
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 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";
}
@@ -74,8 +84,7 @@ 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(id);
return result;
}
@@ -91,8 +100,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;
}
}
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/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/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/main/resources/META-INF/proguard/prettytime.pro b/core/src/main/resources/META-INF/proguard/prettytime.pro
new file mode 100644
index 00000000..07c96803
--- /dev/null
+++ b/core/src/main/resources/META-INF/proguard/prettytime.pro
@@ -0,0 +1,2 @@
+-keep class org.ocpsoft.prettytime.i18n**
+-keep public class * implements org.ocpsoft.prettytime.TimeUnit
diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java
index 68430272..80a21ed1 100644
--- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java
+++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeAPIManipulationTest.java
@@ -18,6 +18,12 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+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;
@@ -30,16 +36,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(null));
+ Assert.assertEquals(t.approximateDuration((LocalDateTime) null),
+ t.approximateDuration((LocalDateTime) null));
}
@Test
public void testApiMisuse2() throws Exception
{
- Assert.assertEquals(t.calculatePreciseDuration(new Date()), t.calculatePreciseDuration(null));
+ Assert.assertEquals(t.calculatePreciseDuration(LocalDateTime.now()),
+ t.calculatePreciseDuration((LocalDateTime) null));
}
@Test
@@ -51,49 +65,151 @@ 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(LocalDateTime.now().plusSeconds(1)), t.format((Instant) null));
+ }
+
+ @Test
+ public void testApiMisuse4_5() throws Exception
+ {
+ Assert.assertEquals(t.format(LocalDateTime.now().plusSeconds(1)), t.format((ZonedDateTime) null));
+ }
+
+ @Test
+ public void testApiMisuse4_6() throws Exception
+ {
+ Assert.assertEquals(t.format(LocalDateTime.now().plusSeconds(1)), t.format((OffsetDateTime) null));
+ }
+
+ @Test
+ public void testApiMisuse4_7_1() throws Exception
+ {
+ Assert.assertEquals(t.format(LocalDateTime.now().plusSeconds(1)), 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(LocalDateTime.now().plusSeconds(1)), t.format((LocalDateTime) null));
+ }
+
+ @Test
+ public void testApiMisuse4_9_1() throws Exception
+ {
+ Assert.assertEquals(t.format(LocalDateTime.now().plusSeconds(1)), 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
{
- 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(LocalDateTime.now().plusSeconds(1)), t.formatUnrounded((Instant) null));
+ }
+
+ @Test
+ public void testApiMisuse5_5() throws Exception
+ {
+ Assert.assertEquals(t.formatUnrounded(LocalDateTime.now().plusSeconds(1)),
+ t.formatUnrounded((ZonedDateTime) null));
+ }
+
+ @Test
+ public void testApiMisuse5_6() throws Exception
+ {
+ Assert.assertEquals(t.formatUnrounded(LocalDateTime.now().plusSeconds(1)),
+ t.formatUnrounded((OffsetDateTime) null));
+ }
+
+ @Test
+ public void testApiMisuse5_7_1() throws Exception
+ {
+ Assert.assertEquals(t.formatUnrounded(LocalDateTime.now().plusSeconds(1)),
+ 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(LocalDateTime.now().plusSeconds(1)),
+ t.formatUnrounded((LocalDateTime) null));
+ }
+
+ @Test
+ public void testApiMisuse5_9_1() throws Exception
+ {
+ Assert.assertEquals(t.formatUnrounded(LocalDateTime.now().plusSeconds(1)),
+ t.formatUnrounded((LocalDate) null, null));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testApiMisuse5_9_2()
+ {
+ t.formatUnrounded(LocalDate.now(), null);
}
@Test
@@ -117,13 +233,25 @@ public void testApiMisuse11() throws Exception
@Test
public void testApiMisuse12() throws Exception
{
- t.getUnits();
+ t.getReferenceAsLegacyDate();
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testApiMisuse13() throws Exception
{
- t.registerUnit(null, null);
+ t.getUnits();
+ }
+
+ @Test(expected = NullPointerException.class)
+ 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
@@ -147,7 +275,7 @@ public void testApiMisuse17() throws Exception
@Test
public void testApiMisuse18() throws Exception
{
- Assert.assertNull(t.getUnit(null));
+ Assert.assertNull(t.getUnit((Class) null));
}
@Test
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..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
@@ -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
@@ -67,15 +68,16 @@ public void testCeilingInterval() throws Exception
@Test
public void testNullDate() throws Exception
{
- PrettyTime t = new PrettyTime(locale);
- Date date = null;
- assertEquals("straks", t.format(date));
+ 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()));
}
@@ -207,4 +209,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_DE_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_DE_Test.java
new file mode 100644
index 00000000..f699014d
--- /dev/null
+++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_DE_Test.java
@@ -0,0 +1,161 @@
+/*
+ * @author hertg
+ */
+package org.ocpsoft.prettytime;
+
+import static org.junit.Assert.assertEquals;
+
+import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
+import java.util.List;
+import java.util.Locale;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class PrettyTimeI18n_DE_Test
+{
+
+ private LocalDateTime base;
+ private PrettyTime prettyTime;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ 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(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(base.minus(5, Calendar.MILLISECOND)));
+ // assertEquals("1 Millisekunde", prettyTime.formatDuration(base.minus(1, Calendar.MILLISECOND)));
+ }
+
+ @Test
+ public void testGrammaticalCaseSeconds()
+ {
+ 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(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(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(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(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(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(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(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(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(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)));
+ }
+
+ @Test
+ public void testGrammaticalCasesForMultipleDurations()
+ {
+ 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));
+ }
+}
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..5b707e71
--- /dev/null
+++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_EL_Test.java
@@ -0,0 +1,230 @@
+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;
+import org.junit.Test;
+import org.ocpsoft.prettytime.impl.ResourcesTimeFormat;
+import org.ocpsoft.prettytime.units.Minute;
+
+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();
+ final String format = t.format((Date) null);
+ Assert.assertTrue("πριν από στιγμές".equals(format) || "στιγμές από τώρα".equals(format));
+ }
+
+ @Test
+ public void testRightNow() throws Exception
+ {
+ PrettyTime t = new PrettyTime();
+ Assert.assertEquals("στιγμές από τώρα", t.format(new Date()));
+ }
+
+ @Test
+ 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)));
+ Assert.assertEquals("Πριν από 2 ώρες 2 λεπτά", t.format(preciseDuration));
+ Assert.assertEquals("2 ώρες 2 λεπτά", t.formatDuration(preciseDuration));
+ Assert.assertEquals("στιγμές από τώρα", t.format(t.calculatePreciseDuration(now)));
+ }
+
+ @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);
+ }
+}
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..c053aeee
--- /dev/null
+++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_EO_Test.java
@@ -0,0 +1,468 @@
+/*
+ * 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.time.LocalDate;
+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
+ 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 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
+ 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);
+ }
+
+}
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_HE_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_HE_Test.java
index 453bcb75..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
@@ -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;
@@ -51,22 +52,19 @@ 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())));
}
@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 יום 9 שעות 19 דקות", t.format(durations));
+ Assert.assertEquals("1 מילניום 9 מאות 1 חודש 1 יום 9 שעות 19 דקות", t.formatDuration(durations));
}
@Test
@@ -77,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
@@ -206,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()
{
@@ -228,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));
@@ -272,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());
@@ -283,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());
@@ -302,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));
}
@@ -377,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
@@ -389,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
@@ -401,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
@@ -413,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
@@ -425,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
@@ -437,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_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_IW_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_IW_Test.java
index 8da2e196..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,17 +3,22 @@
*/
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;
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_IW_Test
{
SimpleDateFormat format = new SimpleDateFormat("dd/mm/yyyy");
@@ -30,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));
}
@@ -38,31 +43,29 @@ 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())));
}
@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 יום 9 שעות 19 דקות", t.format(durations));
+ Assert.assertEquals("1 מילניום 9 מאות 1 חודש 1 יום 9 שעות 19 דקות", t.formatDuration(durations));
}
@Test
@@ -73,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
@@ -202,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()
{
@@ -224,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));
@@ -268,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());
@@ -279,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());
@@ -298,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));
}
@@ -373,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
@@ -385,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
@@ -397,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
@@ -409,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
@@ -421,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
@@ -433,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_MS_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_MS_Test.java
new file mode 100644
index 00000000..2d4e8e2d
--- /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_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()));
+ }
+
+ @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);
+ }
+}
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/PrettyTimeI18n_PL_Test.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_PL_Test.java
new file mode 100644
index 00000000..75ec3f39
--- /dev/null
+++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_PL_Test.java
@@ -0,0 +1,328 @@
+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_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("za 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);
+ }
+}
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..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,62 +152,233 @@ 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
- 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)));
+ assertEquals("1 минута", t.formatDuration(new Date(0)));
+ assertEquals("1 минута", t.formatDuration(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)));
+ assertEquals("12 минут", t.formatDuration(new Date(0)));
+ assertEquals("12 минут", t.formatDuration(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)));
+ assertEquals("1 час", t.formatDuration(new Date(0)));
+ assertEquals("1 час", t.formatDurationUnrounded(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)));
+ assertEquals("3 часа", t.formatDuration(new Date(0)));
+ assertEquals("3 часа", t.formatDurationUnrounded(new Date(0)));
+ }
+
+ @Test
+ 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
+ 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
- public void testDaysAgo() throws Exception
+ 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
+ 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
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
+ 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
+ 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
- public void testMonthsAgo() throws Exception
+ 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
+ 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
- public void testYearsAgo() throws Exception
+ 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
+ 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
+ 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
+ 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 testDecadesAgo() throws Exception
+ 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
+ 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
- public void testCenturiesAgo() throws Exception
+ 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
+ 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
+ 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
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
new file mode 100644
index 00000000..d1055acc
--- /dev/null
+++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SO_Test.java
@@ -0,0 +1,503 @@
+/*
+ * 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_SO_Test
+{
+ private Locale locale;
+ private LocalDateTime now;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ locale = Locale.getDefault();
+ Locale.setDefault(new Locale("so", "SO"));
+ 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(now);
+ 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 kadib", 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 ilbiriqsi ... BILOW!", t.format(fiveTicks));
+ t.setReference(fiveTicks);
+ Assert.assertEquals("isburburintii waxay ahayd: 5 ilbiriqsi kahor...", t.format(now));
+ }
+
+ @Test
+ public void testYearsAgo() throws Exception
+ {
+ PrettyTime t = new PrettyTime(now);
+ Assert.assertEquals("3 sano 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 kahor", 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 kahor",
+ 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);
+ }
+
+}
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..8a7e3846
--- /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);
+ }
+
+ }
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_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_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);
+ }
+}
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..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
@@ -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
@@ -57,42 +57,42 @@ 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
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)));
}
@@ -143,42 +143,42 @@ 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
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 -- //
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..f726ad58
--- /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("momente nga 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 nga tani", 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);
+ }
+}
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
{
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 7c546679..b0ace507 100644
--- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java
+++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeTest.java
@@ -15,7 +15,9 @@
*/
package org.ocpsoft.prettytime;
-import java.text.SimpleDateFormat;
+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;
@@ -32,24 +34,22 @@
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
@@ -67,6 +67,16 @@ public void testRightNow() throws Exception
Assert.assertEquals("moments from now", 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("moments from now", formatted);
+ }
+
@Test
public void testCalculatePreciceDuration() throws Exception
{
@@ -75,19 +85,43 @@ 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().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 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 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
+ 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
@@ -97,71 +131,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)));
}
/*
@@ -170,65 +204,64 @@ 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));
- TimeUnit unit = new TimeUnit()
- {
+ PrettyTime t = new PrettyTime(now);
+ TimeUnit unit = new TimeUnit() {
@Override
public long getMaxQuantity()
{
@@ -255,45 +288,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).plusSeconds(1));
Assert.assertTrue(durations.size() >= 2);
Assert.assertEquals(5, durations.get(0).getQuantity());
Assert.assertEquals(10, durations.get(1).getQuantity());
@@ -303,8 +336,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).minusSeconds(1));
Assert.assertTrue(durations.size() >= 2);
Assert.assertEquals(-5, durations.get(0).getQuantity());
Assert.assertEquals(-10, durations.get(1).getQuantity());
@@ -313,27 +345,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));
}
/**
@@ -367,7 +399,10 @@ 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);
+
+ result = t.formatDuration(now.minusMinutes(10));
+ Assert.assertEquals("10 minutes", result);
}
@Test
@@ -377,7 +412,10 @@ 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);
+
+ result = t.formatDuration(now.minusMinutes(10).minusSeconds(40));
+ Assert.assertEquals("11 minutes", result);
}
@Test
@@ -387,7 +425,10 @@ 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);
+
+ result = t.formatDurationUnrounded(now.minusMinutes(10).minusSeconds(40));
+ Assert.assertEquals("10 minutes", result);
}
@Test
@@ -398,8 +439,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
@@ -410,8 +450,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
@@ -422,8 +461,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
@@ -435,7 +473,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
@@ -446,8 +484,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
@@ -458,8 +495,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
diff --git a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java
index 65df20c2..e7f77a59 100644
--- a/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java
+++ b/core/src/test/java/org/ocpsoft/prettytime/PrettyTimeUnitConfigurationTest.java
@@ -16,21 +16,18 @@
package org.ocpsoft.prettytime;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
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.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;
@@ -66,7 +63,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)));
}
@@ -80,6 +80,34 @@ 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)));
+ }
+
+ @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
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 b3ca6477..c80d7f0e 100644
--- a/core/src/test/java/org/ocpsoft/prettytime/SimpleTimeFormatTest.java
+++ b/core/src/test/java/org/ocpsoft/prettytime/SimpleTimeFormatTest.java
@@ -17,15 +17,13 @@
import static org.junit.Assert.assertEquals;
+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
@@ -49,6 +47,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 +65,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
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()));
- }
-
-}
diff --git a/jsf/pom.xml b/jsf/pom.xml
index 789f001a..a8fd18df 100644
--- a/jsf/pom.xml
+++ b/jsf/pom.xml
@@ -4,7 +4,7 @@
org.ocpsoft.prettytimeprettytime-parent
- 4.0.1-SNAPSHOT
+ 5.0.10-SNAPSHOT../pom.xml
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..4d9dd279 100644
--- a/jsf/src/main/java/org/ocpsoft/prettytime/jsf/PrettyTimeConverter.java
+++ b/jsf/src/main/java/org/ocpsoft/prettytime/jsf/PrettyTimeConverter.java
@@ -57,19 +57,13 @@ 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();
+ PrettyTime prettyTime;
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);
- }
+ prettyTime = PRETTY_TIME_LOCALE_MAP.computeIfAbsent(locale, PrettyTime::new);
}
return prettyTime.format((Date) value);
}
diff --git a/jstl/pom.xml b/jstl/pom.xml
index 74e23ad4..6b147196 100644
--- a/jstl/pom.xml
+++ b/jstl/pom.xml
@@ -3,7 +3,7 @@
prettytime-parentorg.ocpsoft.prettytime
- 4.0.1-SNAPSHOT
+ 5.0.10-SNAPSHOT../pom.xml
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"
diff --git a/nlp/pom.xml b/nlp/pom.xml
index 724bac8e..044e018f 100644
--- a/nlp/pom.xml
+++ b/nlp/pom.xml
@@ -3,7 +3,7 @@
prettytime-parentorg.ocpsoft.prettytime
- 4.0.1-SNAPSHOT
+ 5.0.10-SNAPSHOT../pom.xml
@@ -23,7 +23,7 @@
com.joestelmachnatty
- 0.10.1
+ 0.13antlr
@@ -62,6 +62,7 @@
com.joestelmach.**
+ org.slf4j.**edu.emory.**net.fortuna.**org.antlr.**
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..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;
@@ -143,11 +145,21 @@ else if (number < 100)
* Parse the given language and return a {@link List} with all discovered {@link Date} instances.
*/
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);
- List result = new ArrayList();
- List groups = parser.parse(language);
+ List result = new ArrayList<>();
+ List groups = parser.parse(language, referenceDate);
for (com.joestelmach.natty.DateGroup group : groups) {
result.addAll(group.getDates());
}
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..d2ee9471 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());
@@ -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));
+ }
}
diff --git a/pom.xml b/pom.xml
index 3b752f68..b988f346 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,14 +4,14 @@
org.ocpsoftocpsoft-parent
- 14
+ 15org.ocpsoft.prettytimeprettytime-parentpom
- 4.0.1-SNAPSHOT
+ 5.0.10-SNAPSHOTPrettyTime - ParentSocial style time-formatting utilities and web-framework integrations.
@@ -22,10 +22,12 @@
jsfjstlnlp
- samples
-
+ samples
+
+ 1.8
+ 1.8
UTF-8
@@ -46,8 +48,8 @@
scm:git:git://github.com/ocpsoft/prettytime.gitscm:git:git@github.com:ocpsoft/prettytime.githttp://github.com/ocpsoft/prettytime
- HEAD
-
+ HEAD
+
GitHub
@@ -66,62 +68,77 @@
Thomas Weitzeltweitzel@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.felixmaven-bundle-plugin2.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/pom.xml b/samples/jstl/pom.xml
index e2eed87d..a4e3ca16 100644
--- a/samples/jstl/pom.xml
+++ b/samples/jstl/pom.xml
@@ -3,7 +3,7 @@
prettytime-samplesorg.ocpsoft.prettytime
- 4.0.1-SNAPSHOT
+ 5.0.10-SNAPSHOT4.0.0
@@ -15,12 +15,12 @@
org.eclipse.jettyjetty-server
- 7.2.2.v20101205
+ 10.0.10org.eclipse.jettyjetty-webapp
- 7.2.2.v20101205
+ 9.4.35.v20201120
@@ -37,7 +37,7 @@
org.ocpsoft.prettytimeprettytime-integration-jstl
- 4.0.1-SNAPSHOT
+ 5.0.10-SNAPSHOT
@@ -66,4 +66,4 @@
-
\ No newline at end of file
+
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);
}
diff --git a/samples/pom.xml b/samples/pom.xml
index c1a2e2b9..96f55211 100644
--- a/samples/pom.xml
+++ b/samples/pom.xml
@@ -4,7 +4,7 @@
prettytime-parentorg.ocpsoft.prettytime
- 4.0.1-SNAPSHOT
+ 5.0.10-SNAPSHOT4.0.0