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 * @param source A <code>String</code> whose beginning should be parsed. 35 * @return A <code>Date</code> parsed from the string 36 * @throws ParseException if the beginning of the specified string cannot be parsed. 37 */ 38 Date parse(String source) throws ParseException; 39 40 /** 41 * Equivalent to DateFormat.parse(String, ParsePosition). 42 * 43 * See {@link java.text.DateFormat#parse(String, ParsePosition)} for more information. 44 * 45 * @param source A <code>String</code>, part of which should be parsed. 46 * @param pos A <code>ParsePosition</code> object with index and error index information 47 * 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 * <p>Get the pattern used by this parser.</p> 57 * 58 * @return the pattern, {@link java.text.SimpleDateFormat} compatible 59 */ 60 String getPattern(); 61 62 /** 63 * <p> 64 * Get the time zone used by this parser. 65 * </p> 66 * 67 * <p> 68 * The default {@link TimeZone} used to create a {@link Date} when the {@link TimeZone} is not specified by 69 * the format pattern. 70 * </p> 71 * 72 * @return the time zone 73 */ 74 TimeZone getTimeZone(); 75 76 /** 77 * <p>Get the locale used by this parser.</p> 78 * 79 * @return the locale 80 */ 81 Locale getLocale(); 82 83 /** 84 * Parses text from a string to produce a Date. 85 * 86 * @param source A <code>String</code> whose beginning should be parsed. 87 * @return a <code>java.util.Date</code> object 88 * @throws ParseException if the beginning of the specified string cannot be parsed. 89 * @see java.text.DateFormat#parseObject(String) 90 */ 91 Object parseObject(String source) throws ParseException; 92 93 /** 94 * Parse a date/time string according to the given parse position. 95 * 96 * @param source A <code>String</code> whose beginning should be parsed. 97 * @param pos the parse position 98 * @return a <code>java.util.Date</code> object 99 * @see java.text.DateFormat#parseObject(String, ParsePosition) 100 */ 101 Object parseObject(String source, ParsePosition pos); 102 }