|
1 | 1 | import { Interval } from '../../src/datatypes/interval'; |
2 | | -import { DateTime } from '../../src/datatypes/datetime'; |
| 2 | +import { DateTime, Date } from '../../src/datatypes/datetime'; |
| 3 | +import { Quantity } from '../../src/datatypes/quantity'; |
3 | 4 |
|
4 | 5 | class TestDateTime { |
5 | 6 | static parse(string: string) { |
@@ -43,23 +44,33 @@ class TestInterval { |
43 | 44 | toMinute: Interval; |
44 | 45 | toSecond: Interval; |
45 | 46 | toMillisecond: Interval; |
| 47 | + withNullStart: TestInterval; |
| 48 | + withNullEnd: TestInterval; |
46 | 49 |
|
47 | | - constructor(low: any, high: any) { |
48 | | - const [thLow, thHigh] = Array.from([ |
49 | | - TestDateTime.fromDateTime(low), |
50 | | - TestDateTime.fromDateTime(high) |
51 | | - ]); |
| 50 | + constructor(low: any, high: any, createNullVariants = true) { |
52 | 51 | this.closed = new Interval(low, high, true, true); |
53 | 52 | this.open = new Interval(low, high, false, false); |
54 | 53 | this.closedOpen = new Interval(low, high, true, false); |
55 | 54 | this.openClosed = new Interval(low, high, false, true); |
56 | | - this.toYear = new Interval(thLow.toYear, thHigh.toYear); |
57 | | - this.toMonth = new Interval(thLow.toMonth, thHigh.toMonth); |
58 | | - this.toDay = new Interval(thLow.toDay, thHigh.toDay); |
59 | | - this.toHour = new Interval(thLow.toHour, thHigh.toHour); |
60 | | - this.toMinute = new Interval(thLow.toMinute, thHigh.toMinute); |
61 | | - this.toSecond = new Interval(thLow.toSecond, thHigh.toSecond); |
62 | | - this.toMillisecond = new Interval(thLow.toMillisecond, thHigh.toMillisecond); |
| 55 | + |
| 56 | + if (low != null && high != null) { |
| 57 | + const [thLow, thHigh] = Array.from([ |
| 58 | + TestDateTime.fromDateTime(low), |
| 59 | + TestDateTime.fromDateTime(high) |
| 60 | + ]); |
| 61 | + this.toYear = new Interval(thLow.toYear, thHigh.toYear); |
| 62 | + this.toMonth = new Interval(thLow.toMonth, thHigh.toMonth); |
| 63 | + this.toDay = new Interval(thLow.toDay, thHigh.toDay); |
| 64 | + this.toHour = new Interval(thLow.toHour, thHigh.toHour); |
| 65 | + this.toMinute = new Interval(thLow.toMinute, thHigh.toMinute); |
| 66 | + this.toSecond = new Interval(thLow.toSecond, thHigh.toSecond); |
| 67 | + this.toMillisecond = new Interval(thLow.toMillisecond, thHigh.toMillisecond); |
| 68 | + } |
| 69 | + |
| 70 | + if (createNullVariants) { |
| 71 | + this.withNullStart = new TestInterval(null, high, false); |
| 72 | + this.withNullEnd = new TestInterval(low, null, false); |
| 73 | + } |
63 | 74 | } |
64 | 75 | } |
65 | 76 |
|
@@ -94,6 +105,11 @@ export default () => { |
94 | 105 | data['mid2012'] = TestDateTime.parse('2012-06-01T00:00:00.0'); |
95 | 106 | data['end2012'] = TestDateTime.parse('2012-12-31T23:59:59.999'); |
96 | 107 | data['aft2012'] = TestDateTime.parse('2013-06-01T00:00:00.0'); |
| 108 | + data['all2012date'] = new TestInterval(Date.parse('2012-01-01'), Date.parse('2012-12-31')); |
| 109 | + data['alldaytime'] = new TestInterval( |
| 110 | + DateTime.parse('0001-01-01T00:00:00.0').getTime(), |
| 111 | + DateTime.parse('0001-01-01T23:59:59.999').getTime() |
| 112 | + ); |
97 | 113 | data['dIvl'] = { |
98 | 114 | sameAs: { |
99 | 115 | // |----------X----------| |
@@ -276,5 +292,7 @@ export default () => { |
276 | 292 | y: new TestInterval(0n, 100n) |
277 | 293 | } |
278 | 294 | }; |
| 295 | + data['zeroPointFiveToNinePointFive'] = new TestInterval(0.5, 9.5); |
| 296 | + data['zeroToHundredMg'] = new TestInterval(new Quantity(0, 'mg'), new Quantity(100, 'mg')); |
279 | 297 | return data; |
280 | 298 | }; |
0 commit comments