/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_SE_Test.java
http://github.com/ocpsoft/prettytime · Java · 206 lines · 160 code · 28 blank · 18 comment · 0 complexity · 33756a117a2c59dad24fa583da1cb766 MD5 · raw file
- /*
- * Copyright 2012 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package org.ocpsoft.prettytime;
- import static org.junit.Assert.assertEquals;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.Locale;
- import org.junit.Before;
- import org.junit.Test;
- import org.ocpsoft.prettytime.PrettyTime;
- public class PrettyTimeI18n_SE_Test {
- private Locale locale;
- private final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
- @Before
- public void setUp() throws Exception
- {
- locale = new Locale("se");
- }
- @Test
- public void testPrettyTime()
- {
- PrettyTime p = new PrettyTime(locale);
- assertEquals(p.format(new Date()), "om ett par ögonblick frĺn nu");
- }
- @Test
- public void testPrettyTimeCenturies()
- {
- PrettyTime p = new PrettyTime(new Date(3155692597470L * 3L), locale);
- assertEquals("för 3 ĺrhundraden sedan", p.format(new Date(0)));
- p = new PrettyTime(new Date(0), locale);
- assertEquals("om 3 ĺrhundraden frĺn och med nu", 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("för 1 mĺnad sedan", t.format(then));
- }
- @Test
- public void testNullDate() throws Exception
- {
- PrettyTime t = new PrettyTime(locale);
- Date date = null;
- assertEquals("om ett par ögonblick frĺn nu", t.format(date));
- }
- @Test
- public void testRightNow() throws Exception
- {
- PrettyTime t = new PrettyTime(locale);
- assertEquals("om ett par ögonblick frĺn nu", t.format(new Date()));
- }
- @Test
- public void testRightNowVariance() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(0), locale);
- assertEquals("om ett par ögonblick frĺn nu", t.format(new Date(600)));
- }
- @Test
- public void testMinutesFromNow() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(0), locale);
- assertEquals("om 12 minuter frĺn och med nu", t.format(new Date(1000 * 60 * 12)));
- }
- @Test
- public void testHoursFromNow() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(0), locale);
- assertEquals("om 3 timmar frĺn och med nu", t.format(new Date(1000 * 60 * 60 * 3)));
- }
- @Test
- public void testDaysFromNow() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(0), locale);
- assertEquals("om 3 dagar frĺn och med nu", t.format(new Date(1000 * 60 * 60 * 24 * 3)));
- }
- @Test
- public void testWeeksFromNow() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(0), locale);
- assertEquals("om 3 veckor frĺn och med nu", 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("om 3 mĺnader frĺn och med nu", t.format(new Date(2629743830L * 3L)));
- }
- @Test
- public void testYearsFromNow() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(0), locale);
- assertEquals("om 3 ĺr frĺn och med nu", t.format(new Date(2629743830L * 12L * 3L)));
- }
- @Test
- public void testDecadesFromNow() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(0), locale);
- assertEquals("om 3 ĺrtionden frĺn och med nu", t.format(new Date(315569259747L * 3L)));
- }
- @Test
- public void testCenturiesFromNow() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(0), locale);
- assertEquals("om 3 ĺrhundraden frĺn och med nu", t.format(new Date(3155692597470L * 3L)));
- }
- /*
- * Past
- */
- @Test
- public void testMomentsAgo() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(6000), locale);
- assertEquals("för ett par ögonblick sedan", t.format(new Date(0)));
- }
- @Test
- public void testMinutesAgo() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale);
- assertEquals("för 12 minuter sedan", t.format(new Date(0)));
- }
- @Test
- public void testHoursAgo() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale);
- assertEquals("för 3 timmar sedan", t.format(new Date(0)));
- }
- @Test
- public void testDaysAgo() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale);
- assertEquals("för 3 dagar sedan", 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("för 3 veckor sedan", t.format(new Date(0)));
- }
- @Test
- public void testMonthsAgo() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale);
- assertEquals("för 3 mĺnader sedan", t.format(new Date(0)));
- }
- @Test
- public void testYearsAgo() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale);
- assertEquals("för 3 ĺr sedan", t.format(new Date(0)));
- }
- @Test
- public void testDecadesAgo() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale);
- assertEquals("för 3 ĺrtionden sedan", t.format(new Date(0)));
- }
- @Test
- public void testCenturiesAgo() throws Exception
- {
- PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale);
- assertEquals("för 3 ĺrhundraden sedan", t.format(new Date(0)));
- }
- }