diff --git a/README.adoc b/README.adoc index ecec5b0..eb968c3 100644 --- a/README.adoc +++ b/README.adoc @@ -10,9 +10,34 @@ image:https://img.shields.io/github/license/heruan/humanize.svg[link=http://www. image:https://img.shields.io/maven-central/v/to.lova.humanize/humanize-time.svg[title=humanize-time] +Add the dependency to your `pom.xml`: + +[source,xml] +---- + + to.lova.humanize + humanize-time + 0.1.1 + +---- + +Use it in your code as simple as: + [source,java] ---- Temporal minutesAgo = ZonedDateTime.now().minus(5, ChronoUnit.MINUTES); String relative = HumanizeTime.fromNow(minutesAgo); // produces: "5 minutes ago" ---- + +By default it uses the locale provided by `Locale.getDefault()`, but you can request a different one or provide your own resolver: + +[source,java] +---- +Temporal minutesAgo = ZonedDateTime.now().minus(5, ChronoUnit.MINUTES); +Locale.setDefault(Locale.ITALIAN); +String italian = HumanizeTime.fromNow(temporal); +// produces: "5 minuti fa" +String english = HumanizeTime.fromNow(temporal, Locale.FRENCH); +// produces: "5 minutes" +---- diff --git a/humanize-time/pom.xml b/humanize-time/pom.xml index 53dc18c..d1272db 100644 --- a/humanize-time/pom.xml +++ b/humanize-time/pom.xml @@ -10,7 +10,7 @@ to.lova.humanize - 0.1.1 + 0.1.2 humanize-parent @@ -23,4 +23,4 @@ - \ No newline at end of file + diff --git a/humanize-time/src/main/resources/messages_fr.properties b/humanize-time/src/main/resources/messages_fr.properties new file mode 100644 index 0000000..31194a9 --- /dev/null +++ b/humanize-time/src/main/resources/messages_fr.properties @@ -0,0 +1,29 @@ +now=à présent +seconds.ago[one]=il y a un instant +seconds.ago[other]=il y a {0,number} secondes +minutes.ago[one]=il y'a une minute +minutes.ago[other]=il y a {0,number} minutes +hours.ago[one]=il y a une heure +hours.ago[other]=il y a {0,number} heures +days.ago[one]=il y a un jour +days.ago[other]=il y a {0,number} jours +weeks.ago[one]=il y a une semaine +weeks.ago[other]=il y a {0,number} semaines +months.ago[one]=il y a un mois +months.ago[other]=il y a {0,number} mois +years.ago[one]=il y a un an +years.ago[other]=il y a {0,number} ans +seconds.within[one]=dans une seconde +seconds.within[other]=dans les {0,number} secondes +minutes.within[one]=dans une minute +minutes.within[other]=dans les {0,number} minutes +hours.within[one]=dans une heure +hours.within[other]=dans les {0,number} heures +days.within[one]=en un jour +days.within[other]=dans le {0,number} jours +weeks.within[one]=dans une semaine +weeks.within[other]=dans les {0,number} semaines +months.within[one]=dans un mois +months.within[other]=dans les {0,number} mois +years.within[one]=dans l'année +years.within[other]=dans le {0,number} ans diff --git a/humanize-time/src/main/resources/messages_ja.properties b/humanize-time/src/main/resources/messages_ja.properties new file mode 100644 index 0000000..22acc3d --- /dev/null +++ b/humanize-time/src/main/resources/messages_ja.properties @@ -0,0 +1,29 @@ +now=今 +seconds.ago[one]=一秒前 +seconds.ago[other]={0,number}秒前 +minutes.ago[one]=一時間前 +minutes.ago[other]={0,number}時間前 +hours.ago[one]=一時間前 +hours.ago[other]={0,number}時間前 +days.ago[one]=一日前 +days.ago[other]={0,number}日前 +weeks.ago[one]=一週間前 +weeks.ago[other]={0,number}週間前 +months.ago[one]=一ヶ月前 +months.ago[other]={0,number}ヶ月前 +years.ago[other]=一年前 +years.ago[other]={0,number}年前 +seconds.within[one]=一秒以内 +seconds.within[other]={0,number}秒以内 +minutes.within[one]=一時間以内 +minutes.within[other]={0,number}時間以内 +hours.within[one]=一時間以内 +hours.within[other]={0,number}時間以内 +days.within[one]=一日以内 +days.within[other]={0,number}日以内 +weeks.within[one]=一週間以内 +weeks.within[other]={0,number}週間以内 +months.within[one]=一ヶ月以内 +months.within[other]={0,number}ヶ月以内 +years.within[other]=一年以内 +years.within[other]={0,number}年以内 diff --git a/humanize-time/src/test/java/to/lova/humanize/time/test/TimeUnitTest.java b/humanize-time/src/test/java/to/lova/humanize/time/test/TimeUnitTest.java index 53ece17..cd3426f 100644 --- a/humanize-time/src/test/java/to/lova/humanize/time/test/TimeUnitTest.java +++ b/humanize-time/src/test/java/to/lova/humanize/time/test/TimeUnitTest.java @@ -26,7 +26,9 @@ public class TimeUnitTest { - private static final Temporal NOW = ZonedDateTime.now(); + private static final String REFERENCE_TIME = "2007-12-03T10:15:30+01:00[Europe/Paris]"; + + private static final Temporal NOW = ZonedDateTime.parse(REFERENCE_TIME); @Test public void testStaticMethods() { diff --git a/pom.xml b/pom.xml index 743bdd1..80eaf3d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ to.lova.humanize humanize-parent - 0.1.1 + 0.1.2 pom