1 package org.apache.turbine.services.localization; 2 3 import java.time.format.DateTimeFormatter; 4 import java.time.temporal.TemporalAccessor; 5 import java.util.Locale; 6 7 public interface DateTimeFormatterInterface { 8 DateTimeFormatter getDefaultFormat(); 9 10 String getDateTimeFormatPattern(); 11 12 /** 13 * Formats the given datetime as a String with the #{@link DateTimeFormatterService#defaultFormat}. 14 * using the default date format. 15 * 16 * @param the {@link TemporalAccessor to format 17 * @return String value of the date 18 */ 19 <T extends TemporalAccessor> String format(T temporalAccessor); 20 21 /** 22 * Formats the given date as a String. 23 * 24 * @param the TimeDate date to format 25 * @param dateFormatString format string to use. See {@link DateTimeFormatter} 26 * for details. 27 * @return String value of the date 28 */ 29 <T extends TemporalAccessor> String format(T temporalAccessor, String dateFormatString); 30 31 /** 32 * Formats the given date as a String. 33 * 34 * @param the TimeDate date to format 35 * @param dateFormatString format string to use. See {@link DateTimeFormatter} 36 * for details. 37 * @param locale 38 * @return String value of the date 39 */ 40 <T extends TemporalAccessor> String format(T temporalAccessor, String dateFormatString, Locale locale); 41 42 /** 43 * Maps from an incoming format to an outgoing format {@link DateTimeFormatter}. 44 * @param src the formatted datetime 45 * @param outgoingFormat {@link DateTimeFormatter} 46 * @param locale Locale, if needed for outgoing formatting, no default. 47 * @param incomingFormat {@link DateTimeFormatter}, optional, default is {@link #defaultFormat}. 48 * @return the newly mapped 49 */ 50 String map(String src, String outgoingFormatPattern, Locale locale, String incomingFormatPattern); 51 52 /** 53 * Uses as incoming format {@link #defaultFormat} and no locale. 54 * @param src 55 * @param outgoingFormat 56 * @return the formatted string 57 * 58 * @throws java.time.temporal.UnsupportedTemporalTypeException 59 */ 60 String map(String src, DateTimeFormatter outgoingFormat, Locale locale, 61 DateTimeFormatter incomingFormat); 62 63 /** 64 * Uses as outgoing {@link DateTimeFormatter} {@link #defaultFormat} and no locale. 65 * @param src the datetime formatted string 66 * @param incomingFormat the format of this string 67 * @return the date time formatted using the {@link #defaultFormat}. 68 */ 69 String mapTo(String src, DateTimeFormatter outgoingFormat); 70 71 /** 72 * Uses as incoming {@link DateTimeFormatter} {@link #defaultFormat}. 73 * @param src the datetime formatted string 74 * @param outgoingFormat the format to which this string should be formatted. 75 * @param locale 76 * @return the newly formatted date time string 77 * 78 * @throws java.time.temporal.UnsupportedTemporalTypeException 79 */ 80 String mapFrom(String src, DateTimeFormatter incomingFormat); 81 82 String map(String src, DateTimeFormatter outgoingFormat, Locale locale); 83 }