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