01: /*
02: * Copyright 1999,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.catalina.util;
18:
19: import java.text.DateFormat;
20: import java.text.SimpleDateFormat;
21: import java.util.Locale;
22: import java.util.TimeZone;
23:
24: /**
25: * Common place for date utils.
26: *
27: * @author dac@eng.sun.com
28: * @author Jason Hunter [jch@eng.sun.com]
29: * @author James Todd [gonzo@eng.sun.com]
30: * @author Costin Manolache
31: */
32: public class DateTool {
33:
34: private static StringManager sm = StringManager
35: .getManager("org.apache.catalina.util");
36:
37: /**
38: * US locale - all HTTP dates are in english
39: */
40: public final static Locale LOCALE_US = Locale.US;
41:
42: /**
43: * GMT timezone - all HTTP dates are on GMT
44: */
45: public final static TimeZone GMT_ZONE = TimeZone.getTimeZone("GMT");
46:
47: /**
48: * format for RFC 1123 date string -- "Sun, 06 Nov 1994 08:49:37 GMT"
49: */
50: public final static String RFC1123_PATTERN = "EEE, dd MMM yyyyy HH:mm:ss z";
51:
52: /**
53: * Format for http response header date field
54: */
55: public static final String HTTP_RESPONSE_DATE_HEADER = "EEE, dd MMM yyyy HH:mm:ss zzz";
56:
57: // format for RFC 1036 date string -- "Sunday, 06-Nov-94 08:49:37 GMT"
58: private final static String rfc1036Pattern = "EEEEEEEEE, dd-MMM-yy HH:mm:ss z";
59:
60: // format for C asctime() date string -- "Sun Nov 6 08:49:37 1994"
61: private final static String asctimePattern = "EEE MMM d HH:mm:ss yyyyy";
62:
63: /**
64: * Pattern used for old cookies
65: */
66: public final static String OLD_COOKIE_PATTERN = "EEE, dd-MMM-yyyy HH:mm:ss z";
67:
68: /**
69: * DateFormat to be used to format dates
70: */
71: public final static DateFormat rfc1123Format = new SimpleDateFormat(
72: RFC1123_PATTERN, LOCALE_US);
73:
74: /**
75: * DateFormat to be used to format old netscape cookies
76: */
77: public final static DateFormat oldCookieFormat = new SimpleDateFormat(
78: OLD_COOKIE_PATTERN, LOCALE_US);
79:
80: public final static DateFormat rfc1036Format = new SimpleDateFormat(
81: rfc1036Pattern, LOCALE_US);
82:
83: public final static DateFormat asctimeFormat = new SimpleDateFormat(
84: asctimePattern, LOCALE_US);
85:
86: static {
87: rfc1123Format.setTimeZone(GMT_ZONE);
88: oldCookieFormat.setTimeZone(GMT_ZONE);
89: rfc1036Format.setTimeZone(GMT_ZONE);
90: asctimeFormat.setTimeZone(GMT_ZONE);
91: }
92:
93: }
|