本文整理汇总了Java中nl.strohalm.cyclos.utils.Period.between方法的典型用法代码示例。如果您正苦于以下问题:Java Period.between方法的具体用法?Java Period.between怎么用?Java Period.between使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nl.strohalm.cyclos.utils.Period
的用法示例。
在下文中一共展示了Period.between方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStatusAt
import nl.strohalm.cyclos.utils.Period; //导入方法依赖的package包/类
private AccountStatus getStatusAt(final Account account, final Calendar date, final boolean onlyIfThereAreDiffs) {
// Fill the status with basic data
AccountStatus status = new AccountStatus();
status.setAccount(account);
status.setCreditLimit(account.getCreditLimit());
status.setUpperCreditLimit(account.getUpperCreditLimit());
status.setDate(date);
// Get the last closed balance
ClosedAccountBalance closedBalance = closedAccountBalanceDao.get(account, date);
Calendar closedDate = closedBalance == null ? null : closedBalance.getDate();
Calendar endDate = (Calendar) (date == null ? null : date.clone());
if (endDate != null) {
endDate.add(Calendar.SECOND, -1);
}
Period period = Period.between(closedDate, endDate);
// Get the balance diff
BigDecimal balanceDiff = transferDao.balanceDiff(account, period);
status.setBalance(closedBalance == null ? balanceDiff : closedBalance.getBalance().add(balanceDiff));
// Get the reserved amount diff
BigDecimal reservationDiff = amountReservationDao.reservationDiff(account, period);
status.setReservedAmount(closedBalance == null ? reservationDiff : closedBalance.getReserved().add(reservationDiff));
if (onlyIfThereAreDiffs && balanceDiff.equals(BigDecimal.ZERO) && reservationDiff.equals(BigDecimal.ZERO)) {
// If should return only if there are diffs, and there were none, return null
return null;
}
return status;
}
示例2: calculateChargeOverTransactionedVolume
import nl.strohalm.cyclos.utils.Period; //导入方法依赖的package包/类
private BigDecimal calculateChargeOverTransactionedVolume(final AccountFeeLog feeLog, final Member member) {
AccountFee fee = feeLog.getAccountFee();
if (!fee.isEnabled()) {
return BigDecimal.ZERO;
}
MemberAccount account = (MemberAccount) accountService.getAccount(new AccountDTO(member, fee.getAccountType()));
// We want to limit for diffs within the fee log period
Period logPeriod = feeLog.getPeriod();
Calendar beginDate = logPeriod.getBegin();
if (fee.getEnabledSince().after(beginDate)) {
// However, if the fee was enabled in the middle of the period, consider this date instead
beginDate = fee.getEnabledSince();
}
if (account.getCreationDate().after(beginDate)) {
// If the account was created after, use it's creation date
beginDate = account.getCreationDate();
}
// As we calculate by whole days, make sure we're on the next day, so the balance will be ok
beginDate = DateHelper.truncateNextDay(beginDate);
Period period = Period.between(beginDate, logPeriod.getEnd());
if (period.getBegin().after(period.getEnd())) {
// In case of single days, the begin is the next day, and the end is the last second of the current day
period.setEnd(period.getBegin());
}
return calculateVolumeCharge(account, fee, period, BigDecimal.ZERO, false);
}
示例3: getEnabledPeriod
import nl.strohalm.cyclos.utils.Period; //导入方法依赖的package包/类
public Period getEnabledPeriod() {
final Period period = Period.between(enabledSince, disabledSince);
period.setUseTime(true);
return period;
}
示例4: calculateReservedAmountForVolumeFee
import nl.strohalm.cyclos.utils.Period; //导入方法依赖的package包/类
@Override
public BigDecimal calculateReservedAmountForVolumeFee(final MemberAccount account) {
MemberGroup group = (MemberGroup) fetchService.fetch(account.getMember().getGroup());
AccountFee volumeFee = getVolumeFee(account.getType(), group);
if (volumeFee == null) {
return BigDecimal.ZERO;
}
// Get the last period which was charged for this account
AccountFeeLog lastCharged = memberAccountFeeLogDao.getLastChargedLog(account.getMember(), volumeFee);
Calendar fromDate;
if (lastCharged == null || lastCharged.getDate().before(volumeFee.getEnabledSince())) {
// Never charged, or fee re-enabled after the last charge: consider either the account creation date or the fee enabled since -
// whatever happened later
fromDate = account.getCreationDate().after(volumeFee.getEnabledSince()) ? account.getCreationDate() : volumeFee.getEnabledSince();
} else {
// Already charged - consider the first day on the next period
fromDate = lastCharged.getPeriod().getEnd();
}
// As we calculate by whole days, make sure we're on the next day, so the balance will be ok
fromDate = DateHelper.truncateNextDay(fromDate);
// As the volume is an average of days, if there are previous uncharged periods, we must compute each period separately.
// For example, if the last charge was 2 months ago (a charge failed), we cannot assume that a single charge over 2 months is the
// same as 2 charges of 1 month, as we charge over the average. So, in the example, if an account has 100 over all time, and we charge 1%,
// the average for 1 month is 100, so we charge 1. The next month, is the same, and we charge another 1. If the period would be 2 months,
// The average over those 2 months is still 100, so a single charge of 1 is done, unlike the previous 2 charges.
// In most normal cases, the loop should be executed only once. Only when an account fee log has failed, it should be executed more than once.
TimePeriod recurrence = volumeFee.getRecurrence();
BigDecimal result = BigDecimal.ZERO;
Calendar now = Calendar.getInstance();
boolean done = false;
if (LOG.isDebugEnabled()) {
LOG.debug("Getting current status for " + account);
}
while (!done) {
Period period = recurrence.currentPeriod(fromDate);
if (!period.getEnd().after(now)) {
// Still a past uncharged period
period.setBegin(fromDate);
fromDate = DateHelper.truncateNextDay(period.getEnd());
} else {
period = Period.between(fromDate, DateHelper.truncate(now));
done = true;
}
BigDecimal chargeForPeriod = calculateVolumeCharge(account, volumeFee, period, result, done);
if (LOG.isDebugEnabled()) {
LOG.debug("Charge for period " + FormatObject.formatObject(period.getBegin()) + "\t" + FormatObject.formatObject(period.getEnd()) + "\t" + chargeForPeriod);
}
result = result.add(chargeForPeriod);
}
return result;
}