timespan.js 412 B

123456789101112131415161718
  1. var ms = require('ms');
  2. module.exports = function (time, iat) {
  3. var timestamp = iat || Math.floor(Date.now() / 1000);
  4. if (typeof time === 'string') {
  5. var milliseconds = ms(time);
  6. if (typeof milliseconds === 'undefined') {
  7. return;
  8. }
  9. return Math.floor(timestamp + milliseconds / 1000);
  10. } else if (typeof time === 'number') {
  11. return timestamp + time;
  12. } else {
  13. return;
  14. }
  15. };