001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache license, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the license for the specific language governing permissions and
015 * limitations under the license.
016 */
017package org.apache.logging.log4j.core.util.datetime;
018
019import java.text.ParseException;
020import java.text.ParsePosition;
021import java.util.Date;
022import java.util.Locale;
023import java.util.TimeZone;
024
025/**
026 * Copied from Commons Lang 3.
027 */
028public interface DateParser {
029
030    /**
031     * Equivalent to DateFormat.parse(String).
032     * 
033     * See {@link java.text.DateFormat#parse(String)} for more information.
034     * 
035     * @param source A <code>String</code> whose beginning should be parsed.
036     * @return A <code>Date</code> parsed from the string
037     * @throws ParseException if the beginning of the specified string cannot be parsed.
038     */
039    Date parse(String source) throws ParseException;
040
041    /**
042     * Equivalent to DateFormat.parse(String, ParsePosition).
043     * 
044     * See {@link java.text.DateFormat#parse(String, ParsePosition)} for more information.
045     * 
046     * @param source A <code>String</code>, part of which should be parsed.
047     * @param pos A <code>ParsePosition</code> object with index and error index information as described above.
048     * @return A <code>Date</code> parsed from the string. In case of error, returns null.
049     * @throws NullPointerException if text or pos is null.
050     */
051    Date parse(String source, ParsePosition pos);
052
053    // Accessors
054    // -----------------------------------------------------------------------
055    /**
056     * Get the pattern used by this parser.
057     * 
058     * @return the pattern, {@link java.text.SimpleDateFormat} compatible
059     */
060    String getPattern();
061
062    /**
063     * Get the time zone used by this parser.
064     * 
065     * <p>
066     * The default {@link TimeZone} used to create a {@link Date} when the {@link TimeZone} is not specified by the
067     * format pattern.
068     * </p>
069     * 
070     * @return the time zone
071     */
072    TimeZone getTimeZone();
073
074    /**
075     * Get the locale used by this parser.
076     * 
077     * @return the locale
078     */
079    Locale getLocale();
080
081    /**
082     * Parses text from a string to produce a Date.
083     * 
084     * @param source A <code>String</code> whose beginning should be parsed.
085     * @return a <code>java.util.Date</code> object
086     * @throws ParseException if the beginning of the specified string cannot be parsed.
087     * @see java.text.DateFormat#parseObject(String)
088     */
089    Object parseObject(String source) throws ParseException;
090
091    /**
092     * Parse a date/time string according to the given parse position.
093     * 
094     * @param source A <code>String</code> whose beginning should be parsed.
095     * @param pos the parse position
096     * @return a <code>java.util.Date</code> object
097     * @see java.text.DateFormat#parseObject(String, ParsePosition)
098     */
099    Object parseObject(String source, ParsePosition pos);
100}