How to use the range funtions - e.g of how to use it

Hi,

I am looking for examples of how to develop workflow comands with the range functions. Whenever I try I get red!

I have looked at the manual but it only informs us what it does. Not how it can be inserted into a workflow. Do you have any ideas? Examples?

Continuing the discussion from Saving the dates between two dates as things:

2 Likes

Hi @rachel.camp900 :slight_smile: Does this example help?

If not, what do you need the workflow to do in your app? Can you share a link to the editor?

1 Like

This was driving me crazy recently too. The date range info in the manual (along with a lot of other manual references) only tells you what it does, not how to use it! Looking forward to Bubble doing their revamp of the help documentation, apparently it’s on their roadmap.

7 Likes

Thanks both. Nice to know that I am not the only one who has got stuck here. So many people on the forum are flying through it.

I am spending real time reading the article you sent. Lots of information in here, I have not got to the bit where we can use a single date range yet.

@fayewatson I will try what you have suggested. I guess what is really confusing me is how it is saved in the database. How many fields do I need? Should they be lists?

A link to my app is below

I guess the difference with the thread you suggested is that the date/time picker had not been created.

Ideally I would love to learn how to use this plugin because the app is on mobile - so the fewer the elements the better

If you want to use the Air Date/Time picker plugin to save range values its straightforward.
You save range values the same way you save any other value.

If you want to save a list of date range values you need to have a field whose type is a List of date range.

1 Like

OK: A Quick Primer on Date Ranges

What is a date? You are probably familiar with the date data type. A date describes a unique point in time.

(Remember: Whenever we are talking about “dates”, we are actually talking about date/time objects. When we casually say “date” we should always remember that what we are saying is “a date/time”.)

A date represents some point in time. A date may be before some other date (in which case it is “in the past” with respect to some other date and would be “less than” that other date). A date may be after some other date (in which case it is “in the future” with respect to some other date and it would be “greater than” that other date).

So, knowing what dates are… what is the date range data type? A date range describes a unique time period.

These unique time periods are defined by a start date/time and an end date/time. The are constructed using the “<- range ->” operator possessed by objects of date type. You make one like this:

date_x ← range → date_y

Doing this creates an object of date range type. The lesser of the two dates becomes the date range’s :start. The greater of the two dates becomes the date range’s :end. In a workflow, it might look like this:

^^^ Here we create a date range stored as a local variable (custom state). This date range goes from “now” (the time this workflow step runs) to “30 seconds from now”.

Here’s another one:

^^^ Here we create a date range that goes from “now” to “15 seconds from now”.

Applications:

In the same way that various date operations allow you to compare points in time, date range operations allow you to compare time periods.

Do you need to know if some point in time is within some time period? (You want to know if date_x is within some start date/time and some end date/time.)

Do you need to know if some time period is within some other time period? Do you want to know if some time period overlaps with some other time period?

Well, date range operations can answer these (and other) questions.

Look at the examples above. You already know that the second time period (My Other Date Range) is within the first time period (My Date Range). But how would our app know?

The :contains Operator

The Reference, as you note, is incomplete (and sort of incorrect) about the various date range operators. The :contains operator is how we tell is one date range is fully enclosed by another date range.

My Date Range:contains My Other Date Range will be “yes” if My Other Date Range is entirely within My Date Range.

The :contains point Operator

The :contains point operator is missing from the reference. This operator is used to tell us if a single date (a single point in time) is within a date range (a time period).

Let us say we have a date object (a single point in time). We can understand if that date is within some date range using the :contains point operator. My workflow above has a third step like this:

So now we could check if that date is inside of one of the previously constructed date ranges like this:

My Date Range:contains point Some Date will be “yes” if Some Date is after the start of My Date Range, but before the end of My Date Range. It will be “no” otherwise.

Let’s put this into practice. Here’s the page that executes the workflow action I’ve been describing. When the button here is clicked, it makes these date ranges and dates. Then a text element tells us about them:

The expressions which yield these results are shown here in edit mode:

Other Things We Could do With Date Ranges

There are of course other things we can do vis-a-vis time periods. Here are the other options. (And now the documentation about them should make more sense.)

Of these, “overlaps with” is one of the most useful. Suppose you have a date range that represents a haircut appointment for Albert with stylist Carlos. Now Betty wants to book an appointment with Carlos. Is Betty’s desired appointment available? (It IS NOT if Betty’s selected date range “overlaps with” Albert’s appointment date range.)

So there you go: That’s what date ranges are for.

Note: Date ranges do NOT have to be stored in the database or stored in a local variable (custom state) to be useful. We can usually construct a date range on the fly inside of any expression.

Let us say we have 4 date objects: datew, datex, datey and datez

Is datez between datex and datey? That’s: datex<- range ->datey:contains point datez

Does the time period datew to datex overlap with time period datey to datez? That’s:

datew<- range ->datex:overlaps with datey<- range ->datez

Etc., etc.

40 Likes

Hi Keith,

This is amazing thank you. I have read your response three times and I am getting ready to start my own versions to absorb what you have told me.

While I do this I am hoping that you could help me clarify and answer one question :slight_smile: I am sure I will have more in the doing but for now this is what I have got.

STEP ONE CREATING DATE RANGES

In your examples you had one date that was entered by the user and then you already knew the duration of the event. (e.g +(days): 5

the second example you showed how having one button you could save a date range by having a start date in one field and an end date in another and you combine the two date entries into a date range in the data base.

Do you have an example of when you use the date picker and it allows you to select a range in one field? I would like to learn how to use this for the mobile applications (space is finite here)

STEP TWO

Condition on dates - I am going to get the first bit learnt and then move onto the CONTAINS functions. That was going to be the next round of questions I was going to ask the forum so thank you!

Ok @fayewatson and @keith

@keith

So i need my events to be saved into a calendar and attendance recorded against them. SO does this mean a custom state is not suitable. At this point I can not see a scenario when you create an event but do not want to save it in the data base.

@fayewatson The problem is that I do not want my event to be one month. The user defines the start date and the end date. SO the duration is different every time.

Sorry for being frustrating.

Best,

Rachel

Good News! I have progress!!!

The missing piece was in the element itself! Please see below:

image

I then have the workflow below:

image

I have it saving as a list of ranges and as just ranges. Date range L = List I have done both because i do not know the pros and cons of each method. You both have recommended a list of ranges. Why is that? I have no idea what the consequences are of choosing one over the other?

image

Well, you’re going to wind up with a list anyway. At present, what you are doing in workflow Step 1 in your second screenshot is creating a new thing (a new Calendar Constraint) with:

  1. A date range field. and…
  2. A list of date ranges field which will only ever have one item in it.

IF you desire to create individual Calendar Constraint objects, use a solo date range field (#1) and forget about (#2) – it’s not helping you.

Why do I say you’re going to wind up with a list anyway? Well, consider this: After you create a bunch of these Calendar Constraints, how do you get at them? Well, you might “Do a search for…” objects of that type. What that will return is a LIST of those objects, right?

IF your use case is that there’s some field on some other object that should represent the “Calendar Constraints”, then that field should probably be a list of date ranges.

The question comes down to this:

Is your app just managing ONE master calendar? If so, you can just have a Calendar Constraints type object with a solo date range field on it. Is there more than one “Calendar” in your system? (Or multiple subtypes of Calendars, basically?) If so, you’ll want to associate these date ranges representing constraints with a field on some other data type (like “Calendar”) that is a list of date ranges.

Where you are right now is where I was hoping to get you: You now know how to construct a date range. Further, you understand how to associate it with some other object. You understand how to make a single item and you sort of understand how make a list of such items.

Now you need to think about what it is you need to do with these things and design your data model in such a way that it will meet those goals.

Hi Keith,

When working on ranges would you put it as a restraint (the only When section)?

I guess I am asking because my end goal is when someone enters an event into the calendar and they have already put in a date range to indicate that the club is closed it will stop the workflow. It will then show a pop up that contains the conflicts and they can delete one of the events so the conflict is removed.

Ideally the workflow will automatically continue but if not then they will have the option to clear the whole command and start again.

This means I will have to learn your logic and enter it into the pop up logic and the repeating table.

Does this sound like my logic and the road I am starting to travel down sound correct. It is taking me a bit longer to learn this bit.

Yeah, so here’s what you’re saying:

  1. A user is picking some dates (a start and end date so you can represent them as a range).

  2. Once the user has picked those dates (specified a date range), you want to do something with them. Like add those to the list of times that your club is booked, I suppose?

  3. Of course, you don’t want to allow them to book that date range IF the club is not available.

  4. So what you need to do is check that the selected range does not overlap with previously blocked date ranges, right? If it DOES overlap, send the user back to square one. If it DOES NOT overlap, proceed to block the dates.

  5. You are correct: The way you do (or do not do) something when some value is true or false is using “Only when…” conditions on workflows or individual steps within a workflow.

If you’re having trouble getting your head around this, you might just wanna make some pages that are rather simpler and play around there. Like, make a page that has some checkboxes on it. Also on that page, put a button. Now, build a workflow that – when the button is clicked – does different things based on which checkboxes are checked. That might help build your confidence in executing workflows and workflow steps conditionally.

Hi Keith,

I think I have date ranges down now but I am still working on the overlap function.

What I am having difficulty is that what I am doing is not quite the same as your demo - I have learnt lots but I just cannot seem to get over the finish line.

  1. I have a list of calendar date entries that already exist.
  2. Member of staff enters in a club closed date. These date entries are entered and data entries are created on two separate pages - this is different to your example that checks for overlaps. Your example shows items that are generated at the same time on the same page.
  3. I need the work flow to throw up an error message listing the duplicates/ cause and corrective measures. Of course I need point 2 to work first.

The print screen below is my attempt to apply your logic in previous posts. I think I am falling down because i do not know how to reference the data that already exists in the database? I can put in the first item…but i need it to check all the items not just a random one or the last one. This is assuming that my understanding of this approach is correct.

You will see i have created a custom state, once reading through your posts i understood this feature to only be needed if you want to create a delayed action and is not relevant to this specific overlapping feature. If you could confirm that my understanding is correct that would be fab.

Any further words of wisdom will be greatly received. Your posts are great - you provide me enough information to figure things out myself. Granted it takes me forever but I really feel like am learning a huge amount so thank you.

Here: Examine this very simple demo project. This does everything you’re trying to do. Here’s the run mode:

And here’s the editor (it’s set to anyone can view but not edit):

3 Likes

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