influxdb icon indicating copy to clipboard operation
influxdb copied to clipboard

CQ current interval start time calculated wrong

Open dgnorton opened this issue 11 years ago • 2 comments

When a CQ is run, the start time of the current interval is:

interval, err := cq.q.GroupByInterval()
startTime := now.Round(interval)

Half way through an interval, the current interval gets rounded up (into the future) to the next interval. It should use now.Truncate(interval) instead.

dgnorton avatar Oct 26 '15 13:10 dgnorton

Hi @dgnorton , I think the start time calculated is right. After startTime := now.Round(interval), the following code is

if startTime.UnixNano() > now.UnixNano() {
        startTime = startTime.Add(-interval)
    }

That can get the same result with now.Truncate(interval), but the now.Truncate(interval) is more simple and clear.

li-ang avatar Oct 28 '15 07:10 li-ang

@li-ang truncating gives a different result because it will align with an interval boundary. now - interval shifts the starting point so that it's not in the future but it may not be aligned with an interval boundary.

dgnorton avatar Oct 28 '15 14:10 dgnorton