Skip to content

feat: change d2:minutesBetween arguments from LocalDate to Instant - #93

Open
superskip wants to merge 6 commits into
mainfrom
DHIS2-20696-2
Open

feat: change d2:minutesBetween arguments from LocalDate to Instant#93
superskip wants to merge 6 commits into
mainfrom
DHIS2-20696-2

Conversation

@superskip

@superskip superskip commented Jan 12, 2026

Copy link
Copy Markdown
Collaborator
  • Introduces toInstantTypeCoercion
  • Changes the return type of d2:minutesBetween from Int to Double.

The goal of this PR is to change the behaviour of d2:minutesBetween so that it can return values beyond the multiples of 24 hours.

@sonarqubecloud

Copy link
Copy Markdown

@superskip
superskip marked this pull request as ready for review August 25, 2026 12:18
@sonarqubecloud

Copy link
Copy Markdown

}

fun d2_minutesBetween(start: LocalDate?, end: LocalDate?): Int {
fun d2_minutesBetween(start: Instant?, end: Instant?): Double {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change in the return type, is it safe? I think this function was only used by program indicator expressions, so that's ok. If it was used by program rules, we might have a sync issue if there is a parser version mismatch between client and server: for example, if a new Capture/Android app has a newer version of the expression-parser and the backend has an old one, the client could evaluate to 4.3 and the backend to 4, and it might produce an error at sync.

@superskip superskip Aug 25, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither Tracker Capture or the Capture web app had implemented d2:minutesBetween. We did add the Int version to the parser in January, however: #92. So you are right, this might cause a headache to anyone who is using a server version released between January and August..

@superskip superskip Aug 25, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request also changes the implementation of d2:minutesBetween such that it no longer returns just multiples of 24 hours. I think this is a necessary change to make. It raises the same concern as with changing the return type, so we may take this opportunity to change both.

Not sure how we deal with the frontend / backend issue it will cause for certain backend versions though.

@jbee jbee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK so far expression would only operate on dates and thus only LocalDate was required. This makes sense since the smallest data point interval we use in DHIS2 is "daily".
Any precision beyond days seems accidental to me unless you calculate some sort of statistic like an average which might yield a fraction number of days. But even in such a scenario you would not need Instant precision in the inputs as those would still be in steps of days. So I am doubtful this is actually required.

In addition I would think that adding another time related input type is quite a big change and would require to think about if not all time related parameters now must accept both types.

@superskip

Copy link
Copy Markdown
Collaborator Author

@jbee Thanks for your input! 🙏

According to the docs, there seems to be a concept of datetime in the world of program indicators. On the tracker side there is a data element of type datetime. At least for these data elements it would make sense to compute time difference in minutes.

Adding a new "input type" like evalToInstant seems like a fairly safe extension point to me. I don't think I have introduced two competing types of parameters here (the DATE type could already be either Instant or LocalDate before this PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants