How is time stored?

What @mebeingken says is all true. Additionally: Bubble essentially makes nodejs applications. Nodejs is just JavaScript, really. Dates in Bubble are just JavaScript dates (by which I mean the date data type is exactly the JavaScript date data type).

You are now saying, “I asked about time, not dates.” Times ARE dates. Dates in JavaScript always have a time component (as they should actually, even though this perplexes folks). So, just like in JS, you will use dates and date manipulation functions to deal with time.

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’ll want to understand JS date objects (start here: JavaScript Date Objects).

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:

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).

Anyway @ezra, times are stored in Bubble just like they are in JavaScript, as date objects (objects with a data type of “date”).

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:

  1. 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!