Skip to main content

DateFormatTransformer

Converts a date from its current format to a specified format.

Notes

This functionality allows you to formats a date from any given format to a format of choice, as per the formatting options found on SimpleDateFormat with the exception of the string EPOCH which represents the difference, measured in milliseconds, between the date and midnight, January 1, 1970. The default format for fromFormat or toFormat when not specified is EPOCH.

When omitting the toField, the value will replace the one in the same field name.

Multiple fromFormats values can be specified. Each formats will be tried in the order provided and the first format that succeed in parsing a date will be used. A date will be considered "bad" only if none of the formats could parse the date.

Storing values in an existing field

If a document already has a target field with the same name, new values are appended to the existing list by default. Use onSet to manage this default behavior.

Parser Handler Compatibility

This functionality can be applied as either a pre-parse or post-parse handler.

Locale of Date Formatting

It is possible to specify a locale used for formatting dates. The locale is the ISO two-letter language code, with an optional ISO country code, separated with an underscore (e.g., fr for French, fr_CA for Canadian French). When no locale is specified, the default is en_US (US English).

Examples

The following converts a date that is sometimes obtained from the HTTP header "Last-Modified" and sometimes is an EPOCH date, into an Apache Solr date format

handler:
class: DateFormatTransformer
fromField: Last-Modified
toField: solr_date
toFormat: yyyy-MM-dd'T'HH:mm:ss.SSS'Z
fromFormats:
- EEE, dd MMM yyyy HH:mm:ss zzz
- EPOCH

Usage

Full configuration skeleton, with every option and its default
class: DateFormatTransformer
fromField: string
fromFormats:
- string
fromLocale: string
keepBadDates: false
label: string
onSet: APPEND
toField: string
toFormat: string
toLocale: string

Properties

PropertyTypeRequiredDefault
fromFieldstringNo-
fromFormatsstring[]No-
fromLocalestringNo-
keepBadDatesbooleanNofalse
labelstringNo-
onSetenumNo-
toFieldstringNo-
toFormatstringNo-
toLocalestringNo-

Property Details

fromField

specifies the document field containing the date to be reformatted.

fromFormats

Specifies one or multiple format of the input date string to be reformatted.

fromLocale

Specifies the expected format(s) of the input date string(s) to be reformatted.

keepBadDates

Determines whether to retain the original date string if it cannot be parsed or reformatted.

label

An optional, user-supplied label for this step in the importer pipeline. It has no effect on processing — it exists purely to help identify this step, for example in large configurations or in the visual configurator.

onSet

What to do if a target field of the same name already exist.

Allowed Values

  • APPEND
  • PREPEND
  • REPLACE
  • OPTIONAL

toField

A target field name used to store the value.

toFormat

Specifies the desired format to convert the input date string into.

toLocale

Defines the locale to apply when formatting the output date string.