in velocity-tools-generic/src/main/java/org/apache/velocity/tools/ConversionUtils.java [469:546]
public static DateFormat getDateFormat(int dateStyle, int timeStyle,
Locale locale, TimeZone timezone)
{
try
{
DateFormat df;
if (dateStyle < 0 && timeStyle < 0)
{
// no style was specified, use default instance
df = DateFormat.getDateInstance();
}
else if (timeStyle < 0)
{
// only a date style was specified
switch (dateStyle)
{
case STYLE_ISO:
case STYLE_ISO_TZ: /* ignore TZ */
case STYLE_INTL:
case STYLE_INTL_TZ: /* ignore TZ */
df = (DateFormat)isoDateFormat.clone();
break;
default:
df = DateFormat.getDateInstance(dateStyle, locale);
break;
}
}
else if (dateStyle < 0)
{
// only a time style was specified
switch (timeStyle)
{
case STYLE_ISO:
case STYLE_INTL:
df = (DateFormat)isoTimeFormat.clone();
break;
case STYLE_ISO_TZ:
df = (DateFormat)isoTimeTzFormat.clone();
break;
case STYLE_INTL_TZ:
df = new TimeZoneIDSuffixFormat((DateFormat)intlTimeTzFormat_base.clone());
break;
default:
df = DateFormat.getTimeInstance(timeStyle, locale);
break;
}
}
else
{
switch (dateStyle)
{
case STYLE_ISO:
df = isoTimestampFormat;
break;
case STYLE_ISO_TZ:
df = (DateFormat)isoTimestampTzFormat.clone();
break;
case STYLE_INTL:
df = (DateFormat)intlTimestampFormat.clone();
break;
case STYLE_INTL_TZ:
df = new TimeZoneIDSuffixFormat((DateFormat)intlTimestampTzFormat_base.clone());
break;
default:
df = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
break;
}
}
df.setTimeZone(timezone);
return df;
}
catch (Exception suppressed)
{
LoggerFactory.getLogger(ConversionUtils.class).error("could not get date/time format", suppressed);
// let it go...
return null;
}
}