From 16006225bd5d5ce3abd8b34deef975e735ee99d2 Mon Sep 17 00:00:00 2001 From: Pedro Adame Vergara Date: Thu, 30 Apr 2015 13:59:03 +0200 Subject: [PATCH 01/18] Update messages.properties --- .../kevinsawicki/timeago/messages.properties | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties index 3a2d588..3236310 100644 --- a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties @@ -11,3 +11,17 @@ TimeAgo.SECONDS=less than a minute TimeAgo.SUFFIX_FROM_NOW=from now TimeAgo.YEAR=about a year TimeAgo.YEARS={0} years + +TimeAgo.HACE=Hace +TimeAgo.DIA=un día +TimeAgo.DIAS={0} daís +TimeAgo.HORA=aprox. una hora +TimeAgo.HORAS={0} horas +TimeAgo.MINUTO=aprox. un minuto +TimeAgo.MINUTOS={0} minutos +TimeAgo.MES=aprox. un mes +TimeAgo.MESES={0} meses +TimeAgo.SEGUNDOS=menos de un minuto +TimeAgo.SUFIJO_AHORA=desde ahora +TimeAgo.ANYO=aprox. un año +TimeAgo.ANYOS={0} años From 7f21bd5b3660f1c6e41350bf6cea1fc4e3d29854 Mon Sep 17 00:00:00 2001 From: Pedro Adame Vergara Date: Thu, 30 Apr 2015 14:05:32 +0200 Subject: [PATCH 02/18] Update TimeAgo.java --- .../github/kevinsawicki/timeago/TimeAgo.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java b/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java index 73d6496..2adf700 100644 --- a/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java @@ -66,6 +66,53 @@ public class TimeAgo { private String years = Messages.getString("TimeAgo.YEARS"); //$NON-NLS-1$ + public TimeAgo(String locale){ + + if(locale.equals("en"){ + initEnglish(); + }else if(locale.equals("es"){ + initSpanish(); + }else{ + throw new IllegalArgumentException("Locale must be equals tu 'es' or 'en'."); + } + } + + private void initEnglish(){ + prefixAgo = null; + prefixFromNow = null; + suffixAgo = Messages.getString("TimeAgo.AGO"); //$NON-NLS-1$ + suffixFromNow = Messages + .getString("TimeAgo.SUFFIX_FROM_NOW"); //$NON-NLS-1$ + seconds = Messages.getString("TimeAgo.SECONDS"); //$NON-NLS-1$ + minute = Messages.getString("TimeAgo.MINUTE"); //$NON-NLS-1$ + minutes = Messages.getString("TimeAgo.MINUTES"); //$NON-NLS-1$ + hour = Messages.getString("TimeAgo.HOUR"); //$NON-NLS-1$ + hours = Messages.getString("TimeAgo.HOURS"); //$NON-NLS-1$ + day = Messages.getString("TimeAgo.DAY"); //$NON-NLS-1$ + days = Messages.getString("TimeAgo.DAYS"); //$NON-NLS-1$ + month = Messages.getString("TimeAgo.MONTH"); //$NON-NLS-1$ + months = Messages.getString("TimeAgo.MONTHS"); //$NON-NLS-1$ + year = Messages.getString("TimeAgo.YEAR"); //$NON-NLS-1$ + years = Messages.getString("TimeAgo.YEARS"); //$NON-NLS-1$ + } + + private void initSpanish(){ + prefixAgo = Messages.getString("TimeAgo.HACE"); + prefixFromNow = Messages.getString("TimeAgo.PREFIJO_AHORA"); + suffixAgo = null; //$NON-NLS-1$ + suffixFromNow = null; //$NON-NLS-1$ + seconds = Messages.getString("TimeAgo.SEGUNDOS"); //$NON-NLS-1$ + minute = Messages.getString("TimeAgo.MINUTO"); //$NON-NLS-1$ + minutes = Messages.getString("TimeAgo.MINUTOS"); //$NON-NLS-1$ + hour = Messages.getString("TimeAgo.HORA"); //$NON-NLS-1$ + hours = Messages.getString("TimeAgo.HORAS"); //$NON-NLS-1$ + day = Messages.getString("TimeAgo.DIA"); //$NON-NLS-1$ + days = Messages.getString("TimeAgo.DIAS"); //$NON-NLS-1$ + month = Messages.getString("TimeAgo.MES"); //$NON-NLS-1$ + months = Messages.getString("TimeAgo.MESES"); //$NON-NLS-1$ + year = Messages.getString("TimeAgo.ANYO"); //$NON-NLS-1$ + years = Messages.getString("TimeAgo.ANYOS"); //$NON-NLS-1$ + } /** * Get time until specified date * From 430d2b1989edcc351de35cd2695e81e978ac2869 Mon Sep 17 00:00:00 2001 From: Pedro Adame Vergara Date: Thu, 30 Apr 2015 14:07:04 +0200 Subject: [PATCH 03/18] Update TimeAgo.java --- .../github/kevinsawicki/timeago/TimeAgo.java | 45 +++++++------------ 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java b/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java index 2adf700..0f474fc 100644 --- a/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java @@ -35,36 +35,21 @@ */ public class TimeAgo { - private String prefixAgo = null; - - private String prefixFromNow = null; - - private String suffixAgo = Messages.getString("TimeAgo.AGO"); //$NON-NLS-1$ - - private String suffixFromNow = Messages - .getString("TimeAgo.SUFFIX_FROM_NOW"); //$NON-NLS-1$ - - private String seconds = Messages.getString("TimeAgo.SECONDS"); //$NON-NLS-1$ - - private String minute = Messages.getString("TimeAgo.MINUTE"); //$NON-NLS-1$ - - private String minutes = Messages.getString("TimeAgo.MINUTES"); //$NON-NLS-1$ - - private String hour = Messages.getString("TimeAgo.HOUR"); //$NON-NLS-1$ - - private String hours = Messages.getString("TimeAgo.HOURS"); //$NON-NLS-1$ - - private String day = Messages.getString("TimeAgo.DAY"); //$NON-NLS-1$ - - private String days = Messages.getString("TimeAgo.DAYS"); //$NON-NLS-1$ - - private String month = Messages.getString("TimeAgo.MONTH"); //$NON-NLS-1$ - - private String months = Messages.getString("TimeAgo.MONTHS"); //$NON-NLS-1$ - - private String year = Messages.getString("TimeAgo.YEAR"); //$NON-NLS-1$ - - private String years = Messages.getString("TimeAgo.YEARS"); //$NON-NLS-1$ + private String prefixAgo; + private String prefixFromNow; + private String suffixAgo; + private String suffixFromNow; + private String seconds; + private String minute; + private String minutes; + private String hour; + private String hours; + private String day; + private String days; + private String month; + private String months; + private String year; + private String years; public TimeAgo(String locale){ From 13e26970a8b10f7f5dfc067262cea39024226b22 Mon Sep 17 00:00:00 2001 From: Pedro Adame Vergara Date: Thu, 30 Apr 2015 14:09:41 +0200 Subject: [PATCH 04/18] Update messages.properties --- .../java/com/github/kevinsawicki/timeago/messages.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties index 3236310..33144e4 100644 --- a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties @@ -13,6 +13,7 @@ TimeAgo.YEAR=about a year TimeAgo.YEARS={0} years TimeAgo.HACE=Hace +TimeAgo.PREFIJO_AHORA=Dentro de TimeAgo.DIA=un día TimeAgo.DIAS={0} daís TimeAgo.HORA=aprox. una hora @@ -22,6 +23,5 @@ TimeAgo.MINUTOS={0} minutos TimeAgo.MES=aprox. un mes TimeAgo.MESES={0} meses TimeAgo.SEGUNDOS=menos de un minuto -TimeAgo.SUFIJO_AHORA=desde ahora TimeAgo.ANYO=aprox. un año TimeAgo.ANYOS={0} años From f1d07c50fe0ff07405a549fee28ead7987f22a3e Mon Sep 17 00:00:00 2001 From: Pedro Adame Vergara Date: Thu, 30 Apr 2015 14:09:57 +0200 Subject: [PATCH 05/18] Update messages.properties --- .../java/com/github/kevinsawicki/timeago/messages.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties index 33144e4..7dc8413 100644 --- a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties @@ -15,7 +15,7 @@ TimeAgo.YEARS={0} years TimeAgo.HACE=Hace TimeAgo.PREFIJO_AHORA=Dentro de TimeAgo.DIA=un día -TimeAgo.DIAS={0} daís +TimeAgo.DIAS={0} días TimeAgo.HORA=aprox. una hora TimeAgo.HORAS={0} horas TimeAgo.MINUTO=aprox. un minuto From e136f2695cf7e9048756ff2eff64c0c2ef3fd29f Mon Sep 17 00:00:00 2001 From: Pedro Adame Vergara Date: Thu, 30 Apr 2015 14:10:56 +0200 Subject: [PATCH 06/18] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e26a74..2c9f412 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ To build and run the included unit tests: ##Usage ```java -TimeAgo time = new TimeAgo(); +TimeAgo time = new TimeAgo('en'); //For English text OR TimeAgo time = new TimeAgo('es' for Spanish text + long current = System.currentTimeMillis(); String minutes = time.timeAgo(current - (15 * 60 * 1000)); // returns "15 minutes ago" String hours = time.timeUntil(current - (6 * 60 * 60 * 1000)); // returns "6 hours from now" From 3b328af5bea95c76fc797e8531052d5a1231341d Mon Sep 17 00:00:00 2001 From: Pedro Adame Vergara Date: Thu, 30 Apr 2015 14:13:08 +0200 Subject: [PATCH 07/18] Update README.md --- README.md | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 2c9f412..0d04e0d 100644 --- a/README.md +++ b/README.md @@ -2,35 +2,19 @@ This is a Java port of the [jquery-timeago](https://github.com/rmm5t/jquery-timeago) plug-in. Please visit the [jquery-timeago](http://rmm5t.github.com/jquery-timeago/) project page to read more about fuzzy timestamps. -##Building - -The timeago project contains a [Maven](http://maven.apache.org/) pom.xml file that builds a jar containing the TimeAgo class. - -To build and run the included unit tests: - -```$ mvn clean install``` +##Importing the library +Use Jitpack.io ([check here](https://jitpack.io/#Kinnonii/java-timeago/timeago-1.1.0) ##Usage ```java -TimeAgo time = new TimeAgo('en'); //For English text OR TimeAgo time = new TimeAgo('es' for Spanish text +TimeAgo time = new TimeAgo('en'); //For English text OR TimeAgo time = new TimeAgo('es') for Spanish text long current = System.currentTimeMillis(); String minutes = time.timeAgo(current - (15 * 60 * 1000)); // returns "15 minutes ago" String hours = time.timeUntil(current - (6 * 60 * 60 * 1000)); // returns "6 hours from now" ``` -### Maven - -This library is available from [Maven Central](http://search.maven.org/#search%7Cga%7C1%7C%20a%3A%22timeago%22%20g%3A%22com.github.kevinsawicki%22). - -```xml - - com.github.kevinsawicki - timeago - 1.0.1 - -``` ##Contribution From 9f65ac80cbf7c0917a4d5ac12f8ec464ab158860 Mon Sep 17 00:00:00 2001 From: Pedro Adame Vergara Date: Thu, 30 Apr 2015 14:13:22 +0200 Subject: [PATCH 08/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d04e0d..1e9c2fc 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This is a Java port of the [jquery-timeago](https://github.com/rmm5t/jquery-timeago) plug-in. Please visit the [jquery-timeago](http://rmm5t.github.com/jquery-timeago/) project page to read more about fuzzy timestamps. ##Importing the library -Use Jitpack.io ([check here](https://jitpack.io/#Kinnonii/java-timeago/timeago-1.1.0) +Use Jitpack.io ([check here](https://jitpack.io/#Kinnonii/java-timeago/timeago-1.1.0)) ##Usage From ef61250de24f7c433d22447c4e0eb9ef01734e09 Mon Sep 17 00:00:00 2001 From: Pedro Adame Vergara Date: Thu, 30 Apr 2015 14:20:39 +0200 Subject: [PATCH 09/18] Update pom.xml --- timeago/pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/timeago/pom.xml b/timeago/pom.xml index 82bf5c1..22ffd23 100644 --- a/timeago/pom.xml +++ b/timeago/pom.xml @@ -8,9 +8,9 @@ - com.github.kevinsawicki + com.github.Kinnonii timeago - 1.0.2-SNAPSHOT + 1.1.0 Time Ago Simple Java library for converting dates to time ago strings. @@ -30,9 +30,9 @@ - https://github.com/kevinsawicki/java-timeago - scm:git:git://github.com/kevinsawicki/java-timeago.git - scm:git:git@github.com:kevinsawicki/java-timeago.git + https://github.com/kinnonii/java-timeago + scm:git:git://github.com/kinnonii/java-timeago.git + scm:git:git@github.com:kinnonii/java-timeago.git From 89adc632362e45f5a4e9474625d34d7c1440ba35 Mon Sep 17 00:00:00 2001 From: Pedro Adame Vergara Date: Thu, 30 Apr 2015 14:21:14 +0200 Subject: [PATCH 10/18] Update TimeAgo.java --- .../main/java/com/github/kevinsawicki/timeago/TimeAgo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java b/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java index 0f474fc..8d04329 100644 --- a/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java @@ -53,9 +53,9 @@ public class TimeAgo { public TimeAgo(String locale){ - if(locale.equals("en"){ + if(locale.equals("en")){ initEnglish(); - }else if(locale.equals("es"){ + }else if(locale.equals("es")){ initSpanish(); }else{ throw new IllegalArgumentException("Locale must be equals tu 'es' or 'en'."); From 6da0c2937d8b56f806c357a1c70ff74d627eb372 Mon Sep 17 00:00:00 2001 From: Pedro Adame Vergara Date: Thu, 30 Apr 2015 14:25:44 +0200 Subject: [PATCH 11/18] Delete TimeAgoTest.java --- .../timeago/tests/TimeAgoTest.java | 201 ------------------ 1 file changed, 201 deletions(-) delete mode 100644 timeago/src/test/java/com/github/kevinsawicki/timeago/tests/TimeAgoTest.java diff --git a/timeago/src/test/java/com/github/kevinsawicki/timeago/tests/TimeAgoTest.java b/timeago/src/test/java/com/github/kevinsawicki/timeago/tests/TimeAgoTest.java deleted file mode 100644 index 664a2ab..0000000 --- a/timeago/src/test/java/com/github/kevinsawicki/timeago/tests/TimeAgoTest.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 2011 Kevin Sawicki - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ -package com.github.kevinsawicki.timeago.tests; - -import com.github.kevinsawicki.timeago.TimeAgo; - -import java.text.MessageFormat; - -import junit.framework.TestCase; - -/** - * - * Unit tests of {@link TimeAgo} - */ -public class TimeAgoTest extends TestCase { - - /** - * One second in milliseconds - */ - public static final long SECOND = 1000; - - /** - * One minute in milliseconds - */ - public static final long MINUTE = 60 * SECOND; - - /** - * One hour in milliseconds - */ - public static final long HOUR = 60 * MINUTE; - - /** - * One day in milliseconds - */ - public static final long DAY = 24 * HOUR; - - /** - * 30 days in milliseconds - */ - public static final long MONTH = 30 * DAY; - - /** - * 365 days in milliseconds - */ - public static final long YEAR = 365 * DAY; - - private long ago(long offset) { - return System.currentTimeMillis() - offset; - } - - /** - * Test seconds ago - */ - public void testAgoSeconds() { - TimeAgo ago = new TimeAgo(); - String time = ago.timeAgo(System.currentTimeMillis()); - String expected = ago.join(ago.getPrefixAgo(), ago.getSeconds(), - ago.getSuffixAgo()); - assertEquals(expected, time); - } - - /** - * Test minute ago - */ - public void testAgoMinute() { - TimeAgo ago = new TimeAgo(); - String time = ago.timeAgo(ago(MINUTE)); - String expected = ago.join(ago.getPrefixAgo(), ago.getMinute(), - ago.getSuffixAgo()); - assertEquals(expected, time); - } - - /** - * Test minutes ago - */ - public void testAgoMinutes() { - TimeAgo ago = new TimeAgo(); - int minutes = 2; - String time = ago.timeAgo(ago(minutes * MINUTE)); - String expected = ago.join(ago.getPrefixAgo(), - MessageFormat.format(ago.getMinutes(), minutes), - ago.getSuffixAgo()); - assertEquals(expected, time); - } - - /** - * Test hour ago - */ - public void testAgoHour() { - TimeAgo ago = new TimeAgo(); - String time = ago.timeAgo(ago(HOUR)); - String expected = ago.join(ago.getPrefixAgo(), ago.getHour(), - ago.getSuffixAgo()); - assertEquals(expected, time); - } - - /** - * Test hours ago - */ - public void testAgoHours() { - TimeAgo ago = new TimeAgo(); - long hours = 3; - String time = ago.timeAgo(ago(hours * HOUR)); - String expected = ago - .join(ago.getPrefixAgo(), - MessageFormat.format(ago.getHours(), hours), - ago.getSuffixAgo()); - assertEquals(expected, time); - } - - /** - * Test day ago - */ - public void testAgoDay() { - TimeAgo ago = new TimeAgo(); - String time = ago.timeAgo(ago(30 * HOUR)); - String expected = ago.join(ago.getPrefixAgo(), ago.getDay(), - ago.getSuffixAgo()); - assertEquals(expected, time); - } - - /** - * Test day ago - */ - public void testAgoDays() { - TimeAgo ago = new TimeAgo(); - long days = 4; - String time = ago.timeAgo(ago(days * DAY)); - String expected = ago.join(ago.getPrefixAgo(), - MessageFormat.format(ago.getDays(), days), ago.getSuffixAgo()); - assertEquals(expected, time); - } - - /** - * Test month ago - */ - public void testAgoMonth() { - TimeAgo ago = new TimeAgo(); - String time = ago.timeAgo(ago(35 * DAY)); - String expected = ago.join(ago.getPrefixAgo(), ago.getMonth(), - ago.getSuffixAgo()); - assertEquals(expected, time); - } - - /** - * Test months ago - */ - public void testAgoMonths() { - TimeAgo ago = new TimeAgo(); - long months = 2; - String time = ago.timeAgo(ago(months * MONTH)); - String expected = ago.join(ago.getPrefixAgo(), - MessageFormat.format(ago.getMonths(), months), - ago.getSuffixAgo()); - assertEquals(expected, time); - } - - /** - * Test year ago - */ - public void testYearAgo() { - TimeAgo ago = new TimeAgo(); - String time = ago.timeAgo(System.currentTimeMillis() - (14 * MONTH)); - String expected = ago.join(ago.getPrefixAgo(), ago.getYear(), - ago.getSuffixAgo()); - assertEquals(expected, time); - } - - /** - * Test year ago - */ - public void testYearsAgo() { - TimeAgo ago = new TimeAgo(); - long years = 7; - String time = ago.timeAgo(System.currentTimeMillis() - (years * YEAR)); - String expected = ago - .join(ago.getPrefixAgo(), - MessageFormat.format(ago.getYears(), years), - ago.getSuffixAgo()); - assertEquals(expected, time); - } -} From e063b925ad35ff535396f7cbca550e03a1864d88 Mon Sep 17 00:00:00 2001 From: federico Date: Tue, 5 May 2015 09:47:31 +0200 Subject: [PATCH 12/18] Added italian language - modified TimeAgo class init method - added test class --- .../github/kevinsawicki/timeago/TimeAgo.java | 62 ++---- .../kevinsawicki/timeago/messages.properties | 75 ++++--- .../timeago/tests/TimeAgoTest.java | 205 ++++++++++++++++++ 3 files changed, 277 insertions(+), 65 deletions(-) create mode 100644 timeago/src/main/java/com/github/kevinsawicki/timeago/tests/TimeAgoTest.java diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java b/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java index 8d04329..d45c5db 100644 --- a/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java @@ -52,52 +52,36 @@ public class TimeAgo { private String years; public TimeAgo(String locale){ - + if(locale.equals("en")){ - initEnglish(); + initLanguage("EN"); }else if(locale.equals("es")){ - initSpanish(); + initLanguage("ES"); + }else if(locale.equals("it")){ + initLanguage("IT"); }else{ throw new IllegalArgumentException("Locale must be equals tu 'es' or 'en'."); } } - - private void initEnglish(){ - prefixAgo = null; - prefixFromNow = null; - suffixAgo = Messages.getString("TimeAgo.AGO"); //$NON-NLS-1$ - suffixFromNow = Messages - .getString("TimeAgo.SUFFIX_FROM_NOW"); //$NON-NLS-1$ - seconds = Messages.getString("TimeAgo.SECONDS"); //$NON-NLS-1$ - minute = Messages.getString("TimeAgo.MINUTE"); //$NON-NLS-1$ - minutes = Messages.getString("TimeAgo.MINUTES"); //$NON-NLS-1$ - hour = Messages.getString("TimeAgo.HOUR"); //$NON-NLS-1$ - hours = Messages.getString("TimeAgo.HOURS"); //$NON-NLS-1$ - day = Messages.getString("TimeAgo.DAY"); //$NON-NLS-1$ - days = Messages.getString("TimeAgo.DAYS"); //$NON-NLS-1$ - month = Messages.getString("TimeAgo.MONTH"); //$NON-NLS-1$ - months = Messages.getString("TimeAgo.MONTHS"); //$NON-NLS-1$ - year = Messages.getString("TimeAgo.YEAR"); //$NON-NLS-1$ - years = Messages.getString("TimeAgo.YEARS"); //$NON-NLS-1$ - } - - private void initSpanish(){ - prefixAgo = Messages.getString("TimeAgo.HACE"); - prefixFromNow = Messages.getString("TimeAgo.PREFIJO_AHORA"); - suffixAgo = null; //$NON-NLS-1$ - suffixFromNow = null; //$NON-NLS-1$ - seconds = Messages.getString("TimeAgo.SEGUNDOS"); //$NON-NLS-1$ - minute = Messages.getString("TimeAgo.MINUTO"); //$NON-NLS-1$ - minutes = Messages.getString("TimeAgo.MINUTOS"); //$NON-NLS-1$ - hour = Messages.getString("TimeAgo.HORA"); //$NON-NLS-1$ - hours = Messages.getString("TimeAgo.HORAS"); //$NON-NLS-1$ - day = Messages.getString("TimeAgo.DIA"); //$NON-NLS-1$ - days = Messages.getString("TimeAgo.DIAS"); //$NON-NLS-1$ - month = Messages.getString("TimeAgo.MES"); //$NON-NLS-1$ - months = Messages.getString("TimeAgo.MESES"); //$NON-NLS-1$ - year = Messages.getString("TimeAgo.ANYO"); //$NON-NLS-1$ - years = Messages.getString("TimeAgo.ANYOS"); //$NON-NLS-1$ + + private void initLanguage(String language) { + prefixAgo = Messages.getString("TimeAgo.PREFIX_AGO" + "_" + language); //$NON-NLS-1$ + suffixAgo = Messages.getString("TimeAgo.SUFFIX_AGO" + "_" + language); //$NON-NLS-1$ + prefixFromNow = Messages.getString("TimeAgo.PREFIX_FROM_NOW" + "_" + language); //$NON-NLS-1$ + suffixFromNow = Messages.getString("TimeAgo.SUFFIX_FROM_NOW" + "_" + language); //$NON-NLS-1$ + seconds = Messages.getString("TimeAgo.SECONDS" + "_" + language); //$NON-NLS-1$ + minute = Messages.getString("TimeAgo.MINUTE" + "_" + language); //$NON-NLS-1$ + minutes = Messages.getString("TimeAgo.MINUTES" + "_" + language); //$NON-NLS-1$ + hour = Messages.getString("TimeAgo.HOUR" + "_" + language); //$NON-NLS-1$ + hours = Messages.getString("TimeAgo.HOURS" + "_" + language); //$NON-NLS-1$ + day = Messages.getString("TimeAgo.DAY" + "_" + language); //$NON-NLS-1$ + days = Messages.getString("TimeAgo.DAYS" + "_" + language); //$NON-NLS-1$ + month = Messages.getString("TimeAgo.MONTH" + "_" + language); //$NON-NLS-1$ + months = Messages.getString("TimeAgo.MONTHS" + "_" + language); //$NON-NLS-1$ + year = Messages.getString("TimeAgo.YEAR" + "_" + language); //$NON-NLS-1$ + years = Messages.getString("TimeAgo.YEARS" + "_" + language); //$NON-NLS-1$ } + /** * Get time until specified date * diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties index 7dc8413..0367987 100644 --- a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties @@ -1,27 +1,50 @@ -TimeAgo.AGO=ago -TimeAgo.DAY=a day -TimeAgo.DAYS={0} days -TimeAgo.HOUR=about an hour -TimeAgo.HOURS={0} hours -TimeAgo.MINUTE=about a minute -TimeAgo.MINUTES={0} minutes -TimeAgo.MONTH=about a month -TimeAgo.MONTHS={0} months -TimeAgo.SECONDS=less than a minute -TimeAgo.SUFFIX_FROM_NOW=from now -TimeAgo.YEAR=about a year -TimeAgo.YEARS={0} years +#en +TimeAgo.PREFIX_AGO_EN= +TimeAgo.SUFFIX_AGO_EN=ago +TimeAgo.PREFIX_FROM_NOW_EN= +TimeAgo.SUFFIX_FROM_NOW_EN=from now +TimeAgo.DAY_EN=a day +TimeAgo.DAYS_EN={0} days +TimeAgo.HOUR_EN=about an hour +TimeAgo.HOURS_EN={0} hours +TimeAgo.MINUTE_EN=about a minute +TimeAgo.MINUTES_EN={0} minutes +TimeAgo.MONTH_EN=about a month +TimeAgo.MONTHS_EN={0} months +TimeAgo.SECONDS_EN=less than a minute +TimeAgo.YEAR_EN=about a year +TimeAgo.YEARS_EN={0} years -TimeAgo.HACE=Hace -TimeAgo.PREFIJO_AHORA=Dentro de -TimeAgo.DIA=un día -TimeAgo.DIAS={0} días -TimeAgo.HORA=aprox. una hora -TimeAgo.HORAS={0} horas -TimeAgo.MINUTO=aprox. un minuto -TimeAgo.MINUTOS={0} minutos -TimeAgo.MES=aprox. un mes -TimeAgo.MESES={0} meses -TimeAgo.SEGUNDOS=menos de un minuto -TimeAgo.ANYO=aprox. un año -TimeAgo.ANYOS={0} años +#en +TimeAgo.PREFIX_AGO_ES=Hace +TimeAgo.SUFFIX_AGO_EN= +TimeAgo.PREFIX_FROM_NOW_ES=Dentro de +TimeAgo.SUFFIX_FROM_NOW_ES= +TimeAgo.DAY_ES=un día +TimeAgo.DAYS_ES={0} días +TimeAgo.HOUR_ES=aprox. una hora +TimeAgo.HOURS_ES={0} horas +TimeAgo.MINUTE_ES=aprox. un minuto +TimeAgo.MINUTES_ES={0} minutos +TimeAgo.MONTH_ES=aprox. un mes +TimeAgo.MONTHS_ES={0} meses +TimeAgo.SECONDS_ES=menos de un minuto +TimeAgo.YEAR_ES=aprox. un año +TimeAgo.YEARS_ES={0} años + +# it +TimeAgo.PREFIX_AGO_IT= +TimeAgo.SUFFIX_AGO_IT=fa +TimeAgo.PREFIX_FROM_NOW_IT= +TimeAgo.SUFFIX_FROM_NOW_IT=adesso +TimeAgo.DAY_IT=un giorno +TimeAgo.DAYS_IT={0} giorni +TimeAgo.HOUR_IT=circa un'ora +TimeAgo.HOURS_IT={0} ore +TimeAgo.MINUTE_IT=circa un minuto +TimeAgo.MINUTES_IT={0} minuti +TimeAgo.MONTH_IT=circa un mese +TimeAgo.MONTHS_IT={0} mesi +TimeAgo.SECONDS_IT=meno di un minuti +TimeAgo.YEAR_IT=circa un anno +TimeAgo.YEARS_IT={0} anni diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/tests/TimeAgoTest.java b/timeago/src/main/java/com/github/kevinsawicki/timeago/tests/TimeAgoTest.java new file mode 100644 index 0000000..128dc2f --- /dev/null +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/tests/TimeAgoTest.java @@ -0,0 +1,205 @@ +package com.github.kevinsawicki.timeago.tests; +/* + * Copyright (c) 2011 Kevin Sawicki + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ +import com.github.kevinsawicki.timeago.TimeAgo; + +import java.text.MessageFormat; + +import junit.framework.TestCase; + +/** + * + * Unit tests of {@link TimeAgo} + */ +public class TimeAgoTest extends TestCase { + + /** + * One second in milliseconds + */ + public static final long SECOND = 1000; + + /** + * One minute in milliseconds + */ + public static final long MINUTE = 60 * SECOND; + + /** + * One hour in milliseconds + */ + public static final long HOUR = 60 * MINUTE; + + /** + * One day in milliseconds + */ + public static final long DAY = 24 * HOUR; + + /** + * 30 days in milliseconds + */ + public static final long MONTH = 30 * DAY; + + /** + * 365 days in milliseconds + */ + public static final long YEAR = 365 * DAY; + + /** + * Locale for test + */ + private static final String locale = "it"; + + private long ago(long offset) { + return System.currentTimeMillis() - offset; + } + + /** + * Test seconds ago + */ + public void testAgoSeconds() { + TimeAgo ago = new TimeAgo(locale); + String time = ago.timeAgo(System.currentTimeMillis()); + String expected = ago.join(ago.getPrefixAgo(), ago.getSeconds(), + ago.getSuffixAgo()); + assertEquals(expected, time); + } + + /** + * Test minute ago + */ + public void testAgoMinute() { + TimeAgo ago = new TimeAgo(locale); + String time = ago.timeAgo(ago(MINUTE)); + String expected = ago.join(ago.getPrefixAgo(), ago.getMinute(), + ago.getSuffixAgo()); + assertEquals(expected, time); + } + + /** + * Test minutes ago + */ + public void testAgoMinutes() { + TimeAgo ago = new TimeAgo(locale); + int minutes = 2; + String time = ago.timeAgo(ago(minutes * MINUTE)); + String expected = ago.join(ago.getPrefixAgo(), + MessageFormat.format(ago.getMinutes(), minutes), + ago.getSuffixAgo()); + assertEquals(expected, time); + } + + /** + * Test hour ago + */ + public void testAgoHour() { + TimeAgo ago = new TimeAgo(locale); + String time = ago.timeAgo(ago(HOUR)); + String expected = ago.join(ago.getPrefixAgo(), ago.getHour(), + ago.getSuffixAgo()); + assertEquals(expected, time); + } + + /** + * Test hours ago + */ + public void testAgoHours() { + TimeAgo ago = new TimeAgo(locale); + long hours = 3; + String time = ago.timeAgo(ago(hours * HOUR)); + String expected = ago + .join(ago.getPrefixAgo(), + MessageFormat.format(ago.getHours(), hours), + ago.getSuffixAgo()); + assertEquals(expected, time); + } + + /** + * Test day ago + */ + public void testAgoDay() { + TimeAgo ago = new TimeAgo(locale); + String time = ago.timeAgo(ago(30 * HOUR)); + String expected = ago.join(ago.getPrefixAgo(), ago.getDay(), + ago.getSuffixAgo()); + assertEquals(expected, time); + } + + /** + * Test day ago + */ + public void testAgoDays() { + TimeAgo ago = new TimeAgo(locale); + long days = 4; + String time = ago.timeAgo(ago(days * DAY)); + String expected = ago.join(ago.getPrefixAgo(), + MessageFormat.format(ago.getDays(), days), ago.getSuffixAgo()); + assertEquals(expected, time); + } + + /** + * Test month ago + */ + public void testAgoMonth() { + TimeAgo ago = new TimeAgo(locale); + String time = ago.timeAgo(ago(35 * DAY)); + String expected = ago.join(ago.getPrefixAgo(), ago.getMonth(), + ago.getSuffixAgo()); + assertEquals(expected, time); + } + + /** + * Test months ago + */ + public void testAgoMonths() { + TimeAgo ago = new TimeAgo(locale); + long months = 2; + String time = ago.timeAgo(ago(months * MONTH)); + String expected = ago.join(ago.getPrefixAgo(), + MessageFormat.format(ago.getMonths(), months), + ago.getSuffixAgo()); + assertEquals(expected, time); + } + + /** + * Test year ago + */ + public void testYearAgo() { + TimeAgo ago = new TimeAgo(locale); + String time = ago.timeAgo(System.currentTimeMillis() - (14 * MONTH)); + String expected = ago.join(ago.getPrefixAgo(), ago.getYear(), + ago.getSuffixAgo()); + assertEquals(expected, time); + } + + /** + * Test year ago + */ + public void testYearsAgo() { + TimeAgo ago = new TimeAgo(locale); + long years = 7; + String time = ago.timeAgo(System.currentTimeMillis() - (years * YEAR)); + String expected = ago + .join(ago.getPrefixAgo(), + MessageFormat.format(ago.getYears(), years), + ago.getSuffixAgo()); + assertEquals(expected, time); + } +} \ No newline at end of file From 632700fb0fb8d0ee457be6098a4364c0595be9c0 Mon Sep 17 00:00:00 2001 From: Federico Date: Sat, 9 May 2015 18:39:37 +0200 Subject: [PATCH 13/18] modified package structure - locale from system --- .../github/kevinsawicki/timeago/Messages.java | 2 +- .../github/kevinsawicki/timeago/TimeAgo.java | 76 ++++++++----------- .../kevinsawicki/timeago/messages.properties | 64 ++++------------ .../timeago/tests/TimeAgoTest.java | 30 ++++---- 4 files changed, 59 insertions(+), 113 deletions(-) rename timeago/src/{main => test}/java/com/github/kevinsawicki/timeago/tests/TimeAgoTest.java (91%) diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/Messages.java b/timeago/src/main/java/com/github/kevinsawicki/timeago/Messages.java index cbd26af..d1a9c0f 100644 --- a/timeago/src/main/java/com/github/kevinsawicki/timeago/Messages.java +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/Messages.java @@ -50,4 +50,4 @@ public static String getString(String key) { return '!' + key + '!'; } } -} +} \ No newline at end of file diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java b/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java index d45c5db..5124433 100644 --- a/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/TimeAgo.java @@ -35,52 +35,36 @@ */ public class TimeAgo { - private String prefixAgo; - private String prefixFromNow; - private String suffixAgo; - private String suffixFromNow; - private String seconds; - private String minute; - private String minutes; - private String hour; - private String hours; - private String day; - private String days; - private String month; - private String months; - private String year; - private String years; - - public TimeAgo(String locale){ - - if(locale.equals("en")){ - initLanguage("EN"); - }else if(locale.equals("es")){ - initLanguage("ES"); - }else if(locale.equals("it")){ - initLanguage("IT"); - }else{ - throw new IllegalArgumentException("Locale must be equals tu 'es' or 'en'."); - } - } + private String prefixAgo = null; - private void initLanguage(String language) { - prefixAgo = Messages.getString("TimeAgo.PREFIX_AGO" + "_" + language); //$NON-NLS-1$ - suffixAgo = Messages.getString("TimeAgo.SUFFIX_AGO" + "_" + language); //$NON-NLS-1$ - prefixFromNow = Messages.getString("TimeAgo.PREFIX_FROM_NOW" + "_" + language); //$NON-NLS-1$ - suffixFromNow = Messages.getString("TimeAgo.SUFFIX_FROM_NOW" + "_" + language); //$NON-NLS-1$ - seconds = Messages.getString("TimeAgo.SECONDS" + "_" + language); //$NON-NLS-1$ - minute = Messages.getString("TimeAgo.MINUTE" + "_" + language); //$NON-NLS-1$ - minutes = Messages.getString("TimeAgo.MINUTES" + "_" + language); //$NON-NLS-1$ - hour = Messages.getString("TimeAgo.HOUR" + "_" + language); //$NON-NLS-1$ - hours = Messages.getString("TimeAgo.HOURS" + "_" + language); //$NON-NLS-1$ - day = Messages.getString("TimeAgo.DAY" + "_" + language); //$NON-NLS-1$ - days = Messages.getString("TimeAgo.DAYS" + "_" + language); //$NON-NLS-1$ - month = Messages.getString("TimeAgo.MONTH" + "_" + language); //$NON-NLS-1$ - months = Messages.getString("TimeAgo.MONTHS" + "_" + language); //$NON-NLS-1$ - year = Messages.getString("TimeAgo.YEAR" + "_" + language); //$NON-NLS-1$ - years = Messages.getString("TimeAgo.YEARS" + "_" + language); //$NON-NLS-1$ - } + private String prefixFromNow = null; + + private String suffixAgo = Messages.getString("TimeAgo.AGO"); //$NON-NLS-1$ + + private String suffixFromNow = Messages + .getString("TimeAgo.SUFFIX_FROM_NOW"); //$NON-NLS-1$ + + private String seconds = Messages.getString("TimeAgo.SECONDS"); //$NON-NLS-1$ + + private String minute = Messages.getString("TimeAgo.MINUTE"); //$NON-NLS-1$ + + private String minutes = Messages.getString("TimeAgo.MINUTES"); //$NON-NLS-1$ + + private String hour = Messages.getString("TimeAgo.HOUR"); //$NON-NLS-1$ + + private String hours = Messages.getString("TimeAgo.HOURS"); //$NON-NLS-1$ + + private String day = Messages.getString("TimeAgo.DAY"); //$NON-NLS-1$ + + private String days = Messages.getString("TimeAgo.DAYS"); //$NON-NLS-1$ + + private String month = Messages.getString("TimeAgo.MONTH"); //$NON-NLS-1$ + + private String months = Messages.getString("TimeAgo.MONTHS"); //$NON-NLS-1$ + + private String year = Messages.getString("TimeAgo.YEAR"); //$NON-NLS-1$ + + private String years = Messages.getString("TimeAgo.YEARS"); //$NON-NLS-1$ /** * Get time until specified date @@ -448,4 +432,4 @@ public TimeAgo setYears(String years) { this.years = years; return this; } -} +} \ No newline at end of file diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties index 0367987..ddfbf59 100644 --- a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages.properties @@ -1,50 +1,16 @@ #en -TimeAgo.PREFIX_AGO_EN= -TimeAgo.SUFFIX_AGO_EN=ago -TimeAgo.PREFIX_FROM_NOW_EN= -TimeAgo.SUFFIX_FROM_NOW_EN=from now -TimeAgo.DAY_EN=a day -TimeAgo.DAYS_EN={0} days -TimeAgo.HOUR_EN=about an hour -TimeAgo.HOURS_EN={0} hours -TimeAgo.MINUTE_EN=about a minute -TimeAgo.MINUTES_EN={0} minutes -TimeAgo.MONTH_EN=about a month -TimeAgo.MONTHS_EN={0} months -TimeAgo.SECONDS_EN=less than a minute -TimeAgo.YEAR_EN=about a year -TimeAgo.YEARS_EN={0} years - -#en -TimeAgo.PREFIX_AGO_ES=Hace -TimeAgo.SUFFIX_AGO_EN= -TimeAgo.PREFIX_FROM_NOW_ES=Dentro de -TimeAgo.SUFFIX_FROM_NOW_ES= -TimeAgo.DAY_ES=un día -TimeAgo.DAYS_ES={0} días -TimeAgo.HOUR_ES=aprox. una hora -TimeAgo.HOURS_ES={0} horas -TimeAgo.MINUTE_ES=aprox. un minuto -TimeAgo.MINUTES_ES={0} minutos -TimeAgo.MONTH_ES=aprox. un mes -TimeAgo.MONTHS_ES={0} meses -TimeAgo.SECONDS_ES=menos de un minuto -TimeAgo.YEAR_ES=aprox. un año -TimeAgo.YEARS_ES={0} años - -# it -TimeAgo.PREFIX_AGO_IT= -TimeAgo.SUFFIX_AGO_IT=fa -TimeAgo.PREFIX_FROM_NOW_IT= -TimeAgo.SUFFIX_FROM_NOW_IT=adesso -TimeAgo.DAY_IT=un giorno -TimeAgo.DAYS_IT={0} giorni -TimeAgo.HOUR_IT=circa un'ora -TimeAgo.HOURS_IT={0} ore -TimeAgo.MINUTE_IT=circa un minuto -TimeAgo.MINUTES_IT={0} minuti -TimeAgo.MONTH_IT=circa un mese -TimeAgo.MONTHS_IT={0} mesi -TimeAgo.SECONDS_IT=meno di un minuti -TimeAgo.YEAR_IT=circa un anno -TimeAgo.YEARS_IT={0} anni +TimeAgo.PREFIX_AGO= +TimeAgo.SUFFIX_AGO=ago +TimeAgo.PREFIX_FROM_NOW= +TimeAgo.SUFFIX_FROM_NOW=from now +TimeAgo.DAY=a day +TimeAgo.DAYS={0} days +TimeAgo.HOUR=about an hour +TimeAgo.HOURS={0} hours +TimeAgo.MINUTE=about a minute +TimeAgo.MINUTES={0} minutes +TimeAgo.MONTH=about a month +TimeAgo.MONTHS={0} months +TimeAgo.SECONDS=less than a minute +TimeAgo.YEAR=about a year +TimeAgo.YEARS={0} years diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/tests/TimeAgoTest.java b/timeago/src/test/java/com/github/kevinsawicki/timeago/tests/TimeAgoTest.java similarity index 91% rename from timeago/src/main/java/com/github/kevinsawicki/timeago/tests/TimeAgoTest.java rename to timeago/src/test/java/com/github/kevinsawicki/timeago/tests/TimeAgoTest.java index 128dc2f..99b28d0 100644 --- a/timeago/src/main/java/com/github/kevinsawicki/timeago/tests/TimeAgoTest.java +++ b/timeago/src/test/java/com/github/kevinsawicki/timeago/tests/TimeAgoTest.java @@ -1,4 +1,3 @@ -package com.github.kevinsawicki.timeago.tests; /* * Copyright (c) 2011 Kevin Sawicki * @@ -20,6 +19,8 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ +package com.github.kevinsawicki.timeago.tests; + import com.github.kevinsawicki.timeago.TimeAgo; import java.text.MessageFormat; @@ -62,11 +63,6 @@ public class TimeAgoTest extends TestCase { */ public static final long YEAR = 365 * DAY; - /** - * Locale for test - */ - private static final String locale = "it"; - private long ago(long offset) { return System.currentTimeMillis() - offset; } @@ -75,7 +71,7 @@ private long ago(long offset) { * Test seconds ago */ public void testAgoSeconds() { - TimeAgo ago = new TimeAgo(locale); + TimeAgo ago = new TimeAgo(); String time = ago.timeAgo(System.currentTimeMillis()); String expected = ago.join(ago.getPrefixAgo(), ago.getSeconds(), ago.getSuffixAgo()); @@ -86,7 +82,7 @@ public void testAgoSeconds() { * Test minute ago */ public void testAgoMinute() { - TimeAgo ago = new TimeAgo(locale); + TimeAgo ago = new TimeAgo(); String time = ago.timeAgo(ago(MINUTE)); String expected = ago.join(ago.getPrefixAgo(), ago.getMinute(), ago.getSuffixAgo()); @@ -97,7 +93,7 @@ public void testAgoMinute() { * Test minutes ago */ public void testAgoMinutes() { - TimeAgo ago = new TimeAgo(locale); + TimeAgo ago = new TimeAgo(); int minutes = 2; String time = ago.timeAgo(ago(minutes * MINUTE)); String expected = ago.join(ago.getPrefixAgo(), @@ -110,7 +106,7 @@ public void testAgoMinutes() { * Test hour ago */ public void testAgoHour() { - TimeAgo ago = new TimeAgo(locale); + TimeAgo ago = new TimeAgo(); String time = ago.timeAgo(ago(HOUR)); String expected = ago.join(ago.getPrefixAgo(), ago.getHour(), ago.getSuffixAgo()); @@ -121,7 +117,7 @@ public void testAgoHour() { * Test hours ago */ public void testAgoHours() { - TimeAgo ago = new TimeAgo(locale); + TimeAgo ago = new TimeAgo(); long hours = 3; String time = ago.timeAgo(ago(hours * HOUR)); String expected = ago @@ -135,7 +131,7 @@ public void testAgoHours() { * Test day ago */ public void testAgoDay() { - TimeAgo ago = new TimeAgo(locale); + TimeAgo ago = new TimeAgo(); String time = ago.timeAgo(ago(30 * HOUR)); String expected = ago.join(ago.getPrefixAgo(), ago.getDay(), ago.getSuffixAgo()); @@ -146,7 +142,7 @@ public void testAgoDay() { * Test day ago */ public void testAgoDays() { - TimeAgo ago = new TimeAgo(locale); + TimeAgo ago = new TimeAgo(); long days = 4; String time = ago.timeAgo(ago(days * DAY)); String expected = ago.join(ago.getPrefixAgo(), @@ -158,7 +154,7 @@ public void testAgoDays() { * Test month ago */ public void testAgoMonth() { - TimeAgo ago = new TimeAgo(locale); + TimeAgo ago = new TimeAgo(); String time = ago.timeAgo(ago(35 * DAY)); String expected = ago.join(ago.getPrefixAgo(), ago.getMonth(), ago.getSuffixAgo()); @@ -169,7 +165,7 @@ public void testAgoMonth() { * Test months ago */ public void testAgoMonths() { - TimeAgo ago = new TimeAgo(locale); + TimeAgo ago = new TimeAgo(); long months = 2; String time = ago.timeAgo(ago(months * MONTH)); String expected = ago.join(ago.getPrefixAgo(), @@ -182,7 +178,7 @@ public void testAgoMonths() { * Test year ago */ public void testYearAgo() { - TimeAgo ago = new TimeAgo(locale); + TimeAgo ago = new TimeAgo(); String time = ago.timeAgo(System.currentTimeMillis() - (14 * MONTH)); String expected = ago.join(ago.getPrefixAgo(), ago.getYear(), ago.getSuffixAgo()); @@ -193,7 +189,7 @@ public void testYearAgo() { * Test year ago */ public void testYearsAgo() { - TimeAgo ago = new TimeAgo(locale); + TimeAgo ago = new TimeAgo(); long years = 7; String time = ago.timeAgo(System.currentTimeMillis() - (years * YEAR)); String expected = ago From 7fb6ae9564401c4ec16906cb5103a12ae5961d0f Mon Sep 17 00:00:00 2001 From: folivares Date: Sat, 9 May 2015 18:43:31 +0200 Subject: [PATCH 14/18] Update README.md --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1e9c2fc..fab4454 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,18 @@ This is a Java port of the [jquery-timeago](https://github.com/rmm5t/jquery-timeago) plug-in. Please visit the [jquery-timeago](http://rmm5t.github.com/jquery-timeago/) project page to read more about fuzzy timestamps. -##Importing the library -Use Jitpack.io ([check here](https://jitpack.io/#Kinnonii/java-timeago/timeago-1.1.0)) +##Building +The timeago project contains a Maven pom.xml file that builds a jar containing the TimeAgo class. +To build and run the included unit tests: +$ mvn clean install ##Usage ```java -TimeAgo time = new TimeAgo('en'); //For English text OR TimeAgo time = new TimeAgo('es') for Spanish text - +TimeAgo time = new TimeAgo(); long current = System.currentTimeMillis(); -String minutes = time.timeAgo(current - (15 * 60 * 1000)); // returns "15 minutes ago" -String hours = time.timeUntil(current - (6 * 60 * 60 * 1000)); // returns "6 hours from now" +String minutes = time.timeAgo(current - (15 * 60 * 1000)); // returns "15 minutes ago" +String hours = time.timeUntil(current - (6 * 60 * 60 * 1000)); // returns "6 hours from now" ``` From bdf0f79e4b7f2f3d4e315481a6e1a2264879a6c5 Mon Sep 17 00:00:00 2001 From: Federico Date: Sat, 9 May 2015 18:49:05 +0200 Subject: [PATCH 15/18] added italian and spanish translations --- .../timeago/messages_es_ES.properties | 15 +++++++++++++++ .../timeago/messages_it_IT.properties | 15 +++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 timeago/src/main/java/com/github/kevinsawicki/timeago/messages_es_ES.properties create mode 100644 timeago/src/main/java/com/github/kevinsawicki/timeago/messages_it_IT.properties diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages_es_ES.properties b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages_es_ES.properties new file mode 100644 index 0000000..507aa88 --- /dev/null +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages_es_ES.properties @@ -0,0 +1,15 @@ +TimeAgo.PREFIX_AGO= +TimeAgo.SUFFIX_AGO=fa +TimeAgo.PREFIX_FROM_NOW= +TimeAgo.SUFFIX_FROM_NOW=adesso +TimeAgo.DAY=un giorno +TimeAgo.DAYS={0} giorni +TimeAgo.HOUR=circa un''ora +TimeAgo.HOURS={0} ore +TimeAgo.MINUTE=circa un minuto +TimeAgo.MINUTES={0} minuti +TimeAgo.MONTH=circa un mese +TimeAgo.MONTHS={0} mesi +TimeAgo.SECONDS=meno di un minuti +TimeAgo.YEAR=circa un anno +TimeAgo.YEARS={0} anni diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages_it_IT.properties b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages_it_IT.properties new file mode 100644 index 0000000..36f5a14 --- /dev/null +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages_it_IT.properties @@ -0,0 +1,15 @@ +TimeAgo.PREFIX_AGO=Hace +TimeAgo.SUFFIX_AGO= +TimeAgo.PREFIX_FROM_NOW=Dentro de +TimeAgo.SUFFIX_FROM_NOW= +TimeAgo.DAY=un día +TimeAgo.DAYS={0} días +TimeAgo.HOUR=aprox. una hora +TimeAgo.HOURS={0} horas +TimeAgo.MINUTE=aprox. un minuto +TimeAgo.MINUTES={0} minutos +TimeAgo.MONTH=aprox. un mes +TimeAgo.MONTHS={0} meses +TimeAgo.SECONDS=menos de un minuto +TimeAgo.YEAR=aprox. un año +TimeAgo.YEARS={0} años \ No newline at end of file From 29ef5633af948cca64bf62d5709ea056b03f94ad Mon Sep 17 00:00:00 2001 From: Federico Date: Sat, 9 May 2015 18:57:32 +0200 Subject: [PATCH 16/18] fix translations --- .../timeago/messages_es_ES.properties | 30 +++++++++---------- .../timeago/messages_it_IT.properties | 30 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages_es_ES.properties b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages_es_ES.properties index 507aa88..36f5a14 100644 --- a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages_es_ES.properties +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages_es_ES.properties @@ -1,15 +1,15 @@ -TimeAgo.PREFIX_AGO= -TimeAgo.SUFFIX_AGO=fa -TimeAgo.PREFIX_FROM_NOW= -TimeAgo.SUFFIX_FROM_NOW=adesso -TimeAgo.DAY=un giorno -TimeAgo.DAYS={0} giorni -TimeAgo.HOUR=circa un''ora -TimeAgo.HOURS={0} ore -TimeAgo.MINUTE=circa un minuto -TimeAgo.MINUTES={0} minuti -TimeAgo.MONTH=circa un mese -TimeAgo.MONTHS={0} mesi -TimeAgo.SECONDS=meno di un minuti -TimeAgo.YEAR=circa un anno -TimeAgo.YEARS={0} anni +TimeAgo.PREFIX_AGO=Hace +TimeAgo.SUFFIX_AGO= +TimeAgo.PREFIX_FROM_NOW=Dentro de +TimeAgo.SUFFIX_FROM_NOW= +TimeAgo.DAY=un día +TimeAgo.DAYS={0} días +TimeAgo.HOUR=aprox. una hora +TimeAgo.HOURS={0} horas +TimeAgo.MINUTE=aprox. un minuto +TimeAgo.MINUTES={0} minutos +TimeAgo.MONTH=aprox. un mes +TimeAgo.MONTHS={0} meses +TimeAgo.SECONDS=menos de un minuto +TimeAgo.YEAR=aprox. un año +TimeAgo.YEARS={0} años \ No newline at end of file diff --git a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages_it_IT.properties b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages_it_IT.properties index 36f5a14..507aa88 100644 --- a/timeago/src/main/java/com/github/kevinsawicki/timeago/messages_it_IT.properties +++ b/timeago/src/main/java/com/github/kevinsawicki/timeago/messages_it_IT.properties @@ -1,15 +1,15 @@ -TimeAgo.PREFIX_AGO=Hace -TimeAgo.SUFFIX_AGO= -TimeAgo.PREFIX_FROM_NOW=Dentro de -TimeAgo.SUFFIX_FROM_NOW= -TimeAgo.DAY=un día -TimeAgo.DAYS={0} días -TimeAgo.HOUR=aprox. una hora -TimeAgo.HOURS={0} horas -TimeAgo.MINUTE=aprox. un minuto -TimeAgo.MINUTES={0} minutos -TimeAgo.MONTH=aprox. un mes -TimeAgo.MONTHS={0} meses -TimeAgo.SECONDS=menos de un minuto -TimeAgo.YEAR=aprox. un año -TimeAgo.YEARS={0} años \ No newline at end of file +TimeAgo.PREFIX_AGO= +TimeAgo.SUFFIX_AGO=fa +TimeAgo.PREFIX_FROM_NOW= +TimeAgo.SUFFIX_FROM_NOW=adesso +TimeAgo.DAY=un giorno +TimeAgo.DAYS={0} giorni +TimeAgo.HOUR=circa un''ora +TimeAgo.HOURS={0} ore +TimeAgo.MINUTE=circa un minuto +TimeAgo.MINUTES={0} minuti +TimeAgo.MONTH=circa un mese +TimeAgo.MONTHS={0} mesi +TimeAgo.SECONDS=meno di un minuti +TimeAgo.YEAR=circa un anno +TimeAgo.YEARS={0} anni From dafa7532d5e6ac2bccb62b88bd2d9867b2491757 Mon Sep 17 00:00:00 2001 From: folivares Date: Mon, 11 May 2015 10:23:10 +0200 Subject: [PATCH 17/18] Update README.md --- README.md | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fab4454..6e26a74 100644 --- a/README.md +++ b/README.md @@ -3,19 +3,33 @@ This is a Java port of the [jquery-timeago](https://github.com/rmm5t/jquery-timeago) plug-in. Please visit the [jquery-timeago](http://rmm5t.github.com/jquery-timeago/) project page to read more about fuzzy timestamps. ##Building -The timeago project contains a Maven pom.xml file that builds a jar containing the TimeAgo class. + +The timeago project contains a [Maven](http://maven.apache.org/) pom.xml file that builds a jar containing the TimeAgo class. + To build and run the included unit tests: -$ mvn clean install + +```$ mvn clean install``` ##Usage ```java TimeAgo time = new TimeAgo(); long current = System.currentTimeMillis(); -String minutes = time.timeAgo(current - (15 * 60 * 1000)); // returns "15 minutes ago" -String hours = time.timeUntil(current - (6 * 60 * 60 * 1000)); // returns "6 hours from now" +String minutes = time.timeAgo(current - (15 * 60 * 1000)); // returns "15 minutes ago" +String hours = time.timeUntil(current - (6 * 60 * 60 * 1000)); // returns "6 hours from now" ``` +### Maven + +This library is available from [Maven Central](http://search.maven.org/#search%7Cga%7C1%7C%20a%3A%22timeago%22%20g%3A%22com.github.kevinsawicki%22). + +```xml + + com.github.kevinsawicki + timeago + 1.0.1 + +``` ##Contribution From b76ccd3e94d0781bec188354719d1e2000f677a3 Mon Sep 17 00:00:00 2001 From: folivares Date: Mon, 11 May 2015 10:25:24 +0200 Subject: [PATCH 18/18] Update pom.xml --- timeago/pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/timeago/pom.xml b/timeago/pom.xml index 22ffd23..82bf5c1 100644 --- a/timeago/pom.xml +++ b/timeago/pom.xml @@ -8,9 +8,9 @@ - com.github.Kinnonii + com.github.kevinsawicki timeago - 1.1.0 + 1.0.2-SNAPSHOT Time Ago Simple Java library for converting dates to time ago strings. @@ -30,9 +30,9 @@ - https://github.com/kinnonii/java-timeago - scm:git:git://github.com/kinnonii/java-timeago.git - scm:git:git@github.com:kinnonii/java-timeago.git + https://github.com/kevinsawicki/java-timeago + scm:git:git://github.com/kevinsawicki/java-timeago.git + scm:git:git@github.com:kevinsawicki/java-timeago.git