Date and Time data structuring

Because dates are hard, unfortunately, and JavaScript date handling confuses the issue somewhat. I’ve written a lot about this and provide some pointers to past helpful writings on this topic.

The main thing to understand (and understanding this will alleviate much confusion about dates) is this:

A date object (a thing of the date data type) describes a unique point in time.

A “date” in programming is not what you are thinking of when we colloquially talk about dates. In human heads, a “date” is usually what would be better described as a “calendar day.” So normal humans think about “dates” and “times” as being different.

In programming, this is not the case. Dates are times. Date objects (and their derivatives) are how we represent time. So you will often see me refer to such objects as date/time objects and not simply as dates, because this point cannot be driven home enough.

Let’s say that you and I want to schedule a Slack call for this coming Thursday and I tell you that I am available over “lunchtime” where I am (which will be San Francisco) and would be happy to chat. In our heads, we are like “OK, Thursday August 8th will be the date of our call” and, furthermore, “the time of our call will be Noon, Keith’s time”.

But neither of these things separately – “August 8th” “Noon” – are dates.

“August 8th 2019 at Noon, Keith’s time” could be a date as it describes a unique point in time.

And this point in time is the same point in time for both of us, of course. However, you and I would write it down differently:

I’d jot down 8/8/19 at 12:00 PM (San Francisco time). You’d jot down 8/8/19 at 7:00 PM (UK time).

That moment in time is the same for both of us, but at that particular hour of the day I might be eating lunch and you might be starting to think about dinner.

This is the difference between date construction (or date parsing) and date formatting.

And this is why we have lots of nice options in Bubble for formatting dates. We don’t have quite as nice a collection of options for date construction (and date construction is conceptually a bit difficult for the reasons discussed above), which is why I build things like Calendar Grid Pro and have written a lot about how one can use libraries like moment and moment-timezone to help.

Anyway, here’s more prattle about dates that is actually good reading!:

5 Likes