const durationToHumanReadable = (duration) => {
  if (!duration) return "N/A";

  let parts = [];

  let years = duration.years();
  let months = duration.months();
  let days = duration.days();
  let hours = duration.hours();
  let minutes = duration.minutes();
  let seconds = duration.seconds();

  if (years) parts.push(years + " year" + (years > 1 ? "s" : ""));
  if (months) parts.push(months + " month" + (months > 1 ? "s" : ""));
  if (days) parts.push(days + " day" + (days > 1 ? "s" : ""));
  if (hours) parts.push(hours + " hour" + (hours > 1 ? "s" : ""));
  if (minutes) parts.push(minutes + " minute" + (minutes > 1 ? "s" : ""));
  if (seconds) parts.push(seconds + " second" + (seconds > 1 ? "s" : ""));

  return parts.join(", ");
};
module.exports = durationToHumanReadable;
