I am creating a todo where the default date should be set to + 3 days but only weekdays. I'm using vue so think a computed of some sort should work?
DateTime.utc().plus({ days: 3 }).toFormat('yyyy-MM-dd HH:mm:ss'),
So how can I exclude Saturday and Sunday here? I've tried googling but haven't been able to find a solution..
the best solution is to use the package luxon-business-day
but if you don't want to add anything you can :
const dayToAdd = 3;
const DateTime = luxon.DateTime;
var nextSaturday = DateTime.utc().startOf('week').plus({ week: 1 }).minus({days: 2});
var dayDifference = nextSaturday.diff(DateTime.utc(), ["days"]).toObject().days;
var addAfterWeekend = 0;
if (dayDifference < dayToAdd) {
addAfterWeekend = dayToAdd - dayDifference;
}
var date = DateTime.utc().plus({ days: dayToAdd + addAfterWeekend });
console.log(date.toFormat('yyyy-MM-dd HH:mm:ss'));
<script src="https://cdn.jsdelivr.net/npm/luxon@1.21.1/build/global/luxon.min.js"></script>