UNPKG

kibana-123

Version:

Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic

18 lines (13 loc) 530 B
var moment = require('moment'); // usually reverse = false on the request, true on the response module.exports = function offsetTime(milliseconds, offset, reverse) { if (!offset.match(/[-+][0-9]+[mshdwMy]/g)) { throw new Error ('Malformed `offset` at ' + offset); } var parts = offset.match(/[-+]|[0-9]+|[mshdwMy]/g); var add = parts[0] === '+'; add = reverse ? !add : add; var mode = add ? 'add' : 'subtract'; var momentObj = moment(milliseconds)[mode](parts[1], parts[2]); return momentObj.valueOf(); };