So I'm trying to implement booking (reservations) on the website which offers online services and I want the dates and time (working days and hours) for the end user to be shown correctly, taking into consideration timezones, DST and and all that tricky stuff. The actual location of the service providers are on timezone +5, and the working hours are from 8am to 5pm. So what I want the actual user, for example, on timezone +4 to see is working hours being 7am - 4pm.
For the time being I'm using Angular Material Datepicker to store dates, and Angular Material Select with hardcoded hours.
But this is not optimal at all, and I could only get away with notifying users that the time shown is of specified timezone.
I also tried to follow this guide, but to no avail.
I have installed moment and moment-timezone but cannot figure it out yet.
I store booked dates and hours in firebase, and retrieve them with angular/fire like so
table: Table;
this.db.list('timetable').valueChanges()
.subscribe(table => this.table = table);
Then I grab the value from the datepicker input and check which working hours are available
selectedDate: string;
hours = hours; // a list of objects with hardcoded working hours in it, like {hour: "8:00", booked: false}, {hour: "9:00", booked: true} etc.
selectDate(e: MatDatepickerInputEvent<Date>) {
this.selectedDate = new Date(e.target.value).toLocaleDateString();
const bookedHours: string[] = [];
this.table.forEach((booking) => {
if (this.selectedDate === booking.date) {
bookedHours.push(booking.hour);
}
});
this.hours.forEach(time => {
if (bookedHours.includes(time.hour)) {time.booked = true;
} else { time.booked = false; }
});
}
And if 10am is booked, for example, it looks like this:
I know that the implementation is poor and hacky and I'm open for suggestions on that as well.