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