Skip to content

changeDateFormat

The changeDateFormat module allows you to manipulate the disambiguator's normalized format of extracted dates. It has one method called changeDateFormat. This module works for the following languages:

  • English
  • German
  • Spanish
  • French
  • Italian
  • Dutch

See the dedicated page about date normalization in the various languages after an extraction.

Note

This page will show examples in English.

When in Studio you install the changeDateFormat module in your project, Studio modifies the main.jr file to insert these statements at the beginning of the file:

var changeDateFormat = require('modules/changeDateFormat');

The statement above sets a variable with an instance of the module so that you can use it inside event handling functions.

Note

The moment module is a dependency of changeDateFormat. When installing the latter, this statement also appears in the main.jr:

var moment = require('modules/moment');

The changeDateFormat method must be used in the onFinalize function, because it acts on the analysis results available when this function is run.

For example, with this template:

TEMPLATE(PERSONAL_DATA)
{
    @DATE_OF_BIRTH
}

and this rule:

SCOPE SENTENCE
{
    IDENTIFY(PERSONAL_DATA)
    {
        @DATE_OF_BIRTH[TYPE(DAT)]
    }
}

applied to these sentences:

Renato was born on the 15th of June 1995.
Julian was born on the 16th of June 1995.
John was born on the 17th of June 1995.
Theodore was born on the 08th of June 1995.

you will get this record:

Template: PERSONAL_DATA

Field Value
@DATE_OF_BIRTH Jun-15-1995
@DATE_OF_BIRTH Jun-16-1995
@DATE_OF_BIRTH Jun-17-1985
@DATE_OF_BIRTH Jun-8-1985

With this code:

function onFinalize(result) {
    changeDateFormat.changeDateFormat(result, {
    target_template_name: "PERSONAL_DATA",
    target_field_name: "DATE_OF_BIRTH",
    date_format: ["MMM-DD-YYYY", "MMM-D-YYYY"],
    new_date_format: "YYYY-MMM-DD",
    language: "en"
    });
    return result;
} 

the output becomes:

Template: PERSONAL_DATA

Field Value
@DATE_OF_BIRTH 1995-Jun-15
@DATE_OF_BIRTH 1995-Jun-16
@DATE_OF_BIRTH 1995-Jun-17
@DATE_OF_BIRTH 1995-Jun-08

The date formats have been changed based on the example code above with the YYYY-MMM-DD format. The date_format parameter above is an array based on the double normalized format of English dates, with leading zeroes removed.

The syntax of the method is:

moduleVariable.changeDateFormat(result, arguments)

where:

  • moduleVariable is the variable corresponding to the module and set with require().
  • result is the object containing the analysis results.
  • arguments is an object containing the parameters to be used. Such parameters are:

    • target_template_name is the template name of the record where the new format is applied.
    • target_field_name is the name of the field whose value(s) must be formatted.
    • date_format is the normalized date format based on the language. It can be a single string or an array if more normalized formats are available.
    • new_date_format is the new date format to apply to the extracted dates.
    • language is the language abbreviation the dates will be formatted in. Values can be:

      • en
      • de
      • sp
      • fr
      • it
      • nl