Skip to content

Commit

Permalink
accept bounds on time expression
Browse files Browse the repository at this point in the history
  • Loading branch information
mcbrewster committed Sep 15, 2023
1 parent 53bd4c3 commit 24c122c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/expressions/baseExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export interface ExpressionValue {
mvArray?: string[];
ipToSearch?: Ip;
ipSearchType?: string;
bounds?: string;
}

export interface ExpressionJS {
Expand Down Expand Up @@ -290,6 +291,7 @@ export interface ExpressionJS {
mvArray?: string[];
ipToSearch?: Ip;
ipSearchType?: string;
bounds?: string;
}

export interface ExtractAndRest {
Expand Down
11 changes: 9 additions & 2 deletions src/expressions/timeRangeExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ export class TimeRangeExpression extends ChainableExpression implements HasTimez
public duration: Duration;
public step: number;
public timezone: Timezone;
public bounds: string;

constructor(parameters: ExpressionValue) {
super(parameters, dummyObject);
this.duration = parameters.duration;
this.step = parameters.step || TimeRangeExpression.DEFAULT_STEP;
this.timezone = parameters.timezone;
this.bounds = parameters.bounds;
this._ensureOp('timeRange');
this._checkOperandTypes('TIME');
if (!(this.duration instanceof Duration)) {
Expand All @@ -59,6 +61,7 @@ export class TimeRangeExpression extends ChainableExpression implements HasTimez
value.duration = this.duration;
value.step = this.step;
if (this.timezone) value.timezone = this.timezone;
if (this.bounds) value.bounds = this.bounds;
return value;
}

Expand All @@ -67,6 +70,7 @@ export class TimeRangeExpression extends ChainableExpression implements HasTimez
js.duration = this.duration.toJS();
js.step = this.step;
if (this.timezone) js.timezone = this.timezone.toJS();
if (this.bounds) js.bounds = this.bounds;
return js;
}

Expand All @@ -75,6 +79,7 @@ export class TimeRangeExpression extends ChainableExpression implements HasTimez
super.equals(other) &&
this.duration.equals(other.duration) &&
this.step === other.step &&
this.bounds === other.bounds &&
immutableEqual(this.timezone, other.timezone)
);
}
Expand All @@ -99,9 +104,9 @@ export class TimeRangeExpression extends ChainableExpression implements HasTimez
if (operandValue === null) return null;
const other = duration.shift(operandValue, timezone, step);
if (step > 0) {
return new TimeRange({ start: operandValue, end: other });
return new TimeRange({ start: operandValue, end: other, bounds: this.bounds });
} else {
return new TimeRange({ start: other, end: operandValue });
return new TimeRange({ start: other, end: operandValue, bounds: this.bounds });
}
}

Expand All @@ -112,6 +117,8 @@ export class TimeRangeExpression extends ChainableExpression implements HasTimez
// HasTimezone mixin:
public getTimezone: () => Timezone;
public changeTimezone: (timezone: Timezone) => TimeRangeExpression;
public getBounds: () => String;
public changeBounds: (bounds: String) => TimeRangeExpression;
}

Expression.applyMixins(TimeRangeExpression, [HasTimezone]);
Expand Down

0 comments on commit 24c122c

Please sign in to comment.