001 /****************************************************************
002 * Licensed to the Apache Software Foundation (ASF) under one *
003 * or more contributor license agreements. See the NOTICE file *
004 * distributed with this work for additional information *
005 * regarding copyright ownership. The ASF licenses this file *
006 * to you under the Apache License, Version 2.0 (the *
007 * "License"); you may not use this file except in compliance *
008 * with the License. You may obtain a copy of the License at *
009 * *
010 * http://www.apache.org/licenses/LICENSE-2.0 *
011 * *
012 * Unless required by applicable law or agreed to in writing, *
013 * software distributed under the License is distributed on an *
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
015 * KIND, either express or implied. See the License for the *
016 * specific language governing permissions and limitations *
017 * under the License. *
018 ****************************************************************/
019
020
021 package org.apache.mailet.base;
022
023 import java.text.ParseException;
024 import java.util.Date;
025 import java.util.TimeZone;
026
027 /**
028 * <p>This interface is designed to provide a simplified subset of the
029 * methods provided by the <code>java.text.DateFormat</code> class.</p>
030 *
031 * <p>This interface is necessary because of the difficulty in writing
032 * thread safe classes that inherit from <code>java.text.DateFormat</code>.
033 * This difficulty leads us to approach the problem using composition
034 * rather than inheritance. In general classes that implement this
035 * interface will delegate these calls to an internal DateFormat object.</p>
036 *
037 */
038 public interface SimplifiedDateFormat {
039
040 /**
041 * Formats a Date into a date/time string.
042 * @param d the time value to be formatted into a time string.
043 * @return the formatted time string.
044 */
045 public String format(Date d);
046
047 /**
048 * Parses text from the beginning of the given string to produce a date.
049 * The method may not use the entire text of the given string.
050 *
051 * @param source A <code>String</code> whose beginning should be parsed.
052 * @return A <code>Date</code> parsed from the string.
053 * @throws ParseException if the beginning of the specified string
054 * cannot be parsed.
055 */
056 public Date parse(String source) throws ParseException;
057
058 /**
059 * Sets the time zone of this SimplifiedDateFormat object.
060 * @param zone the given new time zone.
061 */
062 public void setTimeZone(TimeZone zone);
063
064 /**
065 * Gets the time zone.
066 * @return the time zone associated with this SimplifiedDateFormat.
067 */
068 public TimeZone getTimeZone();
069
070 /**
071 * Specify whether or not date/time parsing is to be lenient. With
072 * lenient parsing, the parser may use heuristics to interpret inputs that
073 * do not precisely match this object's format. With strict parsing,
074 * inputs must match this object's format.
075 * @param lenient when true, parsing is lenient
076 * @see java.util.Calendar#setLenient
077 */
078 public void setLenient(boolean lenient);
079
080 /**
081 * Tell whether date/time parsing is to be lenient.
082 * @return whether this SimplifiedDateFormat is lenient.
083 */
084 public boolean isLenient();
085 }
086