 # Order of operations with filter AND/OR logic

Until we get a simplified arrays of logic, can I get a definitive answer on how to represent this AND/OR logic.

Desired Logic to get all events within a date range that either start in the range, or end in the range, or start before the range and end after the range

``````(
start: { ge: \$START } AND
start: { le: \$END }
) OR (
end: { ge: \$START } AND
end: { le: \$END }
) OR (
start { le: \$START } AND
end: { ge: \$END }
)
``````

Can someone confirm this is syntactically the same:

``````filter: {
# (
start: {ge: \$START}
and: {
start: {le: \$END}
} # )
or: {
# (
end: {ge: \$START}
and: {
end: { le: \$END }
}
# )
or: {
# (
start { le: \$START }
and: {
end: { ge: \$END }
}
# )
}
}
}
``````

What definitely does not work but throws syntax errors:

``````filter: {
or: {
start: {ge: \$START}
and: {
start: {le: \$END}
}
}
or: {
end: {ge: \$START}
and: {
end: { le: \$END }
}
}
or: {
start { le: \$START }
and: {
end: { ge: \$END }
}
}
}
``````

Errors out with:

There can be only one input field named “or”.

How I would eventually like the make the filter:

``````filter: [
or: [
{ and: [
{ start: { ge: \$START } }
{ start: { le: \$END } }
]}
{ and: [
{ end: { ge: \$START } }
{ end: { le: \$END } }
]}
{ and: [
{ start { le: \$START } }
{ end: { ge: \$END } }
]}
]
]
``````

What would be even better:

``````filter: [
or: [
{ start: { between: [ \$START \$END ] } }
{ end: { between: [ \$START \$END ] } }
{ and: [
{ start { le: \$START } }
{ end: { ge: \$END } }
]}
]
]
``````

The results I get with this appear correct.

1. Seeing events starting in the range and ending after the range
2. Seeing events starting before the range and ending in the range
3. Seeing events starting before the range and ending after the range
1 Like

Yes, this looks much easier to understand.
Thank you @amaster507 for sharing this.

1 Like