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     * @param source A <code>String</code> whose beginning should be parsed. 
035     * @return A <code>Date</code> parsed from the string
036     * @throws ParseException if the beginning of the specified string cannot be parsed.
037     */
038    Date parse(String source) throws ParseException;
039
040    /**
041     * Equivalent to DateFormat.parse(String, ParsePosition). 
042     * 
043     * See {@link java.text.DateFormat#parse(String, ParsePosition)} for more information. 
044     * 
045     * @param source A <code>String</code>, part of which should be parsed.
046     * @param pos A <code>ParsePosition</code> object with index and error index information 
047     * 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     * <p>Get the pattern used by this parser.</p>
057     * 
058     * @return the pattern, {@link java.text.SimpleDateFormat} compatible
059     */
060    String getPattern();
061
062    /**
063     * <p>
064     * Get the time zone used by this parser.
065     * </p>
066     * 
067     * <p>
068     * The default {@link TimeZone} used to create a {@link Date} when the {@link TimeZone} is not specified by
069     * the format pattern.
070     * </p>
071     * 
072     * @return the time zone
073     */
074    TimeZone getTimeZone();
075
076    /**
077     * <p>Get the locale used by this parser.</p>
078     * 
079     * @return the locale
080     */
081    Locale getLocale();
082
083    /**
084     * Parses text from a string to produce a Date.
085     * 
086     * @param source A <code>String</code> whose beginning should be parsed.
087     * @return a <code>java.util.Date</code> object
088     * @throws ParseException if the beginning of the specified string cannot be parsed.
089     * @see java.text.DateFormat#parseObject(String) 
090     */
091    Object parseObject(String source) throws ParseException;
092
093    /**
094     * Parse a date/time string according to the given parse position.
095     * 
096     * @param source A <code>String</code> whose beginning should be parsed.
097     * @param pos the parse position
098     * @return a <code>java.util.Date</code> object
099     * @see java.text.DateFormat#parseObject(String, ParsePosition) 
100     */
101    Object parseObject(String source, ParsePosition pos);
102}