helpers.js 644 B

1234567891011121314151617181920212223242526272829303132
  1. const moment = require('moment');
  2. module.exports = {
  3. /**
  4. * Takes an expression such as 30d and returns a moment object of that date in future
  5. *
  6. * Key Shorthand
  7. * ==================
  8. * years y
  9. * quarters Q
  10. * months M
  11. * weeks w
  12. * days d
  13. * hours h
  14. * minutes m
  15. * seconds s
  16. * milliseconds ms
  17. *
  18. * @param {String} expression
  19. * @returns {Object}
  20. */
  21. parseDatePeriod: function (expression) {
  22. let matches = expression.match(/^([0-9]+)(y|Q|M|w|d|h|m|s|ms)$/m);
  23. if (matches) {
  24. return moment().add(matches[1], matches[2]);
  25. }
  26. return null;
  27. }
  28. };