Changing a "Dates" to "Date Ranges"

Does anyone know how to change data that is in the form of “Date” to be formatted as a “Date Range”?

For context, I have a scheduling feature that lets Users book meetings with each other. It currently works by searching for a list of ‘Date Ranges’ that show the start and end time of existing meetings.

I am now connecting it to Google Calendar API and the list of events retrieved from the data call are only retrieved in “Date” format. Trying to figure out how to manipulate those list of events to be “Date Ranges.”

If anyone knows how to do what I am trying to achieve, it would be a huge help to me!

Thanks

If you have a date range already, you can extract the start and end by using the :start and :end operators:
Screenshot_31

If you are receiving the start and end dates separately from an API and you want to change that to a range in your database, you can use the <-range-> operator:


(it will automatically set the “later” date as the end date if you did them reversed by accident)

1 Like

Okay, that is a good start. It works for converting a single date (with start and end time) to a date range.

Now, I am still unsure how to convert a list of dates to date ranges. Any ideas?

Doing this in states to figure it out btw:

Hey @openocean.tampa ,

You can try this solution for storing the start and end times. First, create a field name time with field type date range.

Screen Shot 2022-12-05 at 11.07.42 AM

Then use two date & time Picker elements in order to save start and end time.

Create a workflow on a button when you want to save time.

Screen Shot 2022-12-05 at 11.22.05 AM

Once you save the data in the database. Now again pick the date & time picker element and do the following steps shown in the screenshot to set the start and end date:

end date

If any further assistance is required get in touch with me on:
LinkedIn:- Karamjit Singh - Aprintaa - Rank First To Earn Fast! | LinkedIn
Gmail:- karamwise@gmail.com

Hey Karam! Appreciate the helpful suggestion. However, not sure if this is what I need for my use case. All of the dates I am getting are coming from an API call of the User’s Google Calendar events. So it is coming in as a list of 50+ events sometimes.

I need to convert all of those events that have a start date and an end date to be date ranges. Additionally, I would never be personally looking at my User’s events list, so it would need to be an automated approach. I will add that I have created a temporary work around that accomplishes what I need, but is certainly not sustainable for the platform or ideal in any means. I will detail that below…

For anyone who sees this and wants a temporary solution to achieve this, I will explain what I am doing now below. If anyone has a better idea on how to achieve the desired conversion of a list of events that have start and end dates into a list of events with date ranges, THAT DOESN’T require you to create additional items on the database and/or less workflows, please do share!

Okay, here is what I am doing (can add screenshots later if anyone actually needs):

  1. There is a workflow on my app that ‘gets’ the User’s list of calendar events from their Google Calendar and sets a state on an element with that list of events.

  2. I created a new data type in my database called “External Meetings,” it’s fields are User, Date Range, Calendar, and Title.

  3. I created a backend workflow that is an API workflow. It has the keys User (type User), Start Date (type date), and End Date (type date). Then the actions of this workflow are

  • Create a new Calendar Event (with the start, end, and User)
  • Create a new External Meeting (again this stores the user, the user’s calendar, and now converts the start and end times to a date range
  1. Another workflow schedules an API workflow on a list (calendar items retrieved from User’s Google Calendar). This is where all the key details get sent to that backend workflow (User, and list of events). Right now I just have this on the page for the user, but that may change.

  2. Now I merge the User’s list of External Meetings (google cal events): each item’s date range and the list of User’s Meetings (meetings created on our platform): each item’s date range, to show the User’s availability on a calendar/scheduling buildout I have.

There is obviously a ton more complexity to all of this, but that is how I am doing the specific workaround for converting dates to date ranges.

Hey @openocean.tampa, sorry I didn’t see your reply to me, Bubble is a little weird with doing parallel operations in the front end, there’s a few plugins that can help with that but a vanilla way would be to use the backend to do a recursive workflow.

But quick question, is the Google Calender API really returning a list of start dates, then a list of end dates? Doesn’t it send each event as a JSON object in start/end pairs?

The reason I ask is if it returns each event in pairs you can do a recursive workflow or a “Schedule a workflow on a list” and create your events using the :start :end operators I mentioned previously.

Otherwise a recursive workflow can still take your current setup, take 1st “start”, take 1st “end”, do the operators I mentioned, create the event, subtract those two, run it again looping until it’s done.

Hey @tylerboodman that’s okay! And hmm :face_with_monocle:, I honestly have never done much with recursive workflows and had to just look them up. It seems like it is pretty similar to what I have done with the “schedule workflow on a list,” except that it works in a loop.

So is it better from a capacity standpoint to run a recursive workflow “loop,” then to just schedule the workflow on a list? Or is there any other reason why one method would be better than the other?

And to answer your previous question; No, it is returning a list of events which contains both the start dates and end dates as separate dates. So I believe that is what you mean by “start/end pairs.”

Recursive is better on capacity, but in theory slower because it goes one by one. I usually process 10-20 things per loop which actually speeds it up quite a bit. I seem to have bad luck with “Schedule on a list” where it gives up after ~30 items.

I’ve had 1000+ items processed using a recursive workflow, as long as I give it enough time. Recursive Scheduled Workflows - Bubble Docs

You could actually benefit from using the built in Data API, you can take the response from the Calendar API, and form the call right there to your own app to bulk create all the events at once. Data API - Bubble Docs

I can make an example later today.

1 Like

Try this, set up the Data API call:


To initialize the call just do some dummy call like the datatype paremeter being event, and the body being {"name":"test"}

Of course change your app URL to yours, and you will want to set the authorization to “Private key in header” and make it “Bearer [your api key]” you generate a key in the app settings-> API tab. Also the Data API needs to be enabled on your app and a privacy rule set for that datatype to allow “Create via API”

Then you form the JSON body like this, the delimiter I just pressed “enter” so it’s a linebreak.

Again docs are here: https://manual.bubble.io/core-resources/api/data-api#bulk-create-new-things

EDIT: my example stores the dates as individual fields, but you would do one field for the date range and do the <-range-> like before.

Sweet, this is awesome! I am going to try this out later this week when I have some more time to dig into it. Again, really appreciate the help and will lyk if I run into any issues/have any other questions!

1 Like

Did you figure out how to do this without writing to the database?

Kind of… I had to hire an agency to build out some custom API integrations. It still isn’t perfect either.