0

I am trying to show availability for specific resorts over the course of a month. The resorts all have different rooms and different week end days based on the room. I need to be able to show valid check in days based on availability with respect to their week end days.

That probably does not make too much sense so let me elaborate. Let's assume person A wants to book a room for 3 days. In order for a check in day to be valid the room has to have continuous availability (I.E. Available 05/03, 05/06, 05/07, and 05/08 -The check in day does not count towards the three day stay). In order for the check in day to be valid it also must respect the week end day. For example Let's assume the person wants to book a 3 day stay in a one bedroom unit with a week end day of Saturday. Assuming continuous availability this would mean that valid check in days would be the following: (Saturday, Sunday, Monday, Tuesday, and Wendsday) and we would need to filter out availability on Thursday and Friday

This is where I am struggling a bit. The API endpoint that I am calling returns availability as datetime strings. I originally thought that I could just call the Date.getDay() function on the Date and then check if the week end date was greater than the day + duration of stay. However the getDay function returns 0 for Sunday, 1 for Monday, etc. so most numbers would be greater than these days. For instance if the week end day is a Sunday any number would be greater than 0 and therefore the room would show no availability.

Another option I thought of was to create a hashgraph with all the possible combination of days, but this would be a lot of work so I would like to avoid it if possible. I am hoping that there is an easy enough solution that I am not thinking of.

Alex
  • 1
  • 4
  • If you convert the datestring into a Date instance, you can then use `>` `<` to compare the dates. – hamza765 Apr 21 '22 at 22:43
  • Does this answer your question? [Compare two dates with JavaScript](https://stackoverflow.com/questions/492994/compare-two-dates-with-javascript) – hamza765 Apr 21 '22 at 22:44
  • Potentially. The only other thing I would have to consider is how to add the duration. I think that I can do that with string manipulation or the Temporal NPM package. Thank you for the recource. – Alex Apr 22 '22 at 00:02
  • @hamza765—if the dates are in an ISO 8601 compatible format, they can be compared as strings just as effectively. – RobG Apr 22 '22 at 00:40
  • This question is way too vague to be useful. Comparison of dates and difference between dates in days (hours, minutes, etc.) have been covered many, many times before. If you have coding issues, post code that demonstrates the issue and you might get help. Otherwise, answers will be opinion based and not much help to anyone else. – RobG Apr 22 '22 at 00:44

0 Answers0