Skip to content

Commit 0ff06c5

Browse files
author
lucaijun
committed
AJ-543: duration support exchange calendar
1 parent 73ff1c8 commit 0ff06c5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/com/xxdb/data/BasicDuration.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,21 @@ public class BasicDuration extends AbstractScalar implements Comparable<BasicDur
1414

1515
public BasicDuration(DURATION unit, int value){
1616
this.value = value;
17+
if (unit == DURATION.TDAY)
18+
throw new RuntimeException("the exchange unit should be given when use exchange calendar.");
1719
this.unit = unit;
1820
this.exchange_ = unit.ordinal();
1921
}
2022

23+
public BasicDuration(DURATION unit, int value, String exchangeUnit) {
24+
this.value = value;
25+
this.unit = unit;
26+
if (this.unit == DURATION.TDAY)
27+
this.exchange_ = getCodeNumber(exchangeUnit);
28+
else
29+
this.exchange_ = this.unit.ordinal();
30+
}
31+
2132
public BasicDuration(String unit, int value) {
2233
this.value = value;
2334
int codeNumber = getCodeNumber(unit);
@@ -179,6 +190,8 @@ private int getCodeNumber(String unit) {
179190
} else if (unit.length() == 4) {
180191
int[] codes = new int[4];
181192
for (int i = 0; i < 4; i++) {
193+
if (Character.isLowerCase(unit.charAt(i)))
194+
throw new RuntimeException("the exchange unit except all upper, got " + unit);
182195
codes[i] = unit.charAt(i);
183196
}
184197
return (codes[0] << 24) + (codes[1] << 16) + (codes[2] << 8) + codes[3];

0 commit comments

Comments
 (0)