// Generated by CoffeeScript 1.12.5
'use strict';
moment.fn.isHoliday = function() {
  var locale;
  locale = this.localeData();
  if (locale._holidays) {
    if (locale._holidays.indexOf(this.format(locale._holidayFormat)) >= 0) {
      return true;
    }
  }
  if (locale.holiday) {
    if (locale.holiday(this)) {
      return true;
    } else {
      return false;
    }
  }
  return false;
};

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

moment.fn.businessDaysIntoMonth = function() {
  var businessDay, businessDaysIntoMonth, monthBusinessDays;
  businessDay = this.isBusinessDay() ? this : this.prevBusinessDay();
  monthBusinessDays = businessDay.monthBusinessDays();
  businessDaysIntoMonth = void 0;
  monthBusinessDays.map(function(day, index) {
    if (day.format('M/DD/YY') === businessDay.format('M/DD/YY')) {
      businessDaysIntoMonth = index + 1;
    }
  });
  return businessDaysIntoMonth;
};

moment.fn.businessDiff = function(param) {
  var d1, d2, daysBetween, end, start;
  d1 = this.clone();
  d2 = param.clone();
  start = d1 < d2 ? d1 : d2;
  end = d2 > d1 ? d2 : d1;
  daysBetween = 0;
  if (start === end) {
    return daysBetween;
  }
  while (start < end) {
    if (start.isBusinessDay()) {
      daysBetween++;
    }
    start.add(1, 'd');
  }
  return daysBetween;
};

moment.fn.businessAdd = function(number, options) {
  var day, remaining, signal;
  if (options == null) {
    options = {};
  }
  options.period || (options.period = 'days');
  day = this.clone();
  signal = number < 0 ? -1 : 1;
  remaining = Math.abs(number);
  while (remaining) {
    day.add(signal, options.period);
    if (day.isBusinessDay(options)) {
      remaining--;
    }
  }
  return day;
};

moment.fn.businessSubtract = function(number, options) {
  if (options == null) {
    options = {};
  }
  return this.businessAdd(-number, options);
};

moment.fn.nextBusinessDay = function() {
  var iterator, limit;
  iterator = 1;
  limit = 7;
  while (iterator < limit) {
    if (this.add(1, 'd').isBusinessDay()) {
      break;
    }
    iterator++;
  }
  return this;
};

moment.fn.prevBusinessDay = function() {
  var iterator, limit;
  iterator = 1;
  limit = 7;
  while (iterator < limit) {
    if (this.subtract(1, 'd').isBusinessDay()) {
      break;
    }
    iterator++;
  }
  return this;
};

moment.fn.monthBusinessDays = function(partialEndDate) {
  var day, daysArr, done, end, me;
  me = this.clone();
  day = me.clone().startOf('month');
  end = partialEndDate ? partialEndDate : me.clone().endOf('month');
  daysArr = [];
  done = false;
  while (!done) {
    if (day.isBusinessDay()) {
      daysArr.push(day.clone());
    }
    if (end.diff(day.add(1, 'd')) < 0) {
      done = true;
    }
  }
  return daysArr;
};

moment.fn.monthNaturalDays = function(fromToday) {
  var day, daysArr, done, end, me;
  me = this.clone();
  day = fromToday ? me.clone() : me.clone().startOf('month');
  end = me.clone().endOf('month');
  daysArr = [];
  done = false;
  while (!done) {
    daysArr.push(day.clone());
    if (end.diff(day.add(1, 'd')) < 0) {
      done = true;
    }
  }
  return daysArr;
};

moment.fn.monthBusinessWeeks = function(fromToday) {
  var day, daysArr, done, end, me, weeksArr;
  me = this.clone();
  day = fromToday ? me.clone() : me.clone().startOf('month');
  end = me.clone().endOf('month');
  weeksArr = [];
  daysArr = [];
  done = false;
  while (!done) {
    if (day.day() >= 1 && day.day() < 6) {
      daysArr.push(day.clone());
    }
    if (day.day() === 5) {
      weeksArr.push(daysArr);
      daysArr = [];
    }
    if (end.diff(day.add(1, 'd')) < 0) {
      if (daysArr.length < 5) {
        weeksArr.push(daysArr);
      }
      done = true;
    }
  }
  return weeksArr;
};

moment.fn.monthNaturalWeeks = function(fromToday) {
  var day, daysArr, done, end, me, weeksArr;
  me = this.clone();
  day = fromToday ? me.clone() : me.clone().startOf('month');
  end = me.clone().endOf('month');
  weeksArr = [];
  daysArr = [];
  done = false;
  while (!done) {
    daysArr.push(day.clone());
    if (day.day() === 6) {
      weeksArr.push(daysArr);
      daysArr = [];
    }
    if (end.diff(day.add(1, 'd')) < 0) {
      if (daysArr.length < 7) {
        weeksArr.push(daysArr);
      }
      done = true;
    }
  }
  return weeksArr;
};

if (typeof module !== 'undefined' && module.exports) {
  module.exports = moment;
}
