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

[pkg/ottl] Boolean expressions are update to be able to handle comparing time.Time types #22008

Closed
Tracked by #16067
TylerHelmuth opened this issue May 16, 2023 · 1 comment · Fixed by #24243
Closed
Tracked by #16067
Assignees
Labels
enhancement New feature or request pkg/ottl priority:p2 Medium

Comments

@TylerHelmuth
Copy link
Member

TylerHelmuth commented May 16, 2023

In order to facilitate contexts returning time fields as time.Time we need to be able to compare time.Time values in boolean expressions. Although not supported by the grammar as literals, OTTL should allow working with these types.

When comparing time.Time fields, the following rules should be followed:

  • time.Equal should be used to check if 2 times are equal.
  • time.Before should be used to check if 1 time is earlier than another.
  • time.After should be used to check if 1 time is later than another.

Given 2 times, A and B:

  • A < B is true if and only if A.Before(B) is true.
  • A <= B is true if A.Before(B) is true OR A.Equal(B) is true.
  • A > B is true if and only if A.After(B) is true.
  • A >= B is true if A.After(B) is true OR A.Equal(B) is true.
  • A == B is true if and only if A.Equal(B) is true.
  • A != B is true if and only if A.Equal(B) is false.

If either A or B is not a time, the comparison is false.

@TylerHelmuth TylerHelmuth added enhancement New feature or request priority:p2 Medium pkg/ottl labels May 16, 2023
@TylerHelmuth TylerHelmuth changed the title OTTL Boolean expressions are update to be able to handle comparing time.Time types [pkg/ottl] Boolean expressions are update to be able to handle comparing time.Time types May 16, 2023
@fchikwekwe
Copy link
Contributor

I'm working on this ticket. Please assign me @TylerHelmuth

TylerHelmuth added a commit that referenced this issue Jul 14, 2023
Description: Allows time comparison by enabling boolean behavior for
time objects.

Link to tracking Issue: Closes #22008

Testing: Unit tests

Documentation:

---------

Co-authored-by: Tyler Helmuth <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pkg/ottl priority:p2 Medium
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants