pond icon indicating copy to clipboard operation
pond copied to clipboard

Rollup with Moment duration or certain duration factory methods generates error

Open jscottsf opened this issue 7 years ago • 5 comments

The happy path works:

series.fixedWindowRollup({
  window(duration('1h')),
  aggregation: {v_sum: ['v', sum()]}
})

However, the following does not work, and generates TypeError: Cannot read property 'mid' of undefined:

series.fixedWindowRollup({
  window(duration(moment.duration(1, 'h'))),
  aggregation: {v_sum: ['v', sum()]}
})

Other variants have issues too:

duration(moment.duration(1, 'h').asMilliseconds())

But, if you hack the _string property, it works!

const d = duration(moment.duration(1, 'h').asMilliseconds())
d._string = '1h' // Normally is PT1H when moment is used

So it seems that rollups are sensitive to the string property?

jscottsf avatar Jun 14 '18 15:06 jscottsf

Hi @jscottsf Here are a few tests for the duration code - https://github.com/esnet/pond/blob/master/packages/pond/tests/duration.test.ts

it("can construct one with a moment", () => {
        const p = duration(moment.duration(24, "hours"));
        expect(+p).toBe(86400000);
    });

In your case, use it as duration(moment.duration(1, "hour"))

sartaj10 avatar Jun 14 '18 20:06 sartaj10

Actually, the duration itself is created correctly. It's that the duration created via a moment cannot be used in a fixedWindowRollup since the rollup produces an error.

jscottsf avatar Jun 14 '18 21:06 jscottsf

Ah, okay. Got it. I'll look into it, thanks

sartaj10 avatar Jun 14 '18 22:06 sartaj10

@sartaj10 can you add a test or two to reproduce this?

pjm17971 avatar Jun 22 '18 14:06 pjm17971

I'm fairly sure this is the same bug - I was unable to produce a fixedWindowRollup with any_Durations, receiving the same error. (I'm on the latest Typescript alpha)

Modifying the Duration toString method to be:

toString(): string {
    return `${this._duration}l`
  }

Works for me.

The util.timeRangeFromIndexString function doesn't expect an ms time suffix.

The regex and timerange construction there could be modified to accept ms, or alternatively just passing exactly what it expects works?

Mike-Dax avatar Apr 06 '19 15:04 Mike-Dax