Closed palday closed 2 years ago
FWIW I'm not sure we'd be able to use that definition verbatim, since start(t) + stop(t)
will be a Nanosecond
and may be odd, so dividing by 2 will throw an InexactError
.
Relatedly, what should middle(TimeSpan(0, 1))
return? It can't actually be represented in the precision provided by TimeSpans, nor by the Dates stdlib.
Yeah, the edge cases occurred to me later. In both cases, I would say round down to the nearest whole Nanosecond because the spans are half-open intervals, so rounding down is line with "include the lower bound but not the upper".
So I guess the definition would be fld(start(t) + stop(t), 2)
then.
May as well just let the user have the option of choosing the rounding mode and do:
Statistics.middle(t::TimeSpan, r::RoundingMode=RoundToZero) = div(start(t) + stop(t), 2, r)
I think it might make sense to define
I have a few uses for it. If it sounds generally useful, I'll open a PR.