Modeling dates in many formats

Hi,

In my project, there are many different date-formats, which must be supported in a model. For example, think of exotic non-standard formats like JJJJ+MM+DD or DD_MM_JJ.

The default types of A12 Modelling (Date, DateFragment) only support a few of them. I wonder, what the correct approach would be?

  • “Hack” the JSON-Model and write my own custom Format:
    • How does this this affect the display in the SME? The default format for Date is “yyyy-MM-dd” and does not seem to be changeable.
    • Example:
    "fieldType" : {
      "type" : "DateType",
      "DateType" : {
        "format" : "DD+MM+YYYY"
      }
    }
    
  • Always use a type-definition for every format.
    • Bonus question: Can a type-definition also support a second (shortend) format, for example, if JJJJ+MM+DD also can be a JJ+MM+DD in the same field?

Many thanks,
Stefan

Hi @stefan-grey-canyon

As a modeler, I don’t think that you should ever “hack” the json. In this case, you should consider modeling a Field with a “Custom” Data Type.

This custom data type can then be configured by custom code to match your project needs.

This seems to be the only way forward as a modeler as, as you state, date fields always save the date in the format “yyy-MM-dd”.

Regarding shortend dates, you can build a date in the Kernel Language using 4 parameters.

Date(Day, Month, Century, YearInCentury)

If the century is known, you could use String Data in JJ+MM+DD format to compute the Date.

I’ve suggested a Custom Field rather than a String Field which is then coverted using Computation Rules to a Computed Date Field as the conversion leads to a lot of extra fields. It is however possible.

Thanks for your suggestion.

We will start by using the A12-Date Format in every date field. But we will add an annotation, which the target format is. It may be a temporary solution.