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 LocalDateTime to a String. 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 FmtLocalDateTime extends AbstractTemporalAccessorFormattingProcessor<LocalDateTime> { 39 40 /** 41 * Constructs a new <tt>FmtLocalDateTime</tt> processor, which formats a 42 * LocalDateTime as a String. 43 * 44 * The format is the same as obtained by {@link LocalDateTime#toString()} 45 */ 46 public FmtLocalDateTime() { 47 super(); 48 } 49 50 /** 51 * Constructs a new <tt>FmtLocalDateTime</tt> processor, which formats a 52 * LocalDateTime as a String, then calls the next processor in the 53 * chain. 54 * 55 * @param next next processor in the chain 56 * @throws NullPointerException if next is null 57 */ 58 public FmtLocalDateTime(final CellProcessor next) { 59 super(next); 60 } 61 62 /** 63 * Constructs a new <tt>FmtLocalDateTime</tt> processor, which formats a 64 * LocalDateTime as a String using the supplied formatter. 65 * 66 * @param formatter the formatter to use 67 * @throws NullPointerException if formatter is null 68 */ 69 public FmtLocalDateTime(final DateTimeFormatter formatter) { 70 super(formatter); 71 } 72 73 /** 74 * Constructs a new <tt>FmtLocalDateTime</tt> processor, which formats a 75 * LocalDateTime as a String using the supplied formatter, then calls 76 * the next processor in the chain. 77 * 78 * @param formatter the formatter to use 79 * @param next the next processor in the chain 80 * @throws NullPointerException if formatter or next is null 81 */ 82 public FmtLocalDateTime(final DateTimeFormatter formatter, final CellProcessor next) { 83 super(formatter, next); 84 } 85 86 @Override 87 protected Class<LocalDateTime> getType() { 88 return LocalDateTime.class; 89 } 90 }