{"size": 587, "ext": "js", "max_stars_repo_path": "src/returns/date/period-end.js", "max_stars_repo_name": "DEFRA/water-abstraction-helpers", "max_stars_repo_stars_event_min_datetime": "2020-09-21T13:57:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-21T13:57:48.000Z", "max_issues_repo_path": "src/returns/date/period-end.js", "max_issues_repo_name": "DEFRA/water-abstraction-helpers", "max_issues_repo_issues_event_min_datetime": "2018-12-11T13:06:11.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-13T19:54:30.000Z", "max_forks_repo_path": "src/returns/date/period-end.js", "max_forks_repo_name": "DEFRA/water-abstraction-helpers", "max_forks_repo_forks_event_min_datetime": "2020-03-10T08:00:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-10T21:32:49.000Z"}
{"max_stars_count": 1, "max_issues_count": 155, "max_forks_count": 2, "avg_line_length": 26.6818181818, "max_line_length": 71, "alphanum_fraction": 0.6780238501}
const moment = require('moment');
const { getPeriodStart } = require('./period-start');

/**
 * Given a particular date and a isSummer flag, calculates the end date
 * of the returns cycle that date lies in
 * @param {String} date - comparison date
 * @param {Boolean} isSummer - whether summer return
 * @return {String} YYYY-MM-DD period end date
 */
const getPeriodEnd = (date, isSummer) => {
  const startDate = getPeriodStart(date, isSummer);
  return moment(startDate)
    .add(1, 'year')
    .subtract(1, 'day')
    .format('YYYY-MM-DD');
};

module.exports = {
  getPeriodEnd
};
