PageRenderTime 41ms CodeModel.GetById 20ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_FI_Test.java

http://github.com/ocpsoft/prettytime
Java | 403 lines | 332 code | 56 blank | 15 comment | 4 complexity | fb149df597e7b41b04605a724e46bd2d MD5 | raw file
Possible License(s): Apache-2.0
  1/*
  2 * Copyright 2012 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
  3 * 
  4 * Licensed under the Apache License, Version 2.0 (the "License");
  5 * you may not use this file except in compliance with the License.
  6 * You may obtain a copy of the License at
  7 * 
  8 *     http://www.apache.org/licenses/LICENSE-2.0
  9 * 
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed under the License is distributed on an "AS IS" BASIS,
 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13 * See the License for the specific language governing permissions and
 14 * limitations under the License.
 15 */
 16package org.ocpsoft.prettytime;
 17import static org.junit.Assert.assertEquals;
 18
 19import java.util.ArrayList;
 20import java.util.Date;
 21import java.util.List;
 22import java.util.Locale;
 23
 24import org.junit.Before;
 25import org.junit.Test;
 26import org.ocpsoft.prettytime.Duration;
 27import org.ocpsoft.prettytime.PrettyTime;
 28import org.ocpsoft.prettytime.TimeFormat;
 29import org.ocpsoft.prettytime.TimeUnit;
 30import org.ocpsoft.prettytime.units.JustNow;
 31
 32public class PrettyTimeI18n_FI_Test {
 33	private Locale locale;
 34
 35	@Before
 36	public void setUp() throws Exception
 37	{
 38		locale = new Locale("fi");
 39	}
 40	
 41	private PrettyTime newPrettyTimeWOJustNow(Date ref, Locale locale) 
 42	{
 43		PrettyTime t = new PrettyTime(ref, locale);
 44		List<TimeUnit> units = t.getUnits();
 45		List<TimeFormat> formats = new ArrayList<TimeFormat>();
 46		for (TimeUnit timeUnit : units) {
 47			if(!(timeUnit instanceof JustNow)) {
 48				formats.add(t.getFormat(timeUnit));
 49			}
 50		}
 51		int index = 0;
 52		t.clearUnits();
 53		for (TimeUnit timeUnit : units) {
 54			if(!(timeUnit instanceof JustNow)) {
 55				t.registerUnit(timeUnit, formats.get(index));
 56				index++;
 57			}
 58		}
 59		return t;
 60	}
 61
 62
 63	@Test
 64	public void testRightNow() throws Exception
 65	{
 66		PrettyTime t = new PrettyTime(new Date(0), locale);
 67		assertEquals("hetken pההstה", t.format(new Date(6000)));
 68	}
 69
 70	@Test
 71	public void testMomentsAgo() throws Exception
 72	{
 73		PrettyTime t = new PrettyTime(new Date(6000), locale);
 74		assertEquals("hetki sitten", t.format(new Date(0)));
 75	}
 76	
 77	@Test
 78	public void testMilliSecondsFromNow() throws Exception
 79	{
 80		PrettyTime t = newPrettyTimeWOJustNow(new Date(0), locale);
 81		assertEquals("13 millisekunnin pההstה", t.format(new Date(13)));
 82	}
 83
 84	@Test
 85	public void testMilliSecondsAgo() throws Exception
 86	{
 87		PrettyTime t = newPrettyTimeWOJustNow(new Date(13), locale);
 88		assertEquals("13 millisekuntia sitten", t.format(new Date(0)));
 89	}
 90
 91	@Test
 92	public void testMilliSecondFromNow() throws Exception
 93	{
 94		PrettyTime t = newPrettyTimeWOJustNow(new Date(0), locale);
 95		assertEquals("millisekunnin pההstה", t.format(new Date(1)));
 96	}
 97
 98	@Test
 99	public void testMilliSecondAgo() throws Exception
100	{
101		PrettyTime t = newPrettyTimeWOJustNow(new Date(1), locale);
102		assertEquals("millisekunti sitten", t.format(new Date(0)));
103	}
104	
105	@Test
106	public void testSecondsFromNow() throws Exception
107	{
108		PrettyTime t = newPrettyTimeWOJustNow(new Date(0), locale);
109		assertEquals("13 sekunnin pההstה", t.format(new Date(1000 * 13)));
110	}
111
112	@Test
113	public void testSecondsAgo() throws Exception
114	{
115		PrettyTime t = newPrettyTimeWOJustNow(new Date(1000 * 13), locale);
116		assertEquals("13 sekuntia sitten", t.format(new Date(0)));
117	}
118
119	@Test
120	public void testSecondFromNow() throws Exception
121	{
122		PrettyTime t = newPrettyTimeWOJustNow(new Date(0), locale);
123		assertEquals("sekunnin pההstה", t.format(new Date(1000  * 1)));
124	}
125
126	@Test
127	public void testSecondAgo() throws Exception
128	{
129		PrettyTime t = newPrettyTimeWOJustNow(new Date(1000  * 1), locale);
130		assertEquals("sekunti sitten", t.format(new Date(0)));
131	}
132
133	@Test
134	public void testMinutesFromNow() throws Exception
135	{
136		PrettyTime t = new PrettyTime(new Date(0), locale);
137		assertEquals("13 minuutin pההstה", t.format(new Date(1000 * 60  * 13)));
138	}
139
140	@Test
141	public void testMinutesAgo() throws Exception
142	{
143		PrettyTime t = new PrettyTime(new Date(1000 * 60 * 13), locale);
144		assertEquals("13 minuuttia sitten", t.format(new Date(0)));
145	}
146
147	@Test
148	public void testMinuteFromNow() throws Exception
149	{
150		PrettyTime t = newPrettyTimeWOJustNow(new Date(0), locale);
151		assertEquals("minuutin pההstה", t.format(new Date(1000 * 60 * 1)));
152	}
153
154	@Test
155	public void testMinuteAgo() throws Exception
156	{
157		PrettyTime t = newPrettyTimeWOJustNow(new Date(1000 * 60 * 1), locale);
158		assertEquals("minuutti sitten", t.format(new Date(0)));
159	}
160
161	@Test
162	public void testHoursFromNow() throws Exception
163	{
164		PrettyTime t = new PrettyTime(new Date(0), locale);
165		assertEquals("3 tunnin pההstה", t.format(new Date(1000 * 60 * 60 * 3)));
166	}
167
168	@Test
169	public void testHoursAgo() throws Exception
170	{
171		PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale);
172		assertEquals("3 tuntia sitten", t.format(new Date(0)));
173	}
174
175	@Test
176	public void testHoursFromNowSingle() throws Exception
177	{
178		PrettyTime t = new PrettyTime(new Date(0), locale);
179		assertEquals("tunnin pההstה", t.format(new Date(1000 * 60 * 60 * 1)));
180	}
181
182	@Test
183	public void testHoursAgoSingle() throws Exception
184	{
185		PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 1), locale);
186		assertEquals("tunti sitten", t.format(new Date(0)));
187	}
188
189	@Test
190	public void testDaysFromNow() throws Exception
191	{
192		PrettyTime t = new PrettyTime(new Date(0), locale);
193		assertEquals("3 pהivהn pההstה", t.format(new Date(1000 * 60 * 60 * 24 * 3)));
194	}
195
196	@Test
197	public void testDaysAgo() throws Exception
198	{
199		PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale);
200		assertEquals("3 pהivהה sitten", t.format(new Date(0)));
201	}
202
203	@Test
204	public void testDaysFromNowSingle() throws Exception
205	{
206		PrettyTime t = new PrettyTime(new Date(0), locale);
207		assertEquals("huomenna", t.format(new Date(1000 * 60 * 60 * 24 * 1)));
208	}
209
210	@Test
211	public void testDaysAgoSingle() throws Exception
212	{
213		PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 1), locale);
214		assertEquals("eilen", t.format(new Date(0)));
215	}
216
217	@Test
218	public void testWeeksFromNow() throws Exception
219	{
220		PrettyTime t = new PrettyTime(new Date(0), locale);
221		assertEquals("3 viikon pההstה", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3)));
222	}
223
224	@Test
225	public void testWeeksAgo() throws Exception
226	{
227		PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale);
228		assertEquals("3 viikkoa sitten", t.format(new Date(0)));
229	}
230
231	@Test
232	public void testWeeksFromNowSingle() throws Exception
233	{
234		PrettyTime t = new PrettyTime(new Date(0), locale);
235		assertEquals("viikon pההstה", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 1)));
236	}
237
238	@Test
239	public void testWeeksAgoSingle() throws Exception
240	{
241		PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 1), locale);
242		assertEquals("viikko sitten", t.format(new Date(0)));
243	}
244
245	@Test
246	public void testMonthsFromNow() throws Exception
247	{
248		PrettyTime t = new PrettyTime(new Date(0), locale);
249		assertEquals("3 kuukauden pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 30 * 3)));
250	}
251
252	@Test
253	public void testMonthsAgo() throws Exception
254	{
255		PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 30 * 3), locale);
256		assertEquals("3 kuukautta sitten", t.format(new Date(0)));
257	}
258
259	@Test
260	public void testMonthFromNow() throws Exception
261	{
262		PrettyTime t = new PrettyTime(new Date(0), locale);
263		assertEquals("kuukauden pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 30 * 1)));
264	}
265
266	@Test
267	public void testMonthAgo() throws Exception
268	{
269		PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 30 * 1), locale);
270		assertEquals("kuukausi sitten", t.format(new Date(0)));
271	}
272
273	@Test
274	public void testYearsFromNow() throws Exception
275	{
276		PrettyTime t = new PrettyTime(new Date(0), locale);
277		assertEquals("3 vuoden pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 3)));
278	}
279
280	@Test
281	public void testYearsAgo() throws Exception
282	{
283		PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 365 * 3), locale);
284		assertEquals("3 vuotta sitten", t.format(new Date(0)));
285	}
286
287	@Test
288	public void testYearFromNow() throws Exception
289	{
290		PrettyTime t = new PrettyTime(new Date(0), locale);
291		assertEquals("vuoden pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 366 * 1)));
292	}
293
294	@Test
295	public void testYearAgo() throws Exception
296	{
297		PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 366 * 1), locale);
298		assertEquals("vuosi sitten", t.format(new Date(0)));
299	}
300
301	@Test
302	public void testDecadesFromNow() throws Exception
303	{
304		PrettyTime t = new PrettyTime(new Date(0), locale);
305		assertEquals("3 vuosikymmenen pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 10 * 3)));
306	}
307
308	@Test
309	public void testDecadesAgo() throws Exception
310	{
311		PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 365 * 10 * 3), locale);
312		assertEquals("3 vuosikymmentה sitten", t.format(new Date(0)));
313	}
314
315	@Test
316	public void testDecadeFromNow() throws Exception
317	{
318		PrettyTime t = new PrettyTime(new Date(0), locale);
319		assertEquals("vuosikymmenen pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 11 * 1)));
320	}
321
322	@Test
323	public void testDecadeAgo() throws Exception
324	{
325		PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 365 * 11), locale);
326		assertEquals("vuosikymmen sitten", t.format(new Date(0)));
327	}
328
329	@Test
330	public void testCenturiesFromNow() throws Exception
331	{
332		PrettyTime t = new PrettyTime(new Date(0), locale);
333		assertEquals("3 vuosisadan pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 100 * 3)));
334	}
335
336	@Test
337	public void testCenturiesAgo() throws Exception
338	{
339		PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 365 * 100 * 3), locale);
340		assertEquals("3 vuosisataa sitten", t.format(new Date(0)));
341	}
342
343	@Test
344	public void testCenturyFromNow() throws Exception
345	{
346		PrettyTime t = new PrettyTime(new Date(0), locale);
347		assertEquals("vuosisadan pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 101)));
348	}
349
350	@Test
351	public void testCenturyAgo() throws Exception
352	{
353		PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 365 * 101), locale);
354		assertEquals("vuosisata sitten", t.format(new Date(0)));
355	}
356
357	@Test
358	public void testMillenniaFromNow() throws Exception
359	{
360		PrettyTime t = new PrettyTime(new Date(0), locale);
361		assertEquals("3 vuosituhannen pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 1000 * 3)));
362	}
363
364	@Test
365	public void testMillenniaAgo() throws Exception
366	{
367		PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 365 * 1000 * 3), locale);
368		assertEquals("3 vuosituhatta sitten", t.format(new Date(0)));
369	}
370
371	@Test
372	public void testMillenniumFromNow() throws Exception
373	{
374		PrettyTime t = new PrettyTime(new Date(0), locale);
375		assertEquals("vuosituhannen pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 1001)));
376	}
377
378	@Test
379	public void testMillenniumAgo() throws Exception
380	{
381		PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 365 * 1001), locale);
382		assertEquals("vuosituhat sitten", t.format(new Date(0)));
383	}
384
385	@Test
386	public void testFormattingDurationListInThePast() throws Exception
387	{
388		PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3 + 1000 * 60 * 60 * 15 + 1000 * 60 * 38), locale);
389		List<Duration> durations = t.calculatePreciseDuration(new Date(0));
390		assertEquals("3 pהivהה 15 tuntia 38 minuuttia sitten", t.format(durations));
391	}
392
393	@Test
394	public void testFormattingDurationListInTheFuture() throws Exception
395	{
396		PrettyTime t = new PrettyTime(new Date(0), locale);
397		List<Duration> durations = t.calculatePreciseDuration(new Date(1000 * 60 * 60 * 24 * 3 + 1000 * 60 * 60 * 15
398				+ 1000 * 60 * 38));
399		assertEquals("3 pהivהn 15 tunnin 38 minuutin pההstה", t.format(durations));
400	}
401
402
403}