Skip to content

Commit d3733ae

Browse files
committed
fix origin calc
1 parent cb5b9f1 commit d3733ae

File tree

1 file changed

+10
-5
lines changed
  • packages/cubejs-client-core/src

1 file changed

+10
-5
lines changed

packages/cubejs-client-core/src/time.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,16 @@ export const dayRange = (from: any, to: any, annotations?: Record<string, { gran
217217
const intervalParsed = parseSqlInterval(customGranularity.interval);
218218
let intervalStart = internalDayjs(from);
219219

220-
// If custom granularity has an origin, align to it
221-
if (customGranularity.origin) {
222-
let origin = internalDayjs(customGranularity.origin);
223-
if (customGranularity.offset) {
224-
origin = addInterval(origin, parseSqlInterval(customGranularity.offset));
220+
// origin and offset are mutually exclusive
221+
// If either is specified, align to it
222+
if (customGranularity.origin || customGranularity.offset) {
223+
let origin;
224+
if (customGranularity.origin) {
225+
// Absolute origin time
226+
origin = internalDayjs(customGranularity.origin);
227+
} else {
228+
// offset is relative to start of year
229+
origin = addInterval(internalDayjs().startOf('year'), parseSqlInterval(customGranularity.offset!));
225230
}
226231

227232
// Align the value to the origin to find the actual bucket start

0 commit comments

Comments
 (0)