Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Store duration values in a normalized format #27161

Merged
merged 5 commits into from
Jan 24, 2025
Merged

Conversation

saig0
Copy link
Member

@saig0 saig0 commented Jan 20, 2025

Description

Use toString() of FEEL duration to serialize the value into a JSON variable. Compared to the Java's duration value, the
FEEL value returns the duration in a normalized format (i.e. in the biggest available unit).

This fix aligns the engine with the docs and avoids the workaround using the string() function.

// before
"PT120H"

// after
"P5D"

Related issues

closes #27098

@github-actions github-actions bot added the component/zeebe Related to the Zeebe component/team label Jan 20, 2025
@saig0 saig0 requested a review from korthout January 22, 2025 08:55
Copy link
Member

@korthout korthout left a comment

Choose a reason for hiding this comment

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

Nice work @saig0 🚀

LGTM 👍

🔧 I have some suggestions to extend test coverage

Comment on lines 250 to 251
public void shouldReturnNormalizedPeriod() {
final var evaluationResult = evaluateExpression("=duration(\"P2Y\")");
Copy link
Member

Choose a reason for hiding this comment

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

❓ Should we also add a test case for period and duration with two separate units?

e.g.

  • P2Y3M
  • P5DT3H2M

Comment on lines 235 to 237
@Test
public void shouldReturnNormalizedDuration() {
final var evaluationResult = evaluateExpression("=duration(\"P5D\")");
Copy link
Member

Choose a reason for hiding this comment

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

🔧 We could show the normalization by starting with a non-normalized format:

  • PT120H -> P5D

saig0 added 3 commits January 23, 2025 14:31
Add a test case to verify that a duration value is stored in a normalized format.
Use toString() of FEEL duration to serialize the value into a JSON variable. Compared to the Java's duration value, the
FEEL value returns the duration in a normalized format (i.e. in the biggest available unit).
Adjust the duration value of existing test cases to expect a normalized format.
@saig0 saig0 force-pushed the 27098-feel-duration branch from e56f6ff to 10cda94 Compare January 23, 2025 14:15
@saig0 saig0 added backport stable/8.6 Backport a pull request to stable/8.6 backport stable/8.7 Backport a pull request to stable/8.7 backport stable/8.3 Backport a pull request to 8.3.x backport stable/8.4 Backport a pull request to 8.4.x backport stable/8.5 Backport a pull request to stable/8.5 labels Jan 23, 2025
saig0 added 2 commits January 23, 2025 15:23
Update the JUnit Maven dependency and the test annotations from JUnit 4 to JUnit 5.
Add more cases to verify the normalized duration formation using JUnit's parameterized tests.
@saig0 saig0 force-pushed the 27098-feel-duration branch from 10cda94 to 71aa2d3 Compare January 23, 2025 14:24
@saig0 saig0 added this pull request to the merge queue Jan 23, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jan 23, 2025
## Description

Use `toString()` of FEEL duration to serialize the value into a JSON
variable. Compared to the Java's duration value, the
FEEL value returns the duration in a normalized format (i.e. in the
biggest available unit).

This fix aligns the engine with the
[docs](https://docs.camunda.io/docs/components/modeler/feel/language-guide/feel-temporal-expressions/#subtraction)
and avoids the workaround using the
[string()](https://docs.camunda.io/docs/components/modeler/feel/builtin-functions/feel-built-in-functions-conversion/#stringfrom)
function.

```
// before
"PT120H"

// after
"P5D"
```

## Related issues

closes #27098
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 23, 2025
@saig0 saig0 added this pull request to the merge queue Jan 24, 2025
Merged via the queue into main with commit 603ae36 Jan 24, 2025
66 of 67 checks passed
@saig0 saig0 deleted the 27098-feel-duration branch January 24, 2025 08:48
@backport-action
Copy link
Collaborator

Created backport PR for stable/8.3:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-27161-to-stable/8.3
git worktree add --checkout .worktree/backport-27161-to-stable/8.3 backport-27161-to-stable/8.3
cd .worktree/backport-27161-to-stable/8.3
git reset --hard HEAD^
git cherry-pick -x e7aed5e34b8b24f3dc5078a45a4351db5def4d85 8fb4232e6a65d65c34218a7498fe2942ea2a8ea0 8ee6f31d622d76755dffa2376510ecabde259005 71aa2d3eef0b6d7d553db5b054c6711d354e4664
git push --force-with-lease

@backport-action
Copy link
Collaborator

Created backport PR for stable/8.4:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-27161-to-stable/8.4
git worktree add --checkout .worktree/backport-27161-to-stable/8.4 backport-27161-to-stable/8.4
cd .worktree/backport-27161-to-stable/8.4
git reset --hard HEAD^
git cherry-pick -x e7aed5e34b8b24f3dc5078a45a4351db5def4d85 8fb4232e6a65d65c34218a7498fe2942ea2a8ea0 8ee6f31d622d76755dffa2376510ecabde259005 71aa2d3eef0b6d7d553db5b054c6711d354e4664
git push --force-with-lease

@backport-action
Copy link
Collaborator

Created backport PR for stable/8.5:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-27161-to-stable/8.5
git worktree add --checkout .worktree/backport-27161-to-stable/8.5 backport-27161-to-stable/8.5
cd .worktree/backport-27161-to-stable/8.5
git reset --hard HEAD^
git cherry-pick -x e7aed5e34b8b24f3dc5078a45a4351db5def4d85 8fb4232e6a65d65c34218a7498fe2942ea2a8ea0 8ee6f31d622d76755dffa2376510ecabde259005 71aa2d3eef0b6d7d553db5b054c6711d354e4664
git push --force-with-lease

@backport-action
Copy link
Collaborator

Successfully created backport PR for stable/8.6:

@backport-action
Copy link
Collaborator

Successfully created backport PR for stable/8.7:

github-merge-queue bot pushed a commit that referenced this pull request Jan 24, 2025
…at (#27437)

# Description
Backport of #27161 to `stable/8.7`.

relates to #27098
original author: @saig0
github-merge-queue bot pushed a commit that referenced this pull request Jan 24, 2025
…at (#27436)

# Description
Backport of #27161 to `stable/8.6`.

relates to #27098
original author: @saig0
github-merge-queue bot pushed a commit that referenced this pull request Jan 29, 2025
…at (#27434)

# Description
Backport of #27161 to `stable/8.4`.

relates to #27098
original author: @saig0
github-merge-queue bot pushed a commit that referenced this pull request Feb 4, 2025
…at (#27433)

# Description
Backport of #27161 to `stable/8.3`.

relates to #27098
original author: @saig0
github-merge-queue bot pushed a commit that referenced this pull request Feb 5, 2025
…at (#27435)

# Description
Backport of #27161 to `stable/8.5`.

relates to #27098
original author: @saig0
@github-actions github-actions bot added the version:8.5.14 Marks an issue as being completely or in parts released in 8.5.14 label Feb 11, 2025
@rodrigo-lourenco-lopes rodrigo-lourenco-lopes added the version:8.7.0-alpha4 Marks an issue as being completely or in parts released in 8.7.0-alpha4 label Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport stable/8.3 Backport a pull request to 8.3.x backport stable/8.4 Backport a pull request to 8.4.x backport stable/8.5 Backport a pull request to stable/8.5 backport stable/8.6 Backport a pull request to stable/8.6 backport stable/8.7 Backport a pull request to stable/8.7 component/zeebe Related to the Zeebe component/team version: version:8.4.16 version:8.5.14 Marks an issue as being completely or in parts released in 8.5.14 version:8.6.8 version:8.7.0-alpha4 Marks an issue as being completely or in parts released in 8.7.0-alpha4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEEL] Store duration values in a normalized format
5 participants