23 lines
429 B
JavaScript
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;
|