Time literal arithmetic
From ifql created by nathanielc : influxdata/ifql#216
https://github.com/influxdata/influxdb/issues/6881 https://github.com/influxdata/influxdb/issues/8153
Should be able to convert between times, durations and ints.
This should work well with #317
317 above is likely the wrong repo.
Some questions about time literal arithmetic:
When dividing Durations, do we want to return an Int or a Float? This makes a difference when dividing a smaller duration by a larger one
> 1m / 1d
0.0006944444444444445 or 0
Is the following ok?
> 1y / 1d
364
> 1mo / 1d
28
Should we be able to subtract times and receive a duration (in ns) as a result? Should we be able to add/subtract durations?
Dividing durations should be a float and 1mo / 1d should be 30 for now. When we implement duration vectors it will change.
Should we be able to subtract times and receive a duration (in ns) as a result?
Yes the different of two times is a duration
Should we be able to add/subtract durations?
Yes, add/subtracting durations will produce durations Adding/subtracting durations with times will produce times.
Adding/subtracting durations with times will require the type system to support polymorphic literals. See #476 for a discussion. But duration or time arithmetic is already supported by the type system. All that's needed is to update the interpreter to support it. I.e adding new binary function signatures to values/binary.go.
Clarification. Adding and subtracting duration values is supported by the by the type signature of + and -. Every binary arithmetic operator has the following type signature:
forall ['a] ('a, 'a) -> 'a
Given polymorphic literals, the above type signature supports adding or subtracting time and duration values together. However, it does not support adding two values of the same type together and producing a new different type as is the case with duration division producing a float.
We will need specific operators in order to support duration division returning a float, as well as time subtraction returning a duration. In other words we cannot overload the (/) and (-) operators to support these use cases.
was this solved by https://github.com/influxdata/flux/pull/1592 ?
or also https://v2.docs.influxdata.com/v2.0/reference/flux/stdlib/experimental/addduration/ ?