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.time; 17 18 import java.time.LocalDateTime; 19 import java.time.format.DateTimeFormatter; 20 import java.time.format.DateTimeFormatterBuilder; 21 22 import org.supercsv.cellprocessor.ift.CellProcessor; 23 24 /** 25 * Converts a String to a LocalDateTime. 26 * For constructors using DateTimeFormatter, refer to the following 27 * classes: 28 * <ul> 29 * <li>{@link DateTimeFormatter} - formats by pattern and style</li> 30 * <li>{@link DateTimeFormatter} - ISO 8601 formats</li> 31 * <li>{@link DateTimeFormatterBuilder} - complex formats created via method 32 * calls</li> 33 * </ul> 34 * 35 * @author Ludovico Fischer 36 * @since 2.4.0 37 */ 38 public class ParseLocalDateTime extends AbstractTemporalAccessorParsingProcessor<LocalDateTime> { 39 40 /** 41 * Constructs a new <tt>ParseLocalDateTime</tt> processor, which parses a 42 * String as a LocalDateTime, using {@link LocalDateTime#parse(CharSequence)}. 43 */ 44 public ParseLocalDateTime() { 45 } 46 47 /** 48 * Constructs a new <tt>ParseLocalDateTime</tt> processor, which parses a 49 * String as a LocalDateTime, then calls the next processor in the 50 * chain. 51 * 52 * @param next the next processor in the chain 53 * @throws NullPointerException if next is null 54 */ 55 public ParseLocalDateTime(final CellProcessor next) { 56 super(next); 57 } 58 59 /** 60 * Constructs a new <tt>ParseLocalDateTime</tt> processor, which parses a 61 * String as a LocalDateTime using the supplied formatter. 62 * 63 * @param formatter the formatter used for parsing 64 * @throws NullPointerException if formatter is null 65 */ 66 public ParseLocalDateTime(final DateTimeFormatter formatter) { 67 super(formatter); 68 } 69 70 /** 71 * Constructs a new <tt>ParseLocalDateTime</tt> processor, which parses a 72 * String as a LocalDateTime using the supplied formatter, then calls 73 * the next processor in the chain. 74 * 75 * @param formatter the formatter used for parsing 76 * @param next the next processor in the chain 77 * @throws NullPointerException if formatter or next is null 78 */ 79 public ParseLocalDateTime(final DateTimeFormatter formatter, final CellProcessor next) { 80 super(formatter, next); 81 } 82 83 /** 84 * {@inheritDoc} 85 */ 86 @Override 87 protected LocalDateTime parse(final String string) { 88 return LocalDateTime.parse(string); 89 } 90 91 /** 92 * {@inheritDoc} 93 */ 94 @Override 95 protected LocalDateTime parse(final String string, final DateTimeFormatter formatter) { 96 return LocalDateTime.parse(string, formatter); 97 } 98 }