1 /************************************************************************
2 * Copyright (c) 2000-2006 The Apache Software Foundation. *
3 * All rights reserved. *
4 * ------------------------------------------------------------------- *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you *
6 * may not use this file except in compliance with the License. You *
7 * may obtain a copy of the License at: *
8 * *
9 * 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 *
14 * implied. See the License for the specific language governing *
15 * permissions and limitations under the License. *
16 ***********************************************************************/
17
18 package org.apache.mailet.dates;
19
20 import java.text.ParseException;
21 import java.util.Date;
22 import java.util.TimeZone;
23
24 /***
25 * <p>This interface is designed to provide a simplified subset of the
26 * methods provided by the <code>java.text.DateFormat</code> class.</p>
27 *
28 * <p>This interface is necessary because of the difficulty in writing
29 * thread safe classes that inherit from <code>java.text.DateFormat</code>.
30 * This difficulty leads us to approach the problem using composition
31 * rather than inheritance. In general classes that implement this
32 * interface will delegate these calls to an internal DateFormat object.</p>
33 *
34 */
35 public interface SimplifiedDateFormat {
36
37 /***
38 * Formats a Date into a date/time string.
39 * @param date the time value to be formatted into a time string.
40 * @return the formatted time string.
41 */
42 public String format(Date d);
43
44 /***
45 * Parses text from the beginning of the given string to produce a date.
46 * The method may not use the entire text of the given string.
47 *
48 * @param source A <code>String</code> whose beginning should be parsed.
49 * @return A <code>Date</code> parsed from the string.
50 * @throws ParseException if the beginning of the specified string
51 * cannot be parsed.
52 */
53 public Date parse(String source) throws ParseException;
54
55 /***
56 * Sets the time zone of this SimplifiedDateFormat object.
57 * @param zone the given new time zone.
58 */
59 public void setTimeZone(TimeZone zone);
60
61 /***
62 * Gets the time zone.
63 * @return the time zone associated with this SimplifiedDateFormat.
64 */
65 public TimeZone getTimeZone();
66
67 /***
68 * Specify whether or not date/time parsing is to be lenient. With
69 * lenient parsing, the parser may use heuristics to interpret inputs that
70 * do not precisely match this object's format. With strict parsing,
71 * inputs must match this object's format.
72 * @param lenient when true, parsing is lenient
73 * @see java.util.Calendar#setLenient
74 */
75 public void setLenient(boolean lenient);
76
77 /***
78 * Tell whether date/time parsing is to be lenient.
79 * @return whether this SimplifiedDateFormat is lenient.
80 */
81 public boolean isLenient();
82 }
83