判断债券持有期间是否包含了2月29日

2018-05-17  本文已影响0人  留意依夏

public boolean isContainIntercalaryFeb(String bondExchProductId, Date trdD, Date firstDeliveryDate) throws ParseException {

boolean flag = false;

Calendar cTrdD = Calendar.getInstance();

Calendar cFDD = Calendar.getInstance();

cTrdD.setTime(trdD);

cFDD.setTime(firstDeliveryDate);

int begYear = cTrdD.get(Calendar.YEAR);

int endYear = cFDD.get(Calendar.YEAR);

String intercalaryFeb = begYear + "0229";

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

Date intFeb = sdf.parse(intercalaryFeb);

if (begYear == endYear && (begYear % 4==0 && begYear % 100 != 0 || begYear % 400 == 0)) { // 持有区间为跨年 且 在闰年

// 2月29在区间内;交易所交易日为2月29;银行间最后结算日为2月29

if (diff(trdD, intFeb) * diff(intFeb, firstDeliveryDate) < 0

|| (diff(trdD, intFeb) == 0 && !isInterBank(bondExchProductId))

|| (diff(intFeb, firstDeliveryDate) ==0 && isInterBank(bondExchProductId))) {

flag = true;

}

} else if (begYear != endYear && diff(intFeb, firstDeliveryDate) > 0

|| (diff(intFeb, firstDeliveryDate) ==0 && isInterBank(bondExchProductId))) {

flag = true;

}

return flag;

}

上一篇下一篇

猜你喜欢

热点阅读