Class DateTimeFormatterService
- java.lang.Object
-
- org.apache.turbine.services.BaseInitable
-
- org.apache.turbine.services.BaseService
-
- org.apache.turbine.services.TurbineBaseService
-
- org.apache.turbine.services.localization.DateTimeFormatterService
-
- All Implemented Interfaces:
Initable
,DateTimeFormatterInterface
,Service
public class DateTimeFormatterService extends TurbineBaseService implements DateTimeFormatterInterface
This service is used to formatTemporalAccessor
andmap(String, DateTimeFormatter, Locale)
(different falvors) objects into strings. The methods may throwUnsupportedTemporalTypeException
orDateTimeParseException
. if the source and the target format do not match appropriately.
-
-
Field Summary
Fields Modifier and Type Field Description static String
ROLE
static String
SERVICE_NAME
-
Fields inherited from class org.apache.turbine.services.BaseService
configuration, name, serviceBroker
-
Fields inherited from class org.apache.turbine.services.BaseInitable
initableBroker, isInitialized
-
-
Constructor Summary
Constructors Constructor Description DateTimeFormatterService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends TemporalAccessor>
Stringformat(T temporalAccessor)
Formats the given datetime as a String with the #defaultFormat
.<T extends TemporalAccessor>
Stringformat(T temporalAccessor, String dateFormatString)
Formats the given date as a String.<T extends TemporalAccessor>
Stringformat(T temporalAccessor, String dateFormatString, Locale locale)
Formats the given date as a String.String
getDateTimeFormatPattern()
DateTimeFormatter
getDefaultFormat()
void
init()
Initialize the service.String
map(String src, String outgoingFormatPattern, Locale locale, String incomingFormatPattern)
Maps from an incoming format to an outgoing formatDateTimeFormatter
.String
map(String src, DateTimeFormatter outgoingFormat, Locale locale)
String
map(String src, DateTimeFormatter outgoingFormat, Locale locale, DateTimeFormatter incomingFormat)
Uses as incoming format#defaultFormat
and no locale.String
mapFrom(String src, DateTimeFormatter incomingFormat)
Uses as incomingDateTimeFormatter
#defaultFormat
.String
mapTo(String src, DateTimeFormatter outgoingFormat)
Uses as outgoingDateTimeFormatter
#defaultFormat
and no locale.-
Methods inherited from class org.apache.turbine.services.TurbineBaseService
init, init, shutdown
-
Methods inherited from class org.apache.turbine.services.BaseService
getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker
-
Methods inherited from class org.apache.turbine.services.BaseInitable
getInit, getInitableBroker, setInit, setInitableBroker
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.turbine.services.Initable
getInit, setInitableBroker
-
-
-
-
Field Detail
-
SERVICE_NAME
public static String SERVICE_NAME
-
-
Constructor Detail
-
DateTimeFormatterService
public DateTimeFormatterService()
-
-
Method Detail
-
getDefaultFormat
public DateTimeFormatter getDefaultFormat()
- Specified by:
getDefaultFormat
in interfaceDateTimeFormatterInterface
-
getDateTimeFormatPattern
public String getDateTimeFormatPattern()
- Specified by:
getDateTimeFormatPattern
in interfaceDateTimeFormatterInterface
-
init
public void init()
Initialize the service. thedefaultFormat
fromdateTimeFormatPattern
is initialized with the default LocaleLocale.getDefault()
and default zone:ZoneId.systemDefault()
.- Specified by:
init
in interfaceInitable
- Overrides:
init
in classTurbineBaseService
-
format
public <T extends TemporalAccessor> String format(T temporalAccessor)
Description copied from interface:DateTimeFormatterInterface
Formats the given datetime as a String with the #defaultFormat
. using the default date format.- Specified by:
format
in interfaceDateTimeFormatterInterface
- Returns:
- String value of the date
-
format
public <T extends TemporalAccessor> String format(T temporalAccessor, String dateFormatString)
Description copied from interface:DateTimeFormatterInterface
Formats the given date as a String.- Specified by:
format
in interfaceDateTimeFormatterInterface
dateFormatString
- format string to use. SeeDateTimeFormatter
for details.- Returns:
- String value of the date
-
format
public <T extends TemporalAccessor> String format(T temporalAccessor, String dateFormatString, Locale locale)
Description copied from interface:DateTimeFormatterInterface
Formats the given date as a String.- Specified by:
format
in interfaceDateTimeFormatterInterface
dateFormatString
- format string to use. SeeDateTimeFormatter
for details.- Returns:
- String value of the date
-
map
public String map(String src, String outgoingFormatPattern, Locale locale, String incomingFormatPattern)
Description copied from interface:DateTimeFormatterInterface
Maps from an incoming format to an outgoing formatDateTimeFormatter
.- Specified by:
map
in interfaceDateTimeFormatterInterface
- Parameters:
src
- the formatted datetimelocale
- Locale, if needed for outgoing formatting, no default.- Returns:
- the newly mapped
-
map
public String map(String src, DateTimeFormatter outgoingFormat, Locale locale, DateTimeFormatter incomingFormat)
Description copied from interface:DateTimeFormatterInterface
Uses as incoming format#defaultFormat
and no locale.- Specified by:
map
in interfaceDateTimeFormatterInterface
- Returns:
- the formatted string
-
mapTo
public String mapTo(String src, DateTimeFormatter outgoingFormat)
Description copied from interface:DateTimeFormatterInterface
Uses as outgoingDateTimeFormatter
#defaultFormat
and no locale.- Specified by:
mapTo
in interfaceDateTimeFormatterInterface
- Parameters:
src
- the datetime formatted string- Returns:
- the date time formatted using the
#defaultFormat
.
-
mapFrom
public String mapFrom(String src, DateTimeFormatter incomingFormat)
Description copied from interface:DateTimeFormatterInterface
Uses as incomingDateTimeFormatter
#defaultFormat
.- Specified by:
mapFrom
in interfaceDateTimeFormatterInterface
- Parameters:
src
- the datetime formatted string- Returns:
- the newly formatted date time string
-
map
public String map(String src, DateTimeFormatter outgoingFormat, Locale locale)
- Specified by:
map
in interfaceDateTimeFormatterInterface
-
-