Help With Comparing Date Ranges

Hello!

I need a workflow that goes like this:

-Take the first Calendar Event (Thing) off a list (using List Popper plugin)
-Take the first User off of another list (using List Popper plugin)
-Make a change to the first Thing (Calendar Event), but only if that Calendar Event’s daterange field DOES NOT overlap with any of the second Thing (User)'s List of Calendar Events’s dateranges.

I think the issue is trying to compare one Thing with a List of Things.

I’ve tried the “contain” or “does not contain” function. But what happens then is that the system looks for a match of the exact daterange. I need something like the “overlaps” function found in the Number range type. Except I want the system to look through a list and NOT do an action if it finds a daterange overlapping with a specified daterange.

Any help would be wonderful!

Thanks!

It’s entirely possible to compare a single date range with a list of date ranges in vanilla Bubble. The list operator you’re looking for is :filter. Also, date ranges do have the :overlaps operator, just like numeric ranges.

So, how you do this in Bubble is as follows:

Let us say that we have that we have a scalar date range (let’s call it daterange) and now we also have a list of date ranges (let’s call it drlist).

And now we want to know: “Does daterange overlap any of the date ranges in drlist?”

That’s just:

drlist:filtered by This date range overlaps daterange

:point_up: What this does is iterates over all of the date ranges in drlist, comparing each with the scalar daterange. The result will be the list of date ranges in drlist that overlap with the date range represented by daterange.

Now, how is that useful? Well, if this resulting list has any items in it, daterange must overlap one of them. If the resulting list has NO items in it, daterange must NOT have overlapped any of the ranges in the original list.

So, we can write:

drlist:filtered by This date range overlaps daterange:first item is not empty

:point_up: this expression yields the boolean Yes if daterange is found to overlap any range in drlist.

Or we can write:

drlist:filtered by This date range overlaps daterange:first item is empty

:point_up: this expression yields the boolean Yes if daterange did not overlap any of the ranges in drlist.

And so, now you can see that we have expression that we can use as an “only if” conditional. So your workflow can have a Make Changes to A Thing action that will trigger only if daterange does not overlap with any of the ranges in drlist.

Now, this expression building can look pretty hairball if it takes a complex expression to yield drlist and daterange, right?

And, sometimes, you might not actually be able to build the required expression at all.

BUT, since you’re already using List Popper, have a look at the Flow State SSA and Flow State List SSA actions in there. These are just like custom states on the client side. You shove an expression into their inputs and the resolved expression appears at their outputs.

(Also, I think the Flow State actions weren’t totally compatible with Things, so I pushed a new update to List Popper and Friends v 1.0.5 which fixes that, not that it affects the use case I describe above.)

7 Likes

Hi @keith

Thank you for this detailed response!!

I think I’ve managed to apply your solution to my app. This is what I did:

Although I’m running into this error in test:

image

This is how I set up the “FLOW State List SSA”. I’ve hovered on the “EventDateTimeRange” and it says that it evaluates to a list of dateranges:

Thank you for your help!

Works for me… did you update your List Popper plugin to 1.0.5? (If not, you should.)

@keith Thank you, I’ve updated!

In the debugger it looks like this error:

image

pops up after the first use of the List Popper SSA (so I’m not sure why the error has to do with the FLOW State List SSA). That first step is trying to pop the first item off of a filtered list. It looks like the Events’ daterange isn’t being recognized. I’ve double checked the data and the daterange exists for that Event.

I’m wondering if this might have something to do with the error message?

Thank you!

Oh, so, what’s happening here is that what you’re sending FLOW State List SSA seems to be a null (empty value). Any chance you might either (1) if you’re on a professional plan, invite me to your app as a collaborator (email: keith@synth.biz) or (2) either make your project anyone can view and PM me the editor URL?

(This would help me understand more precisely what’s happening in your project and figure out how to modify these plugins to work for you.)

Hey @keith,

It appears that the problem was with Full Calendar, and for some reason the error for the List Popper plugin was being triggered as well.

With the bug now fixed, your solution is now working!!

Thank you for your generous offer of taking a look at my app yourself.

I’m wondering if you have any pointers on how I could add your solution to a recursive workflow (so, the first API Endpoint would do the above solution, then, if there are more items remaining on the list, a second Endpoint is triggered). I know that List Popper has the option of “remaining list” vs “popped item”, but I’m not sure how I would send the “remaining list” to the second API Endpoint.

Thanks again!

So List Popper is intended for use in recursive workflows - that’s the whole point.

You want to process a list of items sequentially, so you send the list to that workflow. As one of your first steps, you insert List Popper, passing it your list. At the outputs of list popper, you have the item currently to process as well as the list of the remaining items.

You process that item and then as your last step in the workflow, you call the same workflow, this time sending it the remaining list (ONLY IF remaining list:count > 0).

In this way, you perform your workflow on every item in the list, sequentially, and the recursion terminates when the entire list has been processed.

Hi @keith!

Thank you! I think the problem is that I don’t have much experience with recursive workflows so I’m not sure how to implement what you’re saying, though I do understand what you mean. So I have a workflow, have all the actions that you describe up until the “Call the same workflow and send it the remaining list” part. So I don’t know what to add for Step 6:

The only way I know how to get close would be to set up 2 different workflows which trigger eachother until there are no more items on the list. But I don’t know how I would pass on the information resulting from the first workflow to the second one.

Thanks!

Watch this video. I use List Popper here in the way I describe:

This topic was automatically closed after 70 days. New replies are no longer allowed.