eduolalo / moment-business-days

This is a momentJS plugin that allows you to use only business days (Monday to Friday)
MIT License
240 stars 67 forks source link

Extra bussnes day in a week #92

Closed ZoranderTheRealOne closed 3 years ago

ZoranderTheRealOne commented 3 years ago

Hi

depend on locale i have 5 (work day)+ 2 (holiday) extra holiday i add via
var days = [day, day ...] moment.updateLocale('ru', {holidays: days, holidayFormat: 'MM.DD.YYYY'});

But some week in a month have 6 + 1(holiday), so is it possible add extra work day for certain day?

mcdado commented 3 years ago

If I understand correctly you want to define custom business days just like you specify custom holidays.

Right now I don't think it's possible, without specifying always 6 business days and then for the remaining 11 months specify custom holidays for the weekend. I know, it sucks but it is what works right now.

ZoranderTheRealOne commented 3 years ago

Yes you right. I little bit drill source and find out it :( So work should be done and i modified one function similar functionality isHoliday.

moment.fn.isBusinessDay = function () {
  var locale = this.localeData();
  var defaultWorkingWeekdays = [1, 2, 3, 4, 5];
  var workingWeekdays = locale._workingWeekdays || defaultWorkingWeekdays;
  if (locale._businessdays) {
    if (locale._businessdays.indexOf(this.format(locale._businessdayFormat)) >= 0) {
      return true;
    }
  }
  if (this.isHoliday()) return false;
  if (workingWeekdays.indexOf(this.day()) >= 0) return true;
  return false;
};

 moment.updateLocale('ru', { holidays: hdays, holidayFormat: 'MM.DD.YYYY', businessdays: bdays, businessdayFormat: 'MM.DD.YYYY' });

May be not good code but works for me

mcdado commented 3 years ago

Fixed in https://github.com/kalmecak/moment-business-days/pull/94