Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support traditional Chinese for displaying format date.

  • Loading branch information...
commit 09bb368c776ee73c34c07faf7e52f9d554d8f60f 1 parent 271c65b
Edward Chiang authored
View
1  .gitignore
@@ -10,3 +10,4 @@ target/
bin/
/*/src/main/java/META-INF
docs/reference/src/main/docbook/en-US/version_info.xml
+.idea
View
114 core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_zh_TW.java
@@ -0,0 +1,114 @@
+package org.ocpsoft.prettytime.i18n;
+
+/**
+ * Created by edward_chiang on 13/6/27.
+ */
+public class Resources_zh_TW extends java.util.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", "0 年" },
+ { "DecadePluralName", "0 年" },
+ { "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", "" } };
+
+ /**
+ * Returns an {@code Object} array containing the resources of this
+ * {@code ListResourceBundle}. Each element in the array is an array of two
+ * elements, the first is the resource key string and the second is the
+ * resource.
+ *
+ * @return a {@code Object} array containing the resources.
+ */
+ @Override
+ protected Object[][] getContents() {
+ return OBJECTS;
+ }
+}
View
230 core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_zh_TW_Test.java
@@ -0,0 +1,230 @@
+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;
+
+/**
+ * Created by edward_chiang on 13/6/27.
+ */
+public class PrettyTimeI18n_zh_TW_Test {
+ private final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
+ private Locale locale;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ locale = Locale.TRADITIONAL_CHINESE;
+ Locale.setDefault(Locale.TRADITIONAL_CHINESE);
+ }
+
+ @Test
+ public void testPrettyTime()
+ {
+ PrettyTime p = new PrettyTime(locale);
+ assertEquals("剛剛", 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(expected = IllegalArgumentException.class)
+ 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 testMinutesFromNow() throws Exception
+ {
+ PrettyTime t = new PrettyTime(new Date(0), locale);
+ assertEquals("12 分鐘 後", t.format(new Date(1000 * 60 * 12)));
+ }
+
+ @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("30 年 後", 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("30 年 前", t.format(new Date(0)));
+ }
+
+ @Test
+ public void test8DecadesAgo() throws Exception
+ {
+ PrettyTime t = new PrettyTime(new Date(315569259747L * 8L), locale);
+ assertEquals("80 年 前", 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);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.