Duration calcluation seems too long

Hi. I’ve worked through the (excellent) YouTube tutorials and noticed something that seems unusual to me about duration calculations. Normally a year is considered 1 Jan to 31 Dec, or a month eg 1 April to 30 April. But the duration datafield is calculating simply the same date/day for the next month/year/whatever. In the screenshot below you can see that it has calculated 1 month from 1 Jan 2022 as ended on 1 Feb 2022 but the month of January ends 31 Jan, not 1 Feb. So it seems the duration datafield is actually calculating one month and one day. Is there a way to constrain the calculation so that it uses the industry standard definitions of days/weeks/months/years/etc? image

Hi,

Good question, actually!

When designing software, you sometimes have to choose between two opposing views — in this case, between on the one hand how most lawyers would look at date calculations, and on the other hand how date calculations are done in most other software packages (e.g., Excel and many programming languages).

image

This was a borderline case, but eventually we decided to choose the technical view.

The solution is to simply subtract a day:

image

Thanks Maarten for the explanation. Can you point me to instructions on how to calculate dates when using concepts, please? For example, using the coding from the YouTube tutorial, if I try to add “- 1 day” to the formula to calculate the end date using start date and duration, I get a “Value is not a number” error. Here’s a screenshot of what I mean:
image

Based on the screenshot you show here, I think your confusion is not so much in how the formulas work, but instead that you have not yet assigned a value to the #agreement^duration and #agreement^commencement-date datafields. You still need to click (for both datafields) on the the green checkmark in the left panel; right now the two values are ready to be assigned, but not yet effectively assigned.

The problem with the current state of your document, is that you would ask the software to do the following calculation: “unknown date + unknown duration - 1 day” → and that causes the error.

image

Doh! as Homer would say. It works when I click the checkmarks. Thanks for your patience and clear explanations!

Hi Maarten - another question, related: is it possible to configure a custom error message, like to inform the user that they need to supply and tick the variables behind the calculation, a more human-understandable message than “variable not a number”? This may be a low-priority enhancement request if it’s not already available. Just a thought…

You can solve this in different ways:

1. You can include an alert (= text wrapped in double exclamation marks) to cover undesired situations. For example:

{#agreement^commencement-date AND #agreement^duration: {#agreement^commencement-date + #agreement^duration - 1 day} | else: !! both the commencement date and duration must be filled in !!}

This would show an alert if either the commencement date or the duration is not yet filled in; otherwise, it performs the calculation and show the result.

2. You can force the user to fill in all required values (by including an exclamation mark after the ^), otherwise the calculation will not be performed. For example:

{#agreement^!commencement-date + #agreement^!duration - 1 day}

When any of the datafields with an exclamation mark is not available, the yellow box will be shown.

image

There are a few subtleties to know when the yellow box will (not) be shown, you can read more about it here: Special codes – Help

3. In a Q&A, you can include warning or comment blocks that would warn the user about missing values. Simply attach a condition to the warning/comment block that causes it to only show up in case of a missing value. For example:

image

1 Like

Thanks Maarten! I’m really impressed that error handling is so flexibly available.