I’m trying to design a scheduling app, but that someone is able to choose a time and day of the week that works for themselves, without necessarily choosing a particular date.
I’ve created basic data types for time, part of day, and day. Meaning that someone will be able to say that they are looking to have an early morning coffee, which would then only want to search the associated calendar for whatever is defined as early morning. Or similarly, I know that I want to schedule this dinner on a Friday night, but I don’t want to have to choose the specific date yet.
My question is that once I have a particular time - is there a format that I can programmatically save it in the date-time chooser? The documentation doesn’t exactly give a way to add time in a workflow.
Dates and time are stored as timestamps if you create fields using the date type. They are always stored as timestamps. There are various modifiers allowing you to extract, calculate and format those timestamps however you want… Such as just the date, just time, different styles, etc.
Scheduling apps are NOT the easiest thing to build if you have no familiarity with how dates and times (the same thing, really, date/times as I tend to call them) work in computing and in JS in particular.
You can learn a lot about date/time and date/time related issues by reading the docs for a package called moment and its extension moment-timezone: https://momentjs.com/
It seems clear that Bubble uses moment and moment timezone (and likely the moment-range package) to do many of its date/time related operations, though this hasn’t been confirmed here in the forum.
Bubble’s date/time manipulation functions are quite extensive (though not all capabilities of moment and moment-timezone are exposed to you the programmer/user, which is frankly infuriating but understandable).
There are, further (because you will need them), date range and date interval types available to you.
Here’s a quick rundown of what these data types represent:
DATE: A date describes a unique point in time. “Current date/time” is an example (representing “now”).
DATE RANGE: A date range describes a unique time period. “Current date/time<-range->Current date/time:plus days 5” is an example (representing now until 5 days from now).
DATE INTERVAL: A date interval describes the duration of a unique time period. The interval – the duration – itself is of course not unique. (5 seconds is just 5 seconds. But to construct a date interval you must first assume some unique time period like “Now until 5 minutes from now”. Now you have a date interval of 5 minutes duration. You could compare that to other intervals created from other unique date/times.) “Current date/time:plus seconds 5 - Current date/time” is an example (representing 5 seconds, the duration between now and 5 seconds from now – “duh”, I know).
So, the answer to “how exactly is time stored?” is “well, what sort of time are you attempting to store?” In Bubble, you have three options at present.
I take your question to mean, “how would I go about storing ‘30 minutes’ in Bubble?” Well, that’s a value of date interval type.
However, you will need all of these things in order to build your scheduling app. Another quick primer:
Let us say we want to make an APPOINTMENT object. (An object of Appointment data type which represents the creator of that object being “unavailable for your stupid request to meet with me and waste my valuable time”, right?)
That object will obviously have a start date and an end date (even if we assume this “Appointment” happens every day). Those are unique points in time.
That object has an implied (or you can make it explicitly stored) range: Appointment’s:start date <- range ->Appointment’s end date. Ranges have special operations which can tell you if some requested range is :contained by or :overlaps or other things with somebody’s request. You’ll need that.
That Appointment object also has an implied duration. (Again, you could explicitly store that if you wish – it may be more performant depending upon how often you need to compute that duration.) The duration is an interval constructed as Appointment’s end date - Appointment’s start date. (As an example, if the end is 45 minutes after the start, the duration is 45 minutes, eh?)
For more on all of this, search for any post where I’ve mentioned “date” or “date/time”. More on date ranges and how you should think about them (and what we can DO with them) can be found here:
I’ve not written much about date intervals. Intervals are not particularly interesting (though very useful) and – I gotta say – are probably misnamed. I’ve started to see people ask here about “how do I store 5 minutes?” (for example). The answer is as a date interval. Should “date intervals” be called “time”? I dunno… maybe. But Bubble nomenclature is (1) generally bad and (2) always evolving.
Anyway, if you read the post I link to above, you’ll start to understand further the use of various date representations. (The main thing is that they have different operators and different meanings for operations like less than, greater than, etc.)
I was going to stop here, but eff it… I’ll go on. Here’s why this is useful and important. Let’s consider what “less than” and “greater than” mean with respect to all three of the date/time data types:
What does it mean for a date (a unique point in time) to be < or > some other date?
A date is < some_other_date if date occurs in the past with respect to some_other_date.
A date is > some_other_date if date occurs in the future with respect to some_other_date.
2. What does it mean for a date range (a unique time period) to be < or > some other date range?
Trick question. There aren’t such operators for date ranges. Date ranges instead have a variety of states with respect to some other range:
A date_range is before some_other_date_range if date_range’s end is in the past with respect to some_other_date_range’s start.
A date_range is after some_other_date_range if date_range’s start is in the future with respect to some_other_date_range’s end.
A date_range overlaps some_other_date_range if date_range’s start is between some_other_date_range’s start and end OR if date_range’s end is between some_other_date_range’s start and end. (i.e., if it partly runs over – either on the start side or end side, or FULLY RUNS OVER – some_other_date_range)
A date_range is contained by some_other_date_range if date_range’s start is after some_other_date_range’s start AND date_range’s end is before some_other_date_range’s end. (i.e., if it is fully enclosed by some_other_date_range)
If date_range is contained by some_other_date_range, we can conversely say that some_other_date_range contains date_range, BTW.
3. What does it mean for a date interval to be < or > some other date interval?
This one is a lot easier (compared to #2 above). You can think about date intervals as being simple decimals, but decimals of time. I believe the resolution is milliseconds.
So, date_interval < some_other_date_interval if the number of ms represented by date_interval is less than the number of ms represented by some_other_date_interval.
Similarly, date_interval > some_other_date_interval if the number of ms represented by date_interval is greater than the number of ms represented by some_other_date_interval.
There’s a great deal more we can say about times and dates, but this will get you started!
It’s the missing chapter of the manual about dates and times. it’s been a while since I reread it… and it’s basically everything you need to know about this topic, which is definitely a confusing one at first!