parseSeconds = function (str, date) {
  date = moment(date); // defaults to now if no date is provided

  if (str === '' || str === 'now') {
    return date.unix();
  }

  let m, n;
  if ((m = str.match(/^([+-])(\d*)([a-z]*)([@]*)([a-z0-9]*)/))) {
    const format = str2format(m[3]);
    const snap = str2format(m[5]);

    if (m[2] === '') {
      m[2] = 1;
    }

    if (snap) {
      date.startOf(snap);
      if ((n = m[5].match(/^(w|week|weeks)(\d+)$/))) {
        date.day(n[2]);
      }
    }

    date.add((m[1] === '-' ? -1 : 1) * m[2], format);
    return date.unix();
  }

  if ((m = str.match(/^@([a-z0-9]+)/))) {
    const snap = str2format(m[1]);

    date.startOf(snap);
    if ((n = m[1].match(/^(w|week|weeks)(\d+)$/))) {
      date.day(n[2]);
    }
    return date.unix();
  }

  return moment(str, ['YYYY/MM/DDTHH:mm:ss', 'YYYY/MM/DDTHH:mm:ssZ', moment.ISO_8601]).unix();
}
Parses the current time to seconds based on a relative time
(+/- seconds/minutes/hours/days/weeks/months/quarters/years)

@example
'{{ -5h | parseSeconds }}'
this.$options.filters.parseSeconds('-5d');

@param {string} str The relative time string
@param {int} date   The date to use as the base, default = now