<commit_before>const moment = require('moment');
const debug = require('debug')('app:server:components:CalendarUtils');
require('moment-range');

function findWorkdaysInRange(startDate, endDate, targetMonth, targetYear) {
  const targetMonthStartDate = moment().utc().year(targetYear).month(targetMonth).startOf('month');
  const targetMonthEndDate = moment().utc().year(targetYear).month(targetMonth).endOf('month');

  const wholeMonthRange = moment.range(targetMonthStartDate, targetMonthEndDate);

  // Set the start and end times
  const startMoment = moment(startDate).utc().startOf('day');
  const endMoment = moment(endDate).utc().endOf('day');

  debug('Start Date %s End Date %s', startMoment, endMoment);
  debug('Whole month range "%s"', wholeMonthRange.toString());

  // Find the part of the date range that is completely within the month.
  let range = moment.range(startMoment, endMoment);
  debug('Date range "%s"', range.toString());

  range = range.intersect(wholeMonthRange);

  if (range === null) {
    debug('Dates are not within the specified month');
    return 0;
  }

  debug('Intersected date range "%s"', range.toString());

  let workdays = 0;
  console.log('Starting count');
  range.by('days', (currentMoment) => {
    const currentDay = currentMoment.day();
    if (currentDay !== 0 && currentDay !== 6) {
      console.log('Found workday: ' + currentDay + currentMoment.toString());
      // Increment all days that are not Saturday or Sunday
      workdays++;
    } else {
      console.log('Found non-workday: ' + currentDay);
    }
  });
  console.log('Total workdays: ' + workdays);

  return workdays;
}

module.exports = {findWorkdaysInRange};
<commit_msg>Cleaned up the code a bit.  #5<commit_after>const moment = require('moment');
const debug = require('debug')('app:server:components:CalendarUtils');
require('moment-range');

function findWorkdaysInRange(startDate, endDate, targetMonth, targetYear) {
  // Find the start and end of the target month.  Use UTC.
  const targetMonthStartDate = moment().utc().year(targetYear).month(targetMonth).startOf('month');
  const targetMonthEndDate = moment().utc().year(targetYear).month(targetMonth).endOf('month');
  const wholeMonthRange = moment.range(targetMonthStartDate, targetMonthEndDate);

  // Set the start and end times.  Use UTC to keep in sync with the target month.
  const startMoment = moment(startDate).utc().startOf('day');
  const endMoment = moment(endDate).utc().endOf('day');

  debug('Start Date %s End Date %s', startMoment, endMoment);
  debug('Whole month range "%s"', wholeMonthRange.toString());

  // Find the part of the date range that is completely within the month.
  let range = moment.range(startMoment, endMoment);
  debug('Date range "%s"', range.toString());

  range = range.intersect(wholeMonthRange);

  if (range === null) {
    debug('Dates are not within the specified month');
    return 0;
  }

  debug('Intersected date range "%s"', range.toString());

  let workdays = 0;
  range.by('days', (currentMoment) => {
    const currentDay = currentMoment.day();
    if (currentDay !== 0 && currentDay !== 6) {
      // Increment all days that are not Saturday or Sunday
      workdays++;
    }
  });

  return workdays;
}

module.exports = {findWorkdaysInRange};

{'fraction_non_alphanumeric': 0.14606741573033707, 'fraction_numerical': 0.002733070148800486, 'mean_word_length': 4.5641891891891895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2212765', 'n_tokens_mistral': 998, 'n_tokens_neox': 967, 'n_words': 268}