i’m currently working on a “reservation” project, where people can reserve a room for a certain amount of days/weeks/month.
There is no SQL DB included and the room reservations should be found via Client JS.
Now here comes my question: What is the best data structure and programming algorithm to solve the problem?
I started of with a simple list of “available” timespans:
var available = [ [from, to], [from, to], ... ]
The “from” and “to” where initially JS Dates, but i soon switched to Unix Timestamp because of performance.
Now, some days into the project and added live data, i realized that it might be easier to inverse my logic. So “var available” is now “var unavailable”. This also has the advantage for the room manager to add just the timespan where the room becomes unavailable and by default the rooms are available.
Due to my involvement into the project, i got the impression that i might miss some more important points about finding a quick and easy way to find available timespans. Does anyone have some more insights about timespan structure and programming? I don’t want to redo this task over and over again because of me realizing that my basics (structure and algo) are wrong.
Any links, or hints are greatly appreciated!
P.S. Using moment.js (with the “contain” method (= a plugin for moment.js)) is performance wise not a good solution.