View Javadoc
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.commons.lang3.time;
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   * <p>DateParser is the "missing" interface for the parsing methods of 
27   * {@link java.text.DateFormat}.</p>
28   * 
29   * @since 3.2
30   */
31  public interface DateParser {
32  
33      /**
34       * Equivalent to DateFormat.parse(String). 
35       * 
36       * See {@link java.text.DateFormat#parse(String)} for more information. 
37       * @param source A <code>String</code> whose beginning should be parsed. 
38       * @return A <code>Date</code> parsed from the string
39       * @throws ParseException if the beginning of the specified string cannot be parsed.
40       */
41      Date parse(String source) throws ParseException;
42  
43      /**
44       * Equivalent to DateFormat.parse(String, ParsePosition). 
45       * 
46       * See {@link java.text.DateFormat#parse(String, ParsePosition)} for more information. 
47       * 
48       * @param source A <code>String</code>, part of which should be parsed.
49       * @param pos A <code>ParsePosition</code> object with index and error index information 
50       * as described above. 
51       * @return A <code>Date</code> parsed from the string. In case of error, returns null. 
52       * @throws NullPointerException if text or pos is null.
53       */
54      Date parse(String source, ParsePosition pos);
55  
56      // Accessors
57      //-----------------------------------------------------------------------
58      /**
59       * <p>Get the pattern used by this parser.</p>
60       * 
61       * @return the pattern, {@link java.text.SimpleDateFormat} compatible
62       */
63      String getPattern();
64  
65      /**
66       * <p>
67       * Get the time zone used by this parser.
68       * </p>
69       * 
70       * <p>
71       * The default {@link TimeZone} used to create a {@link Date} when the {@link TimeZone} is not specified by
72       * the format pattern.
73       * </p>
74       * 
75       * @return the time zone
76       */
77      TimeZone getTimeZone();
78  
79      /**
80       * <p>Get the locale used by this parser.</p>
81       * 
82       * @return the locale
83       */
84      Locale getLocale();
85  
86      /**
87       * Parses text from a string to produce a Date.
88       * 
89       * @param source A <code>String</code> whose beginning should be parsed.
90       * @return a <code>java.util.Date</code> object
91       * @throws ParseException if the beginning of the specified string cannot be parsed.
92       * @see java.text.DateFormat#parseObject(String) 
93       */
94      Object parseObject(String source) throws ParseException;
95  
96      /**
97       * Parse a date/time string according to the given parse position.
98       * 
99       * @param source A <code>String</code> whose beginning should be parsed.
100      * @param pos the parse position
101      * @return a <code>java.util.Date</code> object
102      * @see java.text.DateFormat#parseObject(String, ParsePosition) 
103      */
104     Object parseObject(String source, ParsePosition pos);
105 }