Skip to content

Commit 16de73e

Browse files
committed
Migrate implementation of interval pointFrom from elm layer to datatype
1 parent 4d1d9f7 commit 16de73e

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/datatypes/interval.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,17 @@ export class Interval {
647647
}
648648
}
649649

650+
pointFrom() {
651+
const start = this.start();
652+
if (cmp.equals(start, this.end())) {
653+
return start;
654+
}
655+
656+
throw new Error(
657+
'PointFrom operator may only be used on an interval containing a single point.'
658+
);
659+
}
660+
650661
toString() {
651662
const start = this.lowClosed ? '[' : '(';
652663
const end = this.highClosed ? ']' : ')';

src/elm/interval.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { convertUnit, compareUnits, convertToCQLDateUnit } from '../util/units';
55
import * as dtivl from '../datatypes/interval';
66
import { Context } from '../runtime/context';
77
import { build } from './builder';
8-
import { equals } from '../util/comparison';
98
import { ELM_NAMED_TYPE_SPECIFIER } from '../util/elmTypes';
109

1110
export class Interval extends Expression {
@@ -211,16 +210,7 @@ export class PointFrom extends Expression {
211210
if (interval == null) {
212211
return null;
213212
}
214-
const start = interval.start();
215-
const end = interval.end();
216-
217-
if (start == end || equals(start, end)) {
218-
return start;
219-
}
220-
221-
throw new Error(
222-
'PointFrom operator may only be used on an interval containing a single point.'
223-
);
213+
return interval.pointFrom();
224214
}
225215
}
226216

0 commit comments

Comments
 (0)