File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ];
You can’t perform that action at this time.
0 commit comments