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 21 package org.apache.mailet.base; 22 23 import java.text.ParseException; 24 import java.util.Date; 25 import java.util.TimeZone; 26 27 /** 28 * <p>This interface is designed to provide a simplified subset of the 29 * methods provided by the <code>java.text.DateFormat</code> class.</p> 30 * 31 * <p>This interface is necessary because of the difficulty in writing 32 * thread safe classes that inherit from <code>java.text.DateFormat</code>. 33 * This difficulty leads us to approach the problem using composition 34 * rather than inheritance. In general classes that implement this 35 * interface will delegate these calls to an internal DateFormat object.</p> 36 * 37 */ 38 public interface SimplifiedDateFormat { 39 40 /** 41 * Formats a Date into a date/time string. 42 * @param d the time value to be formatted into a time string. 43 * @return the formatted time string. 44 */ 45 public String format(Date d); 46 47 /** 48 * Parses text from the beginning of the given string to produce a date. 49 * The method may not use the entire text of the given string. 50 * 51 * @param source A <code>String</code> whose beginning should be parsed. 52 * @return A <code>Date</code> parsed from the string. 53 * @throws ParseException if the beginning of the specified string 54 * cannot be parsed. 55 */ 56 public Date parse(String source) throws ParseException; 57 58 /** 59 * Sets the time zone of this SimplifiedDateFormat object. 60 * @param zone the given new time zone. 61 */ 62 public void setTimeZone(TimeZone zone); 63 64 /** 65 * Gets the time zone. 66 * @return the time zone associated with this SimplifiedDateFormat. 67 */ 68 public TimeZone getTimeZone(); 69 70 /** 71 * Specify whether or not date/time parsing is to be lenient. With 72 * lenient parsing, the parser may use heuristics to interpret inputs that 73 * do not precisely match this object's format. With strict parsing, 74 * inputs must match this object's format. 75 * @param lenient when true, parsing is lenient 76 * @see java.util.Calendar#setLenient 77 */ 78 public void setLenient(boolean lenient); 79 80 /** 81 * Tell whether date/time parsing is to be lenient. 82 * @return whether this SimplifiedDateFormat is lenient. 83 */ 84 public boolean isLenient(); 85 } 86