Skip to content

Commit 09bb368

Browse files
author
Edward Chiang
committed
Add support traditional Chinese for displaying format date.
1 parent 271c65b commit 09bb368

3 files changed

Lines changed: 345 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ target/
1010
bin/
1111
/*/src/main/java/META-INF
1212
docs/reference/src/main/docbook/en-US/version_info.xml
13+
.idea
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package org.ocpsoft.prettytime.i18n;
2+
3+
/**
4+
* Created by edward_chiang on 13/6/27.
5+
*/
6+
public class Resources_zh_TW extends java.util.ListResourceBundle {
7+
8+
9+
private static final Object[][] OBJECTS = new Object[][] {
10+
{ "CenturyPattern", "%n %u" },
11+
{ "CenturyFuturePrefix", "" },
12+
{ "CenturyFutureSuffix", "後" },
13+
{ "CenturyPastPrefix", "" },
14+
{ "CenturyPastSuffix", "前" },
15+
{ "CenturySingularName", "世紀" },
16+
{ "CenturyPluralName", "世紀" },
17+
{ "DayPattern", "%n %u" },
18+
{ "DayFuturePrefix", "" },
19+
{ "DayFutureSuffix", "後" },
20+
{ "DayPastPrefix", "" },
21+
{ "DayPastSuffix", "前" },
22+
{ "DaySingularName", "天" },
23+
{ "DayPluralName", "天" },
24+
{ "DecadePattern", "%n%u" },
25+
{ "DecadeFuturePrefix", "" },
26+
{ "DecadeFutureSuffix", "後" },
27+
{ "DecadePastPrefix", "" },
28+
{ "DecadePastSuffix", "前" },
29+
{ "DecadeSingularName", "0 年" },
30+
{ "DecadePluralName", "0 年" },
31+
{ "HourPattern", "%n %u" },
32+
{ "HourFuturePrefix", "" },
33+
{ "HourFutureSuffix", "後" },
34+
{ "HourPastPrefix", "" },
35+
{ "HourPastSuffix", "前" },
36+
{ "HourSingularName", "小時" },
37+
{ "HourPluralName", "小時" },
38+
{ "JustNowPattern", "%u" },
39+
{ "JustNowFuturePrefix", "" },
40+
{ "JustNowFutureSuffix", "剛剛" },
41+
{ "JustNowPastPrefix", "片刻之前" },
42+
{ "JustNowPastSuffix", "" },
43+
{ "JustNowSingularName", "" },
44+
{ "JustNowPluralName", "" },
45+
{ "MillenniumPattern", "%n %u" },
46+
{ "MillenniumFuturePrefix", "" },
47+
{ "MillenniumFutureSuffix", "後" },
48+
{ "MillenniumPastPrefix", "" },
49+
{ "MillenniumPastSuffix", "前" },
50+
{ "MillenniumSingularName", "千年" },
51+
{ "MillenniumPluralName", "千年" },
52+
{ "MillisecondPattern", "%n %u" },
53+
{ "MillisecondFuturePrefix", "" },
54+
{ "MillisecondFutureSuffix", "後" },
55+
{ "MillisecondPastPrefix", "" },
56+
{ "MillisecondPastSuffix", "前" },
57+
{ "MillisecondSingularName", "毫秒" },
58+
{ "MillisecondPluralName", "毫秒" },
59+
{ "MinutePattern", "%n %u" },
60+
{ "MinuteFuturePrefix", "" },
61+
{ "MinuteFutureSuffix", "後" },
62+
{ "MinutePastPrefix", "" },
63+
{ "MinutePastSuffix", "前" },
64+
{ "MinuteSingularName", "分鐘" },
65+
{ "MinutePluralName", "分鐘" },
66+
{ "MonthPattern", "%n %u" },
67+
{ "MonthFuturePrefix", "" },
68+
{ "MonthFutureSuffix", "後" },
69+
{ "MonthPastPrefix", "" },
70+
{ "MonthPastSuffix", "前" },
71+
{ "MonthSingularName", "個月" },
72+
{ "MonthPluralName", "個月" },
73+
{ "SecondPattern", "%n %u" },
74+
{ "SecondFuturePrefix", "" },
75+
{ "SecondFutureSuffix", "後" },
76+
{ "SecondPastPrefix", "" },
77+
{ "SecondPastSuffix", "前" },
78+
{ "SecondSingularName", "秒" },
79+
{ "SecondPluralName", "秒" },
80+
{ "WeekPattern", "%n %u" },
81+
{ "WeekFuturePrefix", "" },
82+
{ "WeekFutureSuffix", "後" },
83+
{ "WeekPastPrefix", "" },
84+
{ "WeekPastSuffix", "前" },
85+
{ "WeekSingularName", "週" },
86+
{ "WeekPluralName", "週" },
87+
{ "YearPattern", "%n %u" },
88+
{ "YearFuturePrefix", "" },
89+
{ "YearFutureSuffix", "後" },
90+
{ "YearPastPrefix", "" },
91+
{ "YearPastSuffix", "前" },
92+
{ "YearSingularName", "年" },
93+
{ "YearPluralName", "年" },
94+
{ "AbstractTimeUnitPattern", "" },
95+
{ "AbstractTimeUnitFuturePrefix", "" },
96+
{ "AbstractTimeUnitFutureSuffix", "" },
97+
{ "AbstractTimeUnitPastPrefix", "" },
98+
{ "AbstractTimeUnitPastSuffix", "" },
99+
{ "AbstractTimeUnitSingularName", "" },
100+
{ "AbstractTimeUnitPluralName", "" } };
101+
102+
/**
103+
* Returns an {@code Object} array containing the resources of this
104+
* {@code ListResourceBundle}. Each element in the array is an array of two
105+
* elements, the first is the resource key string and the second is the
106+
* resource.
107+
*
108+
* @return a {@code Object} array containing the resources.
109+
*/
110+
@Override
111+
protected Object[][] getContents() {
112+
return OBJECTS;
113+
}
114+
}
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
package org.ocpsoft.prettytime;
2+
3+
import org.junit.After;
4+
import org.junit.Before;
5+
import org.junit.Test;
6+
7+
import java.text.SimpleDateFormat;
8+
import java.util.Date;
9+
import java.util.Locale;
10+
11+
import static org.junit.Assert.assertEquals;
12+
13+
/**
14+
* Created by edward_chiang on 13/6/27.
15+
*/
16+
public class PrettyTimeI18n_zh_TW_Test {
17+
private final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
18+
private Locale locale;
19+
20+
@Before
21+
public void setUp() throws Exception
22+
{
23+
locale = Locale.TRADITIONAL_CHINESE;
24+
Locale.setDefault(Locale.TRADITIONAL_CHINESE);
25+
}
26+
27+
@Test
28+
public void testPrettyTime()
29+
{
30+
PrettyTime p = new PrettyTime(locale);
31+
assertEquals("剛剛", p.format(new Date()));
32+
}
33+
34+
@Test
35+
public void testPrettyTimeCenturies()
36+
{
37+
PrettyTime p = new PrettyTime(new Date(3155692597470L * 3L), locale);
38+
assertEquals("3 世紀 前", p.format(new Date(0)));
39+
40+
p = new PrettyTime(new Date(0), locale);
41+
assertEquals("3 世紀 後", p.format(new Date(3155692597470L * 3L)));
42+
}
43+
44+
@Test
45+
public void testCeilingInterval() throws Exception
46+
{
47+
Date then = format.parse("20/5/2009");
48+
Date ref = format.parse("17/6/2009");
49+
PrettyTime t = new PrettyTime(ref, locale);
50+
assertEquals("1 個月 前", t.format(then));
51+
}
52+
53+
@Test(expected = IllegalArgumentException.class)
54+
public void testNullDate() throws Exception
55+
{
56+
PrettyTime t = new PrettyTime(locale);
57+
Date date = null;
58+
assertEquals("зараз", t.format(date));
59+
}
60+
61+
@Test
62+
public void testRightNow() throws Exception
63+
{
64+
PrettyTime t = new PrettyTime(locale);
65+
assertEquals("剛剛", t.format(new Date()));
66+
}
67+
68+
@Test
69+
public void testRightNowVariance() throws Exception
70+
{
71+
PrettyTime t = new PrettyTime(new Date(0), locale);
72+
assertEquals("剛剛", t.format(new Date(600)));
73+
}
74+
75+
@Test
76+
public void testMinutesFromNow() throws Exception
77+
{
78+
PrettyTime t = new PrettyTime(new Date(0), locale);
79+
assertEquals("12 分鐘 後", t.format(new Date(1000 * 60 * 12)));
80+
}
81+
82+
@Test
83+
public void testHoursFromNow() throws Exception
84+
{
85+
PrettyTime t = new PrettyTime(new Date(0), locale);
86+
assertEquals("3 小時 後", t.format(new Date(1000 * 60 * 60 * 3)));
87+
}
88+
89+
@Test
90+
public void testDaysFromNow() throws Exception
91+
{
92+
PrettyTime t = new PrettyTime(new Date(0), locale);
93+
assertEquals("3 天 後", t.format(new Date(1000 * 60 * 60 * 24 * 3)));
94+
}
95+
96+
@Test
97+
public void testWeeksFromNow() throws Exception
98+
{
99+
PrettyTime t = new PrettyTime(new Date(0), locale);
100+
assertEquals("3 週 後", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3)));
101+
}
102+
103+
@Test
104+
public void testMonthsFromNow() throws Exception
105+
{
106+
PrettyTime t = new PrettyTime(new Date(0), locale);
107+
assertEquals("3 個月 後", t.format(new Date(2629743830L * 3L)));
108+
}
109+
110+
@Test
111+
public void testYearsFromNow() throws Exception
112+
{
113+
PrettyTime t = new PrettyTime(new Date(0), locale);
114+
assertEquals("3 年 後", t.format(new Date(2629743830L * 12L * 3L)));
115+
}
116+
117+
@Test
118+
public void testDecadesFromNow() throws Exception
119+
{
120+
PrettyTime t = new PrettyTime(new Date(0), locale);
121+
assertEquals("30 年 後", t.format(new Date(315569259747L * 3L)));
122+
}
123+
124+
@Test
125+
public void testCenturiesFromNow() throws Exception
126+
{
127+
PrettyTime t = new PrettyTime(new Date(0), locale);
128+
assertEquals("3 世紀 後", t.format(new Date(3155692597470L * 3L)));
129+
}
130+
131+
/*
132+
* Past
133+
*/
134+
@Test
135+
public void testMomentsAgo() throws Exception
136+
{
137+
PrettyTime t = new PrettyTime(new Date(6000), locale);
138+
assertEquals("片刻之前", t.format(new Date(0)));
139+
}
140+
141+
@Test
142+
public void testMinutesAgo() throws Exception
143+
{
144+
PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale);
145+
assertEquals("12 分鐘 前", t.format(new Date(0)));
146+
}
147+
148+
@Test
149+
public void test1HourAgo() throws Exception
150+
{
151+
PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 1), locale);
152+
assertEquals("1 小時 前", t.format(new Date(0)));
153+
}
154+
155+
@Test
156+
public void test3HoursAgo() throws Exception
157+
{
158+
PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale);
159+
assertEquals("3 小時 前", t.format(new Date(0)));
160+
}
161+
162+
@Test
163+
public void test6HoursAgo() throws Exception
164+
{
165+
PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 6), locale);
166+
assertEquals("6 小時 前", t.format(new Date(0)));
167+
}
168+
169+
@Test
170+
public void testDaysAgo() throws Exception
171+
{
172+
PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale);
173+
assertEquals("3 天 前", t.format(new Date(0)));
174+
}
175+
176+
@Test
177+
public void testWeeksAgo() throws Exception
178+
{
179+
PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale);
180+
assertEquals("3 週 前", t.format(new Date(0)));
181+
}
182+
183+
@Test
184+
public void testMonthsAgo() throws Exception
185+
{
186+
PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale);
187+
assertEquals("3 個月 前", t.format(new Date(0)));
188+
}
189+
190+
@Test
191+
public void testYearsAgo() throws Exception
192+
{
193+
PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale);
194+
assertEquals("3 年 前", t.format(new Date(0)));
195+
}
196+
197+
@Test
198+
public void test8YearsAgo() throws Exception
199+
{
200+
PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 8L), locale);
201+
assertEquals("8 年 前", t.format(new Date(0)));
202+
}
203+
204+
@Test
205+
public void testDecadesAgo() throws Exception
206+
{
207+
PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale);
208+
assertEquals("30 年 前", t.format(new Date(0)));
209+
}
210+
211+
@Test
212+
public void test8DecadesAgo() throws Exception
213+
{
214+
PrettyTime t = new PrettyTime(new Date(315569259747L * 8L), locale);
215+
assertEquals("80 年 前", t.format(new Date(0)));
216+
}
217+
218+
@Test
219+
public void testCenturiesAgo() throws Exception
220+
{
221+
PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale);
222+
assertEquals("3 世紀 前", t.format(new Date(0)));
223+
}
224+
225+
@After
226+
public void tearDown() throws Exception
227+
{
228+
Locale.setDefault(locale);
229+
}
230+
}

0 commit comments

Comments
 (0)