001package org.apache.turbine.services.localization; 002 003import java.time.format.DateTimeFormatter; 004import java.time.temporal.TemporalAccessor; 005import java.util.Locale; 006 007public interface DateTimeFormatterInterface { 008 DateTimeFormatter getDefaultFormat(); 009 010 String getDateTimeFormatPattern(); 011 012 /** 013 * Formats the given datetime as a String with the #{@link DateTimeFormatterService#defaultFormat}. 014 * using the default date format. 015 * 016 * @param the {@link TemporalAccessor to format 017 * @return String value of the date 018 */ 019 <T extends TemporalAccessor> String format(T temporalAccessor); 020 021 /** 022 * Formats the given date as a String. 023 * 024 * @param the TimeDate date to format 025 * @param dateFormatString format string to use. See {@link DateTimeFormatter} 026 * for details. 027 * @return String value of the date 028 */ 029 <T extends TemporalAccessor> String format(T temporalAccessor, String dateFormatString); 030 031 /** 032 * Formats the given date as a String. 033 * 034 * @param the TimeDate date to format 035 * @param dateFormatString format string to use. See {@link DateTimeFormatter} 036 * for details. 037 * @param locale 038 * @return String value of the date 039 */ 040 <T extends TemporalAccessor> String format(T temporalAccessor, String dateFormatString, Locale locale); 041 042 /** 043 * Maps from an incoming format to an outgoing format {@link DateTimeFormatter}. 044 * @param src the formatted datetime 045 * @param outgoingFormat {@link DateTimeFormatter} 046 * @param locale Locale, if needed for outgoing formatting, no default. 047 * @param incomingFormat {@link DateTimeFormatter}, optional, default is {@link #defaultFormat}. 048 * @return the newly mapped 049 */ 050 String map(String src, String outgoingFormatPattern, Locale locale, String incomingFormatPattern); 051 052 /** 053 * Uses as incoming format {@link #defaultFormat} and no locale. 054 * @param src 055 * @param outgoingFormat 056 * @return the formatted string 057 * 058 * @throws java.time.temporal.UnsupportedTemporalTypeException 059 */ 060 String map(String src, DateTimeFormatter outgoingFormat, Locale locale, 061 DateTimeFormatter incomingFormat); 062 063 /** 064 * Uses as outgoing {@link DateTimeFormatter} {@link #defaultFormat} and no locale. 065 * @param src the datetime formatted string 066 * @param incomingFormat the format of this string 067 * @return the date time formatted using the {@link #defaultFormat}. 068 */ 069 String mapTo(String src, DateTimeFormatter outgoingFormat); 070 071 /** 072 * Uses as incoming {@link DateTimeFormatter} {@link #defaultFormat}. 073 * @param src the datetime formatted string 074 * @param outgoingFormat the format to which this string should be formatted. 075 * @param locale 076 * @return the newly formatted date time string 077 * 078 * @throws java.time.temporal.UnsupportedTemporalTypeException 079 */ 080 String mapFrom(String src, DateTimeFormatter incomingFormat); 081 082 String map(String src, DateTimeFormatter outgoingFormat, Locale locale); 083}