Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ranges for date, time and date time #27

Merged
merged 1 commit into from
Sep 30, 2023
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
20 changes: 17 additions & 3 deletions src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,15 +826,15 @@ function createRange(start, end, startIncluded = true, endIncluded = true) : Ran
}

if (isTyped('time', [ start, end ])) {
throw notImplemented('range<time>');
return createDateTimeRange(start, end, startIncluded, endIncluded);
}

if (isTyped('date time', [ start, end ])) {
throw notImplemented('range<date and time>');
return createDateTimeRange(start, end, startIncluded, endIncluded);
}

if (isTyped('date', [ start, end ])) {
throw notImplemented('range<date>');
return createDateTimeRange(start, end, startIncluded, endIncluded);
}

if (start === null && end === null) {
Expand Down Expand Up @@ -995,6 +995,20 @@ function createNumberRange(start, end, startIncluded, endIncluded) {
});
}

function createDateTimeRange(start, end, startIncluded, endIncluded) {
const map = noopMap();
const includes = anyIncludes(start, end, startIncluded, endIncluded);

return new Range({
start,
end,
'start included': startIncluded,
'end included': endIncluded,
map,
includes
});
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function cartesianProduct(arrays: any[]) {

Expand Down
49 changes: 42 additions & 7 deletions test/builtins-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,21 +472,56 @@ describe('builtin functions', function() {

exprSkip('duration("P5D") in (duration("P4D"), >=duration("P6D"))', true);

exprSkip(`
expr(`
date and time("2018-12-08T10:30:01") in [
date and time("2018-12-08T10:30:02")
..
date and time("2018-12-08T10:30:04")
]
`, false);
expr(`
date and time("2018-12-08T10:30:02") in [
date and time("2018-12-08T10:30:02")
..
date and time("2018-12-08T10:30:04")
]
`, true);

exprSkip(`
time("10:30:05") in (time("10:30:04"), >=time("10:30:05"))
expr(`
date and time("2018-12-08T10:30:03") in [
date and time("2018-12-08T10:30:02")
..
date and time("2018-12-08T10:30:04")
]
`, true);

exprSkip(`
date("2018-12-02") between date("2018-12-02") and date("2018-12-04")
expr(`
date and time("2018-12-08T10:30:04") in [
date and time("2018-12-08T10:30:02")
..
date and time("2018-12-08T10:30:04")
]
`, true);
expr(`
date and time("2018-12-08T10:30:05") in [
date and time("2018-12-08T10:30:02")
..
date and time("2018-12-08T10:30:04")
]
`, false);

expr('time("10:30:03") in (time("10:30:04"), >=time("10:30:05"))', false);
expr('time("10:30:05") in (time("10:30:04"), >=time("10:30:05"))', true);

expr('date("2018-12-01") between date("2018-12-02") and date("2018-12-04")', false);
expr('date("2018-12-02") between date("2018-12-02") and date("2018-12-04")', true);
expr('date("2018-12-03") between date("2018-12-02") and date("2018-12-04")', true);
expr('date("2018-12-04") between date("2018-12-02") and date("2018-12-04")', true);
expr('date("2018-12-05") between date("2018-12-02") and date("2018-12-04")', false);

expr('date("2018-12-01") in [date("2018-12-02") .. date("2018-12-04")]', false);
expr('date("2018-12-02") in [date("2018-12-02") .. date("2018-12-04")]', true);
expr('date("2018-12-03") in [date("2018-12-02") .. date("2018-12-04")]', true);
expr('date("2018-12-04") in [date("2018-12-02") .. date("2018-12-04")]', true);
expr('date("2018-12-05") in [date("2018-12-02") .. date("2018-12-04")]', false);

});

Expand Down