Configure the Date Formatting Pattern for Date Fields - BloomReach Experience - Open Source CMS

This article covers a Hippo CMS version 11. There's an updated version available that covers our most recent release.

28-11-2016

Configure the Date Formatting Pattern for Date Fields

Introduction

Goal

Configure the pattern used to format dates in Date and CalendarDate fields in document types.

Background

By default, the date in a Date or CalendarDate field in a document type is formatted depending on the UI language selected by the user when they logged in. For example, the pattern M/d/yyyy is used for English while d-M-yyyy is used for French. Through configuration, it's possible to override this default behavior using a fixed language-independent pattern. Overriding can be done at field type level as well as for an individual field in a document type.

For the pattern syntax see the org.joda.time.format.DateTimeFormatter javadoc.

The instructions below are to change the pattern for Date fields. To do the same for CalendarDate fields, replace /hippo:namespaces/system/Date with /hippo:namespaces/system/CalendarDate.

Make the Date Pattern Configurable

In the Console, browse to the node /hippo:namespaces/system/Date/editor:templates/_default_.

Add a new value date.pattern to the existing multiple String property frontend:properties.

/hippo:namespaces/system/Date/editor:templates/_default_
  - frontend:properties = { 
                            mode,
                            date.pattern
                          }

Browse to the node /hippo:namespaces/system/Date/editor:templates/_default_/root.

Add a String property date.pattern to the datepicker node, with the value ${date.pattern}.

/hippo:namespaces/system/Date/editor:templates/_default_/root
​  + datepicker (frontend:pluginconfig)
    - date.pattern = ${date.pattern}

Write changes to the repository.

Now it's possible to configure the date pattern for all Date fields, or for a particular Date field in a document type.

Configure the Date Pattern for All Date Fields

Make sure that the date pattern for Date fields is configurable.

Browse to the node /hippo:namespaces/system/Date/editor:templates/_default_.

Add a String property date.pattern, with the desired date pattern as value (for example, yyyy-MM-dd).

/hippo:namespaces/system/Date/editor:templates/_default_
  - date.pattern = yyyy-MM-dd

Write changes to the repository.

Now all Date fields in all document types will be formatted using the configured pattern, regardless of the selected UI language.

Configure the Date Pattern for a Particular Date Field in a Document Type

The instructions below use an example based on a default project created from Hippo's Maven archetype, named myhippoproject, with the News feature added. The News feature includes a document type News Item (node type myhippoproject:newsdocument) which contains a Date field (path date).

Make sure that the date pattern for Date fields is configurable.

Browse to the node /hippo:namespaces/myhippoproject/newsdocument/editor:templates/_default_/date/cluster.options.

Add a String property date.pattern, with the desired date pattern as value (for example, yyyy-MM-dd).

/hippo:namespaces/myhippoproject/newsdocument/editor:templates/_default_/date/cluster.options
​  - date.pattern = yyyy-MM-dd

Write changes to the repository.

Now the Date field in the News Item document type will be formatted using the configured pattern, regardless of the selected UI language.

Precedence

When the default date pattern is overridden for all Date fields as well as for a particular Date field, the pattern configured for the particular Date field is used.

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?