Skip to content

Commit dd09d09

Browse files
committed
Add more context to comment for normalizeInterval
1 parent 0a06b37 commit dd09d09

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

examples/browser/cql4browsers.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,8 +2410,25 @@ exports.Interval = Interval;
24102410
// - high open boundary that is uncertainty from min value of type or interval low value to max
24112411
// value of type is changed to null open boundary
24122412
//
2413-
// TODO: Is this necessary? Do we care how it is represented if the representations have the same
2414-
// meaning? This does affect test expectations and representation of returned results for callers.
2413+
// Justification: Since interval operations now use start() and end() to calculate and construct
2414+
// intervals, results involving unbounded lows and highs will return boundaries with concrete
2415+
// minimum and maximum values instead of the more familiar closed null boundary representations.
2416+
// Similarly, results involving unknown lows and highs will return boundaries with uncertainty
2417+
// ranges rather than the more familiar open null boundary representations. In other words,
2418+
// intervals that started out looking "simple", such as Interval[null, 0], can result in new
2419+
// intervals with specific values that are not obvious to users, such as Interval[-2147483648, 0].
2420+
//
2421+
// The normalizeInterval function recognizes those situations and converts the interval back to an
2422+
// equivalent form that is more likely to be familiar to all users. The results of this approach
2423+
// are also more consistent with previous implementations that did not use start() and end().
2424+
// Note that in all cases, the pre-normalized and normalized intervals are semantically the same
2425+
// (i.e., they represent the same exact range) even if they are represented using different
2426+
// individual component values (i.e., low, high, lowClosed, and highClosed values).
2427+
//
2428+
// Examples:
2429+
// - Interval[-2147483648, 10] --> Interval[null, 10]
2430+
// - Interval[Uncertainty(-2147483648, 0), 10] --> Interval(null, 10]
2431+
// - Interval[-10, 10] --> Interval[-10, 10] (no change)
24152432
function normalizeInterval(interval) {
24162433
const ivl = interval.copy();
24172434
const minValue = (0, math_1.minValueForType)(ivl.pointType, getQuantityInstanceForMinMax(ivl));

src/datatypes/interval.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,25 @@ export class Interval {
790790
// - high open boundary that is uncertainty from min value of type or interval low value to max
791791
// value of type is changed to null open boundary
792792
//
793-
// TODO: Is this necessary? Do we care how it is represented if the representations have the same
794-
// meaning? This does affect test expectations and representation of returned results for callers.
793+
// Justification: Since interval operations now use start() and end() to calculate and construct
794+
// intervals, results involving unbounded lows and highs will return boundaries with concrete
795+
// minimum and maximum values instead of the more familiar closed null boundary representations.
796+
// Similarly, results involving unknown lows and highs will return boundaries with uncertainty
797+
// ranges rather than the more familiar open null boundary representations. In other words,
798+
// intervals that started out looking "simple", such as Interval[null, 0], can result in new
799+
// intervals with specific values that are not obvious to users, such as Interval[-2147483648, 0].
800+
//
801+
// The normalizeInterval function recognizes those situations and converts the interval back to an
802+
// equivalent form that is more likely to be familiar to all users. The results of this approach
803+
// are also more consistent with previous implementations that did not use start() and end().
804+
// Note that in all cases, the pre-normalized and normalized intervals are semantically the same
805+
// (i.e., they represent the same exact range) even if they are represented using different
806+
// individual component values (i.e., low, high, lowClosed, and highClosed values).
807+
//
808+
// Examples:
809+
// - Interval[-2147483648, 10] --> Interval[null, 10]
810+
// - Interval[Uncertainty(-2147483648, 0), 10] --> Interval(null, 10]
811+
// - Interval[-10, 10] --> Interval[-10, 10] (no change)
795812
function normalizeInterval(interval: Interval) {
796813
const ivl = interval.copy();
797814
const minValue = minValueForType(ivl.pointType, getQuantityInstanceForMinMax(ivl));

0 commit comments

Comments
 (0)