Background: I offer event bookings and capture existing bookings in a database collection. The user will book a date using datepicker but no time, and wix will automatically add 00:00 as the time.
When the site is loaded, the dates that are already booked are disabled in the datepicker based on a query of existing bookings in the collection - see code below.
The problem: The query returns different dates than the ones listed in the database, resulting in the wrong dates being disabled in the datepicker. It follows this pattern, apparantly subtracting 23 hours:
03/09/2019 00:00 (database) → 03/08/2019 01:00 (query result)
Thoughts:
- The query result is in my time zone (GTM+1) according to console, so time zones might be the problem.
- I only need to work with dates, so if I could just avoid times altogether that would be great
- Maybe I could just add 23 hours - but I need a solution that can’t fail due to the users’ time zone, system time, VPN, etc.
$w.onReady(function () {
wixData.query("Bookings")
.limit(1000)
.find()
.then((results) => {
const disabledDates = [];
for (let i = 0; i < results.items.length; i++) {
disabledDates.push(new Date(results.items[i].date.toISOString().slice(0,10)));
}
$w("#datePickerBook").disabledDates = disabledDates;
console.log( 'disabledDates' , disabledDates );
});
$w("#datePickerBook").minDate = new Date(2019,2,1);
});
Site: www.mystery-pubcrawl.dk (datepicker is visible on the frontpage)
I am lost. Can anyone please help?