FileDocCategorySizeDatePackage
DateTool.javaAPI DocGlassfish v2 API6106Fri May 04 22:33:14 BST 2007org.apache.tomcat.util.buf

DateTool

public class DateTool extends Object
Common place for date utils.
deprecated
Will be replaced with a more efficient impl, based on FastDateFormat, with an API using less objects.
author
dac@eng.sun.com
author
Jason Hunter [jch@eng.sun.com]
author
James Todd [gonzo@eng.sun.com]
author
Costin Manolache

Fields Summary
private static final Locale
LOCALE_US
US locale - all HTTP dates are in english
public static final TimeZone
GMT_ZONE
GMT timezone - all HTTP dates are on GMT
public static final String
RFC1123_PATTERN
format for RFC 1123 date string -- "Sun, 06 Nov 1994 08:49:37 GMT"
public static final String
rfc1036Pattern
public static final String
asctimePattern
private static final String
OLD_COOKIE_PATTERN
Pattern used for old cookies
private static final DateFormat
rfc1123Format
DateFormat to be used to format dates. Called from MessageBytes
private static final DateFormat
oldCookieFormat
DateFormat to be used to format old netscape cookies Called from ServerCookie
private static final DateFormat
rfc1036Format
private static final DateFormat
asctimeFormat
private static String
rfc1123DS
private static long
rfc1123Sec
private static org.apache.tomcat.util.res.StringManager
sm
Constructors Summary
Methods Summary
public static java.lang.Stringformat1123(java.util.Date d)

	String dstr=null;
	synchronized(rfc1123Format) {
	    dstr = format1123(d, rfc1123Format);
	}
	return dstr;
    
public static java.lang.Stringformat1123(java.util.Date d, java.text.DateFormat df)

        long dt = d.getTime() / 1000;
        if ((rfc1123DS != null) && (dt == rfc1123Sec))
            return rfc1123DS;
        rfc1123DS  = df.format( d );
        rfc1123Sec = dt;
        return rfc1123DS;
    
public static voidformatOldCookie(java.util.Date d, java.lang.StringBuffer sb, java.text.FieldPosition fp)

	synchronized(oldCookieFormat) {
	    oldCookieFormat.format( d, sb, fp );
	}
    
public static java.lang.StringformatOldCookie(java.util.Date d)

	String ocf=null;
	synchronized(oldCookieFormat) {
	    ocf= oldCookieFormat.format( d );
	}
	return ocf;
    
static longparseDate(MessageBytes value)


    // Called from MessageBytes.getTime()
          
     	return parseDate( value.toString());
    
public static longparseDate(java.lang.String dateString)
Called from HttpServletRequest.getDateHeader(). Not efficient - but not very used.

	DateFormat [] format = {rfc1123Format,rfc1036Format,asctimeFormat};
	return parseDate(dateString,format);
    
public static longparseDate(java.lang.String dateString, java.text.DateFormat[] format)

	Date date=null;
	for(int i=0; i < format.length; i++) {
	    try {
		date = format[i].parse(dateString);
		return date.getTime();
	    } catch (ParseException e) { }
	    catch (StringIndexOutOfBoundsException e) { }
	}
	String msg = sm.getString("httpDate.pe", dateString);
	throw new IllegalArgumentException(msg);