-2

I am using calendar in react js. I am trying to disable entire current week. Right now, I am able to set min date min={new Date(2019, 7, 29)} so till today past dates are disabled.But as per requirement,if week already started then user can not select entire current week. i.e today's date is 07/29/2019 so till 08/04/2019 dates should be disable. My week starts from Monday and ends on Sunday.I am also using lodash library if any function of it can be usable to achieve this functionality. TIA.

  • 1
    Hi! Can you share more information so we can help you? Code you tried, error you get (if any). What calendar library do you use in your app? Screenshots if it can help see what's wrong and the expected behavior. – Pandaiolo Jul 29 '19 at 16:53
  • Hi! totally depends on the library that you are using? There is nothing to do with react in this. –  Jul 29 '19 at 16:57
  • I am using mobiscroll calendar. I tried to count current week but not able to do it. If Wednesday is current date then adding 7 days logic will not work.i.e. 07/31/2019 is current date then entire week will be disabled. – user11853415 Jul 29 '19 at 17:05

1 Answers1

0

check the current date and alter your starting date accordingly.

let minDate = newDate();
const today = new Date();
if (today.getDay() === 0) { // note: this returns 0-7 with 0 being sunday 
  // its sunday, set min date to tomorrow(beginning of your week)
  minDate = minDate.setDate(today.getDate()+1);
} else { // now we know its monday - sat
  const offset = 8 - today.getDay(); // this is the number of days till the next week.
  minDate = minDate.setDate(today.getDate()+offset);
}
Aaron Ross
  • 141
  • 1
  • 5