Curt,

At 10:26 PM 12/20/2004, Ceki Gülcü wrote:

As invoked earlier, I think CachedDateFormat may fail for certain
patterns at certain dates. If we can recognize the limited number of
formats for which it fails (if it does) and sidestep those, then
fine. Before going any further, do you agree that patterns causing
CachedDateFormat to fail exist and that it's just not me making things
up?

I had predicted the following would produce incorrect results.

import org.apache.log4j.*;
import org.apache.log4j.helpers.*;
import java.text.*;
import java.util.*;

public class CDF {

  protected static FieldPosition pos = new FieldPosition(0);

  public static void main(String[] args) throws Exception {

    SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MMMM-dd HH:mm:ss,SSS");
    CachedDateFormat cdf1 = new CachedDateFormat(sdf1);
    StringBuffer buf = new StringBuffer();

    Calendar c = Calendar.getInstance();
    c.set(2004, Calendar.DECEMBER, 12, 20, 0);

    cdf1.format(c.getTime(), buf, pos);
    System.out.println(buf.toString());
    buf.setLength(0);

    cdf1.format(c.getTime(), buf, pos);
    System.out.println(buf.toString());
    buf.setLength(0);

    c.set(2005, Calendar.JANUARY, 1, 0, 0);

    cdf1.format(c.getTime(), buf, pos);
    System.out.println(buf.toString());
    buf.setLength(0);

    cdf1.format(c.getTime(), buf, pos);
    System.out.println(buf.toString());

  }
}

Instead, it produces

2004-December-12 20:00:11,200
2004-December-12 20:00:11,200
2005-January-01 00:00:11,200
2005-January-01 00:00:11,200

which is correct. So much for my predictions.


-- Ceki Gülcü

  The complete log4j manual: http://qos.ch/log4j/



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to