Converting Interval to milliseconds (or some Unit of time)

I am interested in converting an Interval (“TEN_MINUTE”, “HALF_HOUR”, “DAY”, etc.) to a corresponding number of milliseconds.

I imagine there is a Type that has such a method since we probably do some mapping of these intervals to step size in the metric engine. Can someone please point me to it?

If it’s not available to me, I can create my own mapping, but I was thinking this might already exist.

Thank you,

You could use Period.fromString('1d').toDuration().milliseconds()

Thanks Rohit, Sounds like I need to build a mapping between the “DAY” interval and the ‘1d’ Period?

Is there a way to avoid any mapping and go straight from Interval to milliseconds?

Also, copying and pasting Period.fromString('1d').toDuration().milliseconds() into static console produced an error:

You can use Expr.eval:

Expr.eval("period(1, 'MINUTE')")
Expr.eval("period(1, 'TEN_MINUTE')")
Expr.eval("period(1, 'QUARTER_HOUR')")
Expr.eval("period(1, 'HOUR')")
Expr.eval("period(1, 'DAY')")
Expr.eval("period(1, 'MONTH')")
1 Like