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

26 lines (21 loc) 809 B
import moment from 'moment'; export default { toString: function (range, format) { if (!range.from) { return 'Before ' + format(range.to); } else if (!range.to) { return 'After ' + format(range.from); } else { return format(range.from) + ' to ' + format(range.to); } }, parse: function (rangeString, format) { let chunks = rangeString.split(' to '); if (chunks.length === 2) return {from: moment(chunks[0], format), to: moment(chunks[1], format)}; chunks = rangeString.split('Before '); if (chunks.length === 2) return {to: moment(chunks[1], format)}; chunks = rangeString.split('After '); if (chunks.length === 2) return {from: moment(chunks[1], format)}; throw new Error('Error attempting to parse date range: ' + rangeString); } };