Access timepicker range from within visualization plugin

I am trying to access the queried date range from within a plugin, so that I can do calculations based on the length of time being queried. Is there a way to do this?

For example, I may have an aggregated sum of hits and I want to calculate the average number of hits per second and display that number in the visualization.

Hi Nathan!

If you are using Angular, then timefilter is an available service.

Here's where the timefilter is defined: http://github.com/lukasolson/kibana/blob/master/src/ui/public/timefilter/timefilter.js#L48

And here's an example of how to use it: https://github.com/lukasolson/kibana/blob/master/src/core_plugins/kibana/public/dashboard/index.js#L56

I'd suggest using timefilter.getBounds() to accomplish what you're trying to do.

Thank you very much! I was able to get the length of time with:
var ms = Date.parse($scope.timefilter.getBounds().max._d) - Date.parse($scope.timefilter.getBounds().min._d);