1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache license, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the license for the specific language governing permissions and 15 * limitations under the license. 16 */ 17 package org.apache.logging.log4j.core.util.datetime; 18 19 import java.text.ParseException; 20 import java.text.ParsePosition; 21 import java.util.Date; 22 import java.util.Locale; 23 import java.util.TimeZone; 24 25 /** 26 * Copied from Commons Lang 3. 27 */ 28 public interface DateParser { 29 30 /** 31 * Equivalent to DateFormat.parse(String). 32 * 33 * See {@link java.text.DateFormat#parse(String)} for more information. 34 * 35 * @param source A <code>String</code> whose beginning should be parsed. 36 * @return A <code>Date</code> parsed from the string 37 * @throws ParseException if the beginning of the specified string cannot be parsed. 38 */ 39 Date parse(String source) throws ParseException; 40 41 /** 42 * Equivalent to DateFormat.parse(String, ParsePosition). 43 * 44 * See {@link java.text.DateFormat#parse(String, ParsePosition)} for more information. 45 * 46 * @param source A <code>String</code>, part of which should be parsed. 47 * @param pos A <code>ParsePosition</code> object with index and error index information as described above. 48 * @return A <code>Date</code> parsed from the string. In case of error, returns null. 49 * @throws NullPointerException if text or pos is null. 50 */ 51 Date parse(String source, ParsePosition pos); 52 53 // Accessors 54 // ----------------------------------------------------------------------- 55 /** 56 * Get the pattern used by this parser. 57 * 58 * @return the pattern, {@link java.text.SimpleDateFormat} compatible 59 */ 60 String getPattern(); 61 62 /** 63 * Get the time zone used by this parser. 64 * 65 * <p> 66 * The default {@link TimeZone} used to create a {@link Date} when the {@link TimeZone} is not specified by the 67 * format pattern. 68 * </p> 69 * 70 * @return the time zone 71 */ 72 TimeZone getTimeZone(); 73 74 /** 75 * Get the locale used by this parser. 76 * 77 * @return the locale 78 */ 79 Locale getLocale(); 80 81 /** 82 * Parses text from a string to produce a Date. 83 * 84 * @param source A <code>String</code> whose beginning should be parsed. 85 * @return a <code>java.util.Date</code> object 86 * @throws ParseException if the beginning of the specified string cannot be parsed. 87 * @see java.text.DateFormat#parseObject(String) 88 */ 89 Object parseObject(String source) throws ParseException; 90 91 /** 92 * Parse a date/time string according to the given parse position. 93 * 94 * @param source A <code>String</code> whose beginning should be parsed. 95 * @param pos the parse position 96 * @return a <code>java.util.Date</code> object 97 * @see java.text.DateFormat#parseObject(String, ParsePosition) 98 */ 99 Object parseObject(String source, ParsePosition pos); 100 }