How to use the plywood.TimeRange function in plywood

To help you get started, we’ve selected a few plywood examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github allegro / turnilo / src / client / components / date-range-picker / date-range-picker.tsx View on Github external
calculateHoverTimeRange(mouseEnteredDay: Date) {
    const { startTime, endTime } = this.props;
    let hoverTimeRange: TimeRange = null;
    if (startTime && !endTime) {
      let start = startTime;
      let end = mouseEnteredDay;
      // if mousing over backwards, set end to old start time
      if (mouseEnteredDay < startTime) {
        start = mouseEnteredDay;
        end = startTime;
      }
      hoverTimeRange = new TimeRange({ start, end, bounds: "[]" });
    }

    this.setState({ hoverTimeRange });
  }
github allegro / turnilo / src / common / models / granularity / granularity.mocha.ts View on Github external
it("getsBestBucketUnit appropriately for time defaults depending on coarse flag", () => {
    const month = "P1M";
    const week = "P1W";
    const day = "P1D";
    const twelveHours = "PT12H";
    const sixHours = "PT6H";
    const oneHour = "PT1H";
    const fiveMinutes = "PT5M";
    const oneMinute = "PT1M";

    const yearLength = new TimeRange({ start: new Date("1994-02-24T00:00:00.000Z"), end: new Date("1995-02-25T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(yearLength, false).toString()).to.equal(week);
    expect(getBestBucketUnitForRange(yearLength, true).toString()).to.equal(month);

    const monthLength = new TimeRange({ start: new Date("1995-02-24T00:00:00.000Z"), end: new Date("1995-03-25T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(monthLength, false).toString()).to.equal(day);
    expect(getBestBucketUnitForRange(monthLength, true).toString()).to.equal(week);

    const sevenDaysLength = new TimeRange({ start: new Date("1995-02-20T00:00:00.000Z"), end: new Date("1995-02-28T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(sevenDaysLength, false).toString()).to.equal(oneHour);
    expect(getBestBucketUnitForRange(sevenDaysLength, true).toString()).to.equal(day);

    const threeDaysLength = new TimeRange({ start: new Date("1995-02-20T00:00:00.000Z"), end: new Date("1995-02-24T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(sevenDaysLength, false).toString()).to.equal(oneHour);
    expect(getBestBucketUnitForRange(threeDaysLength, true).toString()).to.equal(twelveHours);

    const dayLength = new TimeRange({ start: new Date("1995-02-24T00:00:00.000Z"), end: new Date("1995-02-25T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(dayLength, false).toString()).to.equal(oneHour);
    expect(getBestBucketUnitForRange(dayLength, true).toString()).to.equal(sixHours);

    const fourHours = new TimeRange({ start: new Date("1995-02-24T00:00:00.000Z"), end: new Date("1995-02-24T04:00:00.000Z") });
github allegro / turnilo / src / common / models / granularity / granularity.mocha.ts View on Github external
it("getsBestBucketUnit appropriately for time with bucketing and custom granularities", () => {
    const sixHours = "PT6H";
    const oneHour = "PT1H";
    const week = "P1W";

    const dayLength = new TimeRange({ start: new Date("1995-02-24T00:00:00.000Z"), end: new Date("1995-02-25T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(dayLength, false).toString()).to.equal(oneHour);
    expect(getBestBucketUnitForRange(dayLength, false, granularityFromJS("PT6H")).toString()).to.equal(sixHours);

    const yearLength = new TimeRange({ start: new Date("1994-02-24T00:00:00.000Z"), end: new Date("1995-02-25T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(yearLength, false, granularityFromJS("PT6H")).toString()).to.equal(week);

    const customs = ["PT1H", "PT8H", "PT12H", "P1D", "P1W"].map(granularityFromJS);
    expect(getBestBucketUnitForRange(dayLength, false, null, customs).toString()).to.equal(oneHour);

    const fortyFiveMin = new TimeRange({ start: new Date("1995-02-24T00:00:00.000Z"), end: new Date("1995-02-24T00:45:00.000Z") });
    expect(getBestBucketUnitForRange(fortyFiveMin, false, null, customs).toString()).to.equal(oneHour);

  });
github allegro / turnilo / src / common / models / filter-clause / filter-clause.ts View on Github external
      const elements = values.map(value => new TimeRange(value));
      return expression.overlap(r(new PlywoodSet({ elements, setType: "TIME_RANGE" })));
github geo-opensource / pivot / src / client / components / time-filter-menu / time-filter-menu.tsx View on Github external
function makeDateIntoTimeRange(input: Date, timezone: Timezone): TimeRange {
  return new TimeRange({ start: second.shift(input, timezone, - 1), end: second.shift(input, timezone, 1) });
}
github allegro / turnilo / src / common / models / granularity / granularity.mocha.ts View on Github external
expect(getBestBucketUnitForRange(monthLength, false).toString()).to.equal(day);
    expect(getBestBucketUnitForRange(monthLength, true).toString()).to.equal(week);

    const sevenDaysLength = new TimeRange({ start: new Date("1995-02-20T00:00:00.000Z"), end: new Date("1995-02-28T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(sevenDaysLength, false).toString()).to.equal(oneHour);
    expect(getBestBucketUnitForRange(sevenDaysLength, true).toString()).to.equal(day);

    const threeDaysLength = new TimeRange({ start: new Date("1995-02-20T00:00:00.000Z"), end: new Date("1995-02-24T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(sevenDaysLength, false).toString()).to.equal(oneHour);
    expect(getBestBucketUnitForRange(threeDaysLength, true).toString()).to.equal(twelveHours);

    const dayLength = new TimeRange({ start: new Date("1995-02-24T00:00:00.000Z"), end: new Date("1995-02-25T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(dayLength, false).toString()).to.equal(oneHour);
    expect(getBestBucketUnitForRange(dayLength, true).toString()).to.equal(sixHours);

    const fourHours = new TimeRange({ start: new Date("1995-02-24T00:00:00.000Z"), end: new Date("1995-02-24T04:00:00.000Z") });
    expect(getBestBucketUnitForRange(fourHours, false).toString()).to.equal(fiveMinutes);
    expect(getBestBucketUnitForRange(fourHours, true).toString()).to.equal(oneHour);

    const fortyFiveMin = new TimeRange({ start: new Date("1995-02-24T00:00:00.000Z"), end: new Date("1995-02-24T00:45:00.000Z") });
    expect(getBestBucketUnitForRange(fortyFiveMin, false).toString()).to.equal(oneMinute);
    expect(getBestBucketUnitForRange(fortyFiveMin, true).toString()).to.equal(fiveMinutes);

  });
github allegro / turnilo / src / common / models / granularity / granularity.mocha.ts View on Github external
const fiveMinutes = "PT5M";
    const oneMinute = "PT1M";

    const yearLength = new TimeRange({ start: new Date("1994-02-24T00:00:00.000Z"), end: new Date("1995-02-25T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(yearLength, false).toString()).to.equal(week);
    expect(getBestBucketUnitForRange(yearLength, true).toString()).to.equal(month);

    const monthLength = new TimeRange({ start: new Date("1995-02-24T00:00:00.000Z"), end: new Date("1995-03-25T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(monthLength, false).toString()).to.equal(day);
    expect(getBestBucketUnitForRange(monthLength, true).toString()).to.equal(week);

    const sevenDaysLength = new TimeRange({ start: new Date("1995-02-20T00:00:00.000Z"), end: new Date("1995-02-28T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(sevenDaysLength, false).toString()).to.equal(oneHour);
    expect(getBestBucketUnitForRange(sevenDaysLength, true).toString()).to.equal(day);

    const threeDaysLength = new TimeRange({ start: new Date("1995-02-20T00:00:00.000Z"), end: new Date("1995-02-24T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(sevenDaysLength, false).toString()).to.equal(oneHour);
    expect(getBestBucketUnitForRange(threeDaysLength, true).toString()).to.equal(twelveHours);

    const dayLength = new TimeRange({ start: new Date("1995-02-24T00:00:00.000Z"), end: new Date("1995-02-25T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(dayLength, false).toString()).to.equal(oneHour);
    expect(getBestBucketUnitForRange(dayLength, true).toString()).to.equal(sixHours);

    const fourHours = new TimeRange({ start: new Date("1995-02-24T00:00:00.000Z"), end: new Date("1995-02-24T04:00:00.000Z") });
    expect(getBestBucketUnitForRange(fourHours, false).toString()).to.equal(fiveMinutes);
    expect(getBestBucketUnitForRange(fourHours, true).toString()).to.equal(oneHour);

    const fortyFiveMin = new TimeRange({ start: new Date("1995-02-24T00:00:00.000Z"), end: new Date("1995-02-24T00:45:00.000Z") });
    expect(getBestBucketUnitForRange(fortyFiveMin, false).toString()).to.equal(oneMinute);
    expect(getBestBucketUnitForRange(fortyFiveMin, true).toString()).to.equal(fiveMinutes);

  });
github allegro / turnilo / src / common / models / granularity / granularity.mocha.ts View on Github external
expect(getBestBucketUnitForRange(sevenDaysLength, false).toString()).to.equal(oneHour);
    expect(getBestBucketUnitForRange(sevenDaysLength, true).toString()).to.equal(day);

    const threeDaysLength = new TimeRange({ start: new Date("1995-02-20T00:00:00.000Z"), end: new Date("1995-02-24T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(sevenDaysLength, false).toString()).to.equal(oneHour);
    expect(getBestBucketUnitForRange(threeDaysLength, true).toString()).to.equal(twelveHours);

    const dayLength = new TimeRange({ start: new Date("1995-02-24T00:00:00.000Z"), end: new Date("1995-02-25T00:00:00.000Z") });
    expect(getBestBucketUnitForRange(dayLength, false).toString()).to.equal(oneHour);
    expect(getBestBucketUnitForRange(dayLength, true).toString()).to.equal(sixHours);

    const fourHours = new TimeRange({ start: new Date("1995-02-24T00:00:00.000Z"), end: new Date("1995-02-24T04:00:00.000Z") });
    expect(getBestBucketUnitForRange(fourHours, false).toString()).to.equal(fiveMinutes);
    expect(getBestBucketUnitForRange(fourHours, true).toString()).to.equal(oneHour);

    const fortyFiveMin = new TimeRange({ start: new Date("1995-02-24T00:00:00.000Z"), end: new Date("1995-02-24T00:45:00.000Z") });
    expect(getBestBucketUnitForRange(fortyFiveMin, false).toString()).to.equal(oneMinute);
    expect(getBestBucketUnitForRange(fortyFiveMin, true).toString()).to.equal(fiveMinutes);

  });