Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions web-admin/src/features/bookmarks/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { V1Bookmark } from "@rilldata/web-admin/client";
import { isHomeBookmark } from "@rilldata/web-admin/features/bookmarks/selectors.ts";
import { cleanUrlParams } from "@rilldata/web-common/features/dashboards/url-state/clean-url-params.ts";
import { parseRillTime } from "@rilldata/web-common/features/dashboards/url-state/time-ranges/parser.ts";
import { isAbsoluteTimeRange } from "@rilldata/web-common/features/dashboards/url-state/time-ranges/parser.ts";
import { ExploreStateURLParams } from "@rilldata/web-common/features/dashboards/url-state/url-params";
import { prettyFormatTimeRange } from "@rilldata/web-common/lib/time/ranges/formatter.ts";
import { type DashboardTimeControls } from "@rilldata/web-common/lib/time/types.ts";
Expand Down Expand Up @@ -223,12 +223,7 @@ function isAbsoluteTimeRangeBookmark(bookmarkUrlParams: URLSearchParams) {
const timeRange = bookmarkUrlParams.get(ExploreStateURLParams.TimeRange);
if (!timeRange) return false;

try {
const rt = parseRillTime(timeRange);
return rt.isAbsoluteTime();
} catch {
return false;
}
return isAbsoluteTimeRange(timeRange);
}

export function isFilterOnlyBookmark(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
{#if activeTimeGrain && interval}
<Comparison
{minTimeGrain}
maxDate={minDate}
minDate={maxDate}
{minDate}
{maxDate}
timeGrain={activeTimeGrain}
timeComparisonOptionsState={comparisonOptions}
selectedComparison={selectedComparisonTimeRange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class RillTime {
public asOfLabel: RillTimeAsOfLabel | undefined = undefined;

public isOldFormat = false;
public isAbsolute = false;

public constructor(public readonly interval: RillTimeInterval) {
this.updateIsComplete();
Expand All @@ -58,6 +59,7 @@ export class RillTime {
interval instanceof RillLegacyIsoInterval ||
interval instanceof RillLegacyDaxInterval ||
interval instanceof RillAllTimeInterval;
this.isAbsolute = interval instanceof RillIsoInterval;
}

public withGrain(grain: string) {
Expand Down Expand Up @@ -100,10 +102,6 @@ export class RillTime {
}
}

public isAbsoluteTime() {
return this.interval instanceof RillIsoInterval;
}

public toString() {
let timeRange = this.interval.toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ export function isNewRillTimeFormat(rillTime: string): boolean {
}
}

export function isAbsoluteTimeRange(rillTime: string): boolean {
try {
const parser = parseRillTime(rillTime);
return parser.isAbsolute;
} catch {
return false;
}
}

export function validateRillTime(rillTime: string): Error | undefined {
try {
const parser = parseRillTime(rillTime);
Expand Down
27 changes: 27 additions & 0 deletions web-common/src/lib/time/comparisons/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@ const contiguousAndCustomComparisonRanges = [
end: new Date("2020-03-05T06:05:00.000Z"),
},
},
// custom cases
{
description:
"should return the parsed range when comparison is a custom absolute range",
input: {
start: new Date("2020-03-05T00:00:00.000Z"),
end: new Date("2020-03-06T00:00:00.000Z"),
comparison: "2024-01-01T00:00:00.000Z,2024-02-01T00:00:00.000Z",
},
output: {
start: new Date("2024-01-01T00:00:00.000Z"),
end: new Date("2024-02-01T00:00:00.000Z"),
},
},
{
description:
"should return the parsed range when comparison is a custom absolute range using an interval separator",
input: {
start: new Date("2020-03-05T00:00:00.000Z"),
end: new Date("2020-03-06T00:00:00.000Z"),
comparison: "2024-01-01T00:00:00.000Z/2024-02-01T00:00:00.000Z",
},
output: {
start: new Date("2024-01-01T00:00:00.000Z"),
end: new Date("2024-02-01T00:00:00.000Z"),
},
},
];

const periodStart = new Date("2020-03-05T00:00:00.000Z");
Expand Down
14 changes: 12 additions & 2 deletions web-common/src/lib/time/comparisons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
TimeOffsetType,
TimeRangePreset,
} from "../types";
import { isNewRillTimeFormat } from "@rilldata/web-common/features/dashboards/url-state/time-ranges/parser.ts";
import {
isAbsoluteTimeRange,
isNewRillTimeFormat,
} from "@rilldata/web-common/features/dashboards/url-state/time-ranges/parser.ts";

export function getComparisonTransform(
start: Date,
Expand Down Expand Up @@ -322,7 +325,14 @@ export function getComparisonInterval(
comparisonRange: string | undefined,
activeTimeZone: string,
): Interval<true> | undefined {
if (!interval || !comparisonRange || isNewRillTimeFormat(comparisonRange))
// New format ranges are resolved by the backend, so there is nothing to compute here.
// Absolute ranges are the exception: they carry their own start and end, so they are parsed below.
if (
!interval ||
!comparisonRange ||
(isNewRillTimeFormat(comparisonRange) &&
!isAbsoluteTimeRange(comparisonRange))
)
return undefined;

let comparisonInterval: Interval | undefined = undefined;
Expand Down
Loading