Recv/lib/expirationunits.js

23 lines
429 B
JavaScript
Raw Normal View History

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;