accordproject / template-archive

Smart Legal Contracts & Templating System
https://accordproject.org/projects/cicero/
Apache License 2.0
281 stars 119 forks source link

Optional DateTime variables are erroneously defaulted to current date & time #687

Open martinhalford opened 3 years ago

martinhalford commented 3 years ago

Bug Report 🐛

Details

Consider the following asset declaration.

asset HelloWorldClause extends Clause {
  o String name
  o DateTime date optional
}

As the DateTime date variable is optional then a user may, or may not, pass a value in via the data.json payload.

Example 1

Using the following data.json

{
    "$class": "org.accordproject.helloworld.HelloWorldClause",
    "name": "Fred Blogs",
    "date": "2021-01-01T00:00:00.000+00:00",
    "clauseId": "c69e70dd-81ea-491b-8714-1a7d984a5cae",
    "$identifier": "c69e70dd-81ea-491b-8714-1a7d984a5cae"
}

...the cicero draft command produces the following sample.md

Name of the person to greet: "Fred Blogs".
The date of this agreement is: 01/01/2021
Thank you!

...which is as expected.

Example 2

Using the following data.json which is missing the optional DateTime attribute, as allowed

{
    "$class": "org.accordproject.helloworld.HelloWorldClause",
    "name": "Fred Blogs",
    "clauseId": "c69e70dd-81ea-491b-8714-1a7d984a5cae",
    "$identifier": "c69e70dd-81ea-491b-8714-1a7d984a5cae"
}

...the cicero draft command incorrectly produces the following sample.md

Name of the person to greet: "Fred Blogs".
The date of this agreement is: 08/16/2021
Thank you!

...which is not as expected.

Cicero has incorrectly inserted the current date and time values in place of the undefined DateTime attribute.

Expected Example 2

What was expected was...

Name of the person to greet: "Fred Blogs".
The date of this agreement is: undefined
Thank you!

We'd expect the undefined optional DateTime variable to appear as undefined in the output MD files, in the same was as undefined String variables appear as undefined.

Why is this an issue

At the moment, we are unable to distinguish when an optional DateTime variable has been passed in via data.json and when an optional DateTime variable has legitimately been omitted.

Attached example HelloWorld CTA

helloworld.zip

OmkarAcharekar commented 2 years ago

Hey @jeromesimeon @martinhalford, This issue can be solved by making few changes in dateTimeDrafter function in markdown-transform repo. This may work:

function dateTimeDrafter(value,format) {
     if(value){
          const f = format ? format : 'MM/DD/YYYY';
          return dayjs.utc(value).format(f);
     }else{
          return "undefined";
    }   
}

Should I submit a PR to that repo ?