const moment = require('moment');


const ExpirationUnits = {
  Hours: 'h',
  Days: 'd',
  Weeks: 'w',
  Months: 'M',
  Years: 'y',

  apply: (expiration, date) =>
  {
    if (!expiration) return null;

    let reference = moment(date);
    if (!reference.isValid())
      reference = moment();

    return reference.add(expiration.value, expiration.units).toDate();
  }
}

module.exports = ExpirationUnits;