how can I convert time ranges like “&from=now-1M/M&to=now-1M/M” to epoch time?
Use Case: I execute JavaScript Code in the HTML plugin by aidanmountford. My code shall consider the selected time range. Currently, I take the “from” and “to” value from the browser URL. For absolute time ranges, I get already absolute epoch time but for the other options not. I was already pointed to rangeutil.ts but I don’t know if/how I can access this function from my JavaScript code.
Currently, I see no other way than re-implementing the complete date parsing on my own which is obviously not a good approach.
let tr = angular.element('grafana-app').injector().get('timeSrv').timeRange();
let from = new Date(tr.from._d).toISOString();
let to = new Date(tr.to._d).toISOString();