Recv/lib/expirationunits.js
2018-05-02 20:07:09 +02:00

23 lines
429 B
JavaScript

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;