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.ZonedDateTime; 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 ZonedDateTime. 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 ParseZonedDateTime extends AbstractTemporalAccessorParsingProcessor<ZonedDateTime> { 39 40 /** 41 * Constructs a new <tt>ParseZonedDateTime</tt> processor, which parses a String 42 * in the same format accepted by {@link ZonedDateTime#parse(CharSequence)} 43 * as a ZonedDateTime. 44 */ 45 public ParseZonedDateTime() { 46 super(); 47 } 48 49 /** 50 * Constructs a new <tt>ParseZonedDateTime</tt> processor, which parses a String 51 * as a ZonedDateTime, then calls the next processor in the chain. 52 * 53 * @param next the next processor in the chain 54 * @throws NullPointerException if next is null 55 * @see ParseZonedDateTime() 56 */ 57 public ParseZonedDateTime(final CellProcessor next) { 58 super(next); 59 } 60 61 /** 62 * Constructs a new <tt>ParseZonedDateTime</tt> processor, which parses a String 63 * as a ZonedDateTime using the supplied formatter. 64 * 65 * @param formatter the formatter used for parsing 66 * @throws NullPointerException if formatter is null 67 */ 68 public ParseZonedDateTime(final DateTimeFormatter formatter) { 69 super(formatter); 70 } 71 72 /** 73 * Constructs a new <tt>ParseZonedDateTime</tt> processor, which parses a String 74 * as a ZonedDateTime using the supplied formatter, then calls the next 75 * processor in the chain. 76 * 77 * @param formatter the formatter used for parsing 78 * @param next the next processor in the chain 79 * @throws NullPointerException if formatter or next is null 80 */ 81 public ParseZonedDateTime(final DateTimeFormatter formatter, final CellProcessor next) { 82 super(formatter, next); 83 } 84 85 /** 86 * {@inheritDoc} 87 */ 88 @Override 89 protected ZonedDateTime parse(final String string) { 90 return ZonedDateTime.parse(string); 91 } 92 93 /** 94 * {@inheritDoc} 95 */ 96 @Override 97 protected ZonedDateTime parse(final String string, final DateTimeFormatter formatter) { 98 return ZonedDateTime.parse(string, formatter); 99 } 100 101 }