Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add business days #279

Open
marcwales opened this issue Nov 17, 2021 · 1 comment
Open

Add business days #279

marcwales opened this issue Nov 17, 2021 · 1 comment

Comments

@marcwales
Copy link

marcwales commented Nov 17, 2021

Hi,

I hope this is still active, i was using the original datejs for years but now i see this upgrade which i needed since the beginning ;) I just can't seem to make it work. Here is the original code :

  <script>
  var fromDate = Date.today().addDays(5);
  if (fromDate.is().saturday() || fromDate.is().sunday()) { 
  fromDate = fromDate.next().monday();
  }
  var toDate = Date.today().addDays(10);
  if (toDate.is().saturday() || toDate.is().sunday()) { 
  toDate = toDate.next().monday(); 
  }
  document.getElementById('fromDate').innerHTML = fromDate.toString('dddd dd-MM-yyyy');
  document.getElementById('toDate').innerHTML = toDate.toString('dddd MMMM dS');
  </script> 

I tired to change this : var fromDate = Date.today().addWeekdays(5);

But it doesn't work.

Hope someone can help me on this.

Rgds,
Marc

@DanTheManGude
Copy link

I haven't ran this to test, but from reading your snippet I think the issue is that the date returned after calling addDays could have skipped over the weekend. Checking if it is Saturday or Sunday only works if the result happened to be one of those day. If today is Wednesday, then adding 5 days puts it at Monday which is only 3 weekdays from then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants