Package org.apache.log4j.pattern

Examples of org.apache.log4j.pattern.CachedDateFormat


   * Test of caching when less than three millisecond digits are specified.
   */
  public void test9() {
    // (Note: 'Z' is JDK 1.4, using 'z' instead.)
    DateFormat baseFormat = new SimpleDateFormat("yyyy-MMMM-dd HH:mm:ss,SS z", Locale.US);
    DateFormat cachedFormat = new CachedDateFormat(baseFormat, 1000);
    TimeZone cet = TimeZone.getTimeZone("GMT+1");
    cachedFormat.setTimeZone(cet);
   
    Calendar c = Calendar.getInstance();
    c.set(2004, Calendar.DECEMBER, 12, 20, 0);
    c.set(Calendar.SECOND, 37);
    c.set(Calendar.MILLISECOND, 23);
    c.setTimeZone(cet);

    String s = cachedFormat.format(c.getTime());
    assertEquals("2004-December-12 20:00:37,23 GMT+01:00", s);

    c.set(2005, Calendar.JANUARY, 1, 0, 0);
    c.set(Calendar.SECOND, 13);
    c.set(Calendar.MILLISECOND, 905);

    s = cachedFormat.format(c.getTime());
    assertEquals("2005-January-01 00:00:13,905 GMT+01:00", s);
  }
View Full Code Here


  /**
   * Test when millisecond position moves but length remains constant.
   */
  public void test10() {
    DateFormat baseFormat = new SimpleDateFormat("MMMM SSS EEEEEE", Locale.US);
    DateFormat cachedFormat = new CachedDateFormat(baseFormat, 1000);
    TimeZone cet = TimeZone.getTimeZone("GMT+1");
    cachedFormat.setTimeZone(cet);
   
    Calendar c = Calendar.getInstance();
    c.set(2004, Calendar.OCTOBER, 5, 20, 0);
    c.set(Calendar.SECOND, 37);
    c.set(Calendar.MILLISECOND, 23);
    c.setTimeZone(cet);

    String s = cachedFormat.format(c.getTime());
    assertEquals("October 023 Tuesday", s);

    c.set(2004, Calendar.NOVEMBER, 1, 0, 0);
    c.set(Calendar.MILLISECOND, 23);
    s = cachedFormat.format(c.getTime());
    assertEquals("November 023 Monday", s);


    c.set(Calendar.MILLISECOND, 984);
    s = cachedFormat.format(c.getTime());
    assertEquals("November 984 Monday", s);
  }
View Full Code Here

     //
     //   Earlier versions could be tricked by "SS0" patterns.
     //
     String badPattern = "ss,SS0";
     SimpleDateFormat simpleFormat = new SimpleDateFormat(badPattern);
     DateFormat gmtFormat = new CachedDateFormat(simpleFormat, 1000);
     gmtFormat.setTimeZone(GMT);

     //
     // The first request has to 100 ms after an ordinal second
     //    to push the literal zero out of the pattern check
     long ticks = 11142L * 86400000L;
     Date jul2 = new Date(ticks + 120);
     assertEquals("00,1200", gmtFormat.format(jul2));
     jul2.setTime(ticks + 87);
    

     //
     //   Cache gives 00,087
     assertEquals("00,870", gmtFormat.format(jul2));

  }
View Full Code Here

  public void test17() {
      Date jul2 = new Date(12602L * 86400000L);
      String badPattern = "HH:mm:ss,SSS HH:mm:ss,SSS";
      SimpleDateFormat simpleFormat = new SimpleDateFormat(badPattern);
      simpleFormat.setTimeZone(GMT);
      DateFormat cachedFormat = new CachedDateFormat(simpleFormat, 1000);
      String s = cachedFormat.format(jul2);
      assertEquals("00:00:00,000 00:00:00,000", s);
      jul2.setTime(jul2.getTime() + 120);
      assertEquals("00:00:00,120 00:00:00,120", simpleFormat.format(jul2));
      s = cachedFormat.format(jul2);
      //
      //  TODO: why is this returning ,120 ... , 120
      //
      //assertEquals("00:00:00,120 00:00:00,000", s) ;
     
View Full Code Here

TOP

Related Classes of org.apache.log4j.pattern.CachedDateFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.