コード例 #1
0
 @Test
 public void testCeilingInterval() throws Exception {
   Date then = format.parse("5/20/2009");
   Date ref = format.parse("6/17/2009");
   PrettyTime t = new PrettyTime(ref);
   assertEquals("1 month ago", t.format(then));
 }
コード例 #2
0
 @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 maand geleden", t.format(then));
 }
コード例 #3
0
  @Test
  public void testPrettyTimeCenturies() {
    PrettyTime p = new PrettyTime(new Date(3155692597470L * 3L), locale);
    assertEquals("3 eeuwen geleden", p.format(new Date(0)));

    p = new PrettyTime(new Date(0), locale);
    assertEquals("over 3 eeuwen", p.format(new Date(3155692597470L * 3L)));
  }
コード例 #4
0
  @Test
  public void testCustomFormat() throws Exception {
    PrettyTime t = new PrettyTime(new Date(0));
    t.setUnits(
        new TimeUnit() {

          public TimeFormat getFormat() {
            return new BasicTimeFormat()
                .setPattern("%n %u")
                .setRoundingTolerance(20)
                .setFutureSuffix("... RUN!")
                .setFuturePrefix("self destruct in: ")
                .setPastPrefix("self destruct was: ")
                .setPastSuffix(" ago...");
          }

          public long getMaxQuantity() {
            return 0;
          }

          public long getMillisPerUnit() {
            return 5000;
          }

          public String getName() {
            return "tick";
          }

          public String getPluralName() {
            return "ticks";
          }
        });
    assertEquals("self destruct in: 5 ticks ... RUN!", t.format(new Date(25000)));
    t.setReference(new Date(25000));
    assertEquals("self destruct was: 5 ticks ago...", t.format(new Date(0)));
  }
コード例 #5
0
 @Test
 public void testDaysAgo() throws Exception {
   PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3));
   assertEquals("3 days ago", t.format(new Date(0)));
 }
コード例 #6
0
 @Test
 public void testMinutesFromNow() throws Exception {
   PrettyTime t = new PrettyTime(new Date(0), locale);
   assertEquals("over 12 minuten", t.format(new Date(1000 * 60 * 12)));
 }
コード例 #7
0
 @Test
 public void testNullDate() throws Exception {
   PrettyTime t = new PrettyTime(locale);
   Date date = null;
   assertEquals("op dit moment", t.format(date));
 }
コード例 #8
0
 @Test
 public void testCenturiesAgo() throws Exception {
   PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale);
   assertEquals("3 eeuwen geleden", t.format(new Date(0)));
 }
コード例 #9
0
 @Test
 public void testYearsAgo() throws Exception {
   PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale);
   assertEquals("3 jaar geleden", t.format(new Date(0)));
 }
コード例 #10
0
 @Test
 public void testWeeksAgo() throws Exception {
   PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale);
   assertEquals("3 weken geleden", t.format(new Date(0)));
 }
コード例 #11
0
 @Test
 public void testWeeksFromNow() throws Exception {
   PrettyTime t = new PrettyTime(new Date(0));
   assertEquals("3 weeks from now", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3)));
 }
コード例 #12
0
 @Test
 public void testRightNowVariance() throws Exception {
   PrettyTime t = new PrettyTime(new Date(0));
   assertEquals("moments from now", t.format(new Date(600)));
 }
コード例 #13
0
 @Test
 public void testNullDate() throws Exception {
   PrettyTime t = new PrettyTime();
   Date date = null;
   assertEquals("moments from now", t.format(date));
 }
コード例 #14
0
 @Test
 public void testWithinTwoHoursRounding() throws Exception {
   PrettyTime t = new PrettyTime();
   assertEquals("2 hours ago", t.format(new Date(new Date().getTime() - 6543990)));
 }
コード例 #15
0
 @Test
 public void testMonthsAgo() throws Exception {
   PrettyTime t = new PrettyTime(new Date(2629743830L * 3L));
   assertEquals("3 months ago", t.format(new Date(0)));
 }
コード例 #16
0
 @Test
 public void testMinutesAgo() throws Exception {
   PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale);
   assertEquals("12 minuten geleden", t.format(new Date(0)));
 }
コード例 #17
0
 @Test
 public void testHoursAgo() throws Exception {
   PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale);
   assertEquals("3 uur geleden", t.format(new Date(0)));
 }
コード例 #18
0
 @Test
 public void testYearsFromNow() throws Exception {
   PrettyTime t = new PrettyTime(new Date(0));
   assertEquals("3 years from now", t.format(new Date(2629743830L * 12L * 3L)));
 }
コード例 #19
0
 @Test
 public void testMonthsAgo() throws Exception {
   PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale);
   assertEquals("3 maanden geleden", t.format(new Date(0)));
 }
コード例 #20
0
 @Test
 public void testCenturiesFromNow() throws Exception {
   PrettyTime t = new PrettyTime(new Date(0));
   assertEquals("3 centuries from now", t.format(new Date(3155692597470L * 3L)));
 }
コード例 #21
0
 @Test
 public void testDecadesAgo() throws Exception {
   PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale);
   assertEquals("3 decennia geleden", t.format(new Date(0)));
 }
コード例 #22
0
 @Test
 public void testMonthsFromNow() throws Exception {
   PrettyTime t = new PrettyTime(new Date(0), locale);
   assertEquals("over 3 maanden", t.format(new Date(2629743830L * 3L)));
 }
コード例 #23
0
 @Test
 public void testPrettyTime() {
   PrettyTime p = new PrettyTime(locale);
   assertEquals(p.format(new Date()), "op dit moment");
 }
コード例 #24
0
 @Test
 public void testYearsFromNow() throws Exception {
   PrettyTime t = new PrettyTime(new Date(0), locale);
   assertEquals("over 3 jaar", t.format(new Date(2629743830L * 12L * 3L)));
 }
コード例 #25
0
 @Test
 public void testDecadesFromNow() throws Exception {
   PrettyTime t = new PrettyTime(new Date(0), locale);
   assertEquals("over 3 decennia", t.format(new Date(315569259747L * 3L)));
 }
コード例 #26
0
 @Test
 public void testCenturiesFromNow() throws Exception {
   PrettyTime t = new PrettyTime(new Date(0), locale);
   assertEquals("over 3 eeuwen", t.format(new Date(3155692597470L * 3L)));
 }
コード例 #27
0
 @Test
 public void testRightNowVariance() throws Exception {
   PrettyTime t = new PrettyTime(new Date(0), locale);
   assertEquals("op dit moment", t.format(new Date(600)));
 }
コード例 #28
0
 /*
  * Past
  */
 @Test
 public void testMomentsAgo() throws Exception {
   PrettyTime t = new PrettyTime(new Date(6000), locale);
   assertEquals("een ogenblik geleden", t.format(new Date(0)));
 }
コード例 #29
0
 @Test
 public void testDaysFromNow() throws Exception {
   PrettyTime t = new PrettyTime(new Date(0), locale);
   assertEquals("over 3 dagen", t.format(new Date(1000 * 60 * 60 * 24 * 3)));
 }
コード例 #30
0
 /*
  * Past
  */
 @Test
 public void testMomentsAgo() throws Exception {
   PrettyTime t = new PrettyTime(new Date(6000));
   assertEquals("moments ago", t.format(new Date(0)));
 }