View Javadoc
1   /*
2    * Copyright 2007 Kasper B. Graversen
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.supercsv.cellprocessor.joda;
17  
18  import org.joda.time.DateTime;
19  import org.joda.time.format.DateTimeFormat;
20  import org.joda.time.format.DateTimeFormatter;
21  import org.joda.time.format.DateTimeFormatterBuilder;
22  import org.joda.time.format.ISODateTimeFormat;
23  import org.supercsv.cellprocessor.ift.CellProcessor;
24  
25  /**
26   * Converts a String to a Joda DateTime.
27   * 
28   * <p>
29   * For constructors using DateTimeFormatter, refer to the following Joda
30   * classes:
31   * <ul>
32   * <li>{@link DateTimeFormat} - formats by pattern and style</li>
33   * <li>{@link ISODateTimeFormat} - ISO8601 formats</li>
34   * <li>{@link DateTimeFormatterBuilder} - complex formats created via method
35   * calls</li>
36   * </ul>
37   * <p>
38   * For constructors using date format Strings, refer to {@link DateTimeFormat}
39   * for example formats.
40   * 
41   * @since 2.3.0
42   * @author James Bassett
43   */
44  public class ParseDateTime extends AbstractJodaParsingProcessor<DateTime> {
45  
46  	/**
47  	 * Constructs a new <tt>ParseDateTime</tt> processor, which parses a String
48  	 * as a Joda DateTime.
49  	 */
50  	public ParseDateTime() {
51  	}
52  
53  	/**
54  	 * Constructs a new <tt>ParseDateTime</tt> processor, which parses a String
55  	 * as a Joda DateTime, then calls the next processor in the chain.
56  	 * 
57  	 * @param next
58  	 *            the next processor in the chain
59  	 * @throws NullPointerException
60  	 *             if next is null
61  	 */
62  	public ParseDateTime(final CellProcessor next) {
63  		super(next);
64  	}
65  
66  	/**
67  	 * Constructs a new <tt>ParseDateTime</tt> processor, which parses a String
68  	 * as a Joda DateTime using the supplied formatter.
69  	 * 
70  	 * @param formatter
71  	 *            the formatter used for parsing
72  	 * @throws NullPointerException
73  	 *             if formatter is null
74  	 */
75  	public ParseDateTime(final DateTimeFormatter formatter) {
76  		super(formatter);
77  	}
78  
79  	/**
80  	 * Constructs a new <tt>ParseDateTime</tt> processor, which parses a String
81  	 * as a Joda DateTime using the supplied formatter, then calls the next
82  	 * processor in the chain.
83  	 * 
84  	 * @param formatter
85  	 *            the formatter used for parsing
86  	 * @param next
87  	 *            the next processor in the chain
88  	 * @throws NullPointerException
89  	 *             if formatter or next is null
90  	 */
91  	public ParseDateTime(final DateTimeFormatter formatter,
92  			final CellProcessor next) {
93  		super(formatter, next);
94  	}
95  
96  	/**
97  	 * {@inheritDoc}
98  	 */
99  	@Override
100 	protected DateTime parse(final String string) {
101 		return DateTime.parse(string);
102 	}
103 
104 	/**
105 	 * {@inheritDoc}
106 	 */
107 	@Override
108 	protected DateTime parse(final String string, final DateTimeFormatter formatter) {
109 		return DateTime.parse(string, formatter);
110 	}
111 
112 }