List of usage examples for org.joda.time MutableDateTime add
public void add(DurationFieldType type, int amount)
From source file:com.graphaware.module.timetree.domain.TimeInstant.java
License:Open Source License
/** * Create an instant immediately following the current one, i.e. with its resolution unit incremented by 1. * * @return next instant.//from w ww.ja v a 2 s .com */ public TimeInstant next() { MutableDateTime time = new MutableDateTime(getTime()); time.add(getResolution().getDateTimeFieldType().getDurationType(), 1); return new TimeInstant(time.getMillis(), getTimezone(), getResolution()); }
From source file:org.chaston.oakfunds.model.ModelManagerImpl.java
License:Apache License
private void recalculateDistributionTransactions(Model model, Account account, ModelAccountTransaction modelAccountTransaction) throws StorageException { int distributionMonths = modelAccountTransaction.getDistributionTimeUnit() == DistributionTimeUnit.MONTHS ? modelAccountTransaction.getDistributionTime() : modelAccountTransaction.getDistributionTime() * 12; Instant end = modelAccountTransaction.getInstant(); MutableDateTime mutableDateTime = modelAccountTransaction.getInstant().toMutableDateTime(); mutableDateTime.add(DurationFieldType.months(), 1 - distributionMonths); Instant firstDistributionInstant = DateUtil.endOfYear(systemPropertiesManager.getCurrentYear() - 1); BigDecimal amountPerDistribution = modelAccountTransaction.getAmount() .divide(BigDecimal.valueOf(distributionMonths), 5, RoundingMode.HALF_UP); BigDecimal firstDistributionAmount = BigDecimal.ZERO; // Delete previous distributions. store.deleteInstantRecords(account, ModelDistributionTransaction.TYPE, ImmutableList/*from w w w.ja v a 2 s . c om*/ .of(AttributeSearchTerm.of(ModelDistributionTransaction.ATTRIBUTE_ACCOUNT_TRANSACTION_ID, SearchOperator.EQUALS, modelAccountTransaction.getId()))); while (mutableDateTime.isBefore(end)) { if (mutableDateTime.isBefore(firstDistributionInstant)) { firstDistributionAmount = firstDistributionAmount.add(amountPerDistribution); } else { Map<String, Object> distributionAttributes = new HashMap<>(); distributionAttributes.put(ModelBound.ATTRIBUTE_MODEL_ID, model.getId()); distributionAttributes.put(ModelDistributionTransaction.ATTRIBUTE_ACCOUNT_TRANSACTION_ID, modelAccountTransaction.getId()); distributionAttributes.put(ModelDistributionTransaction.ATTRIBUTE_AMOUNT, amountPerDistribution); store.insertInstantRecord(account, ModelDistributionTransaction.TYPE, mutableDateTime.toInstant(), distributionAttributes); } mutableDateTime.add(DurationFieldType.months(), 1); } // Add the first distribution amount. if (!firstDistributionAmount.equals(BigDecimal.ZERO)) { Map<String, Object> firstDistributionAttributes = new HashMap<>(); firstDistributionAttributes.put(ModelBound.ATTRIBUTE_MODEL_ID, model.getId()); firstDistributionAttributes.put(ModelDistributionTransaction.ATTRIBUTE_ACCOUNT_TRANSACTION_ID, modelAccountTransaction.getId()); firstDistributionAttributes.put(ModelDistributionTransaction.ATTRIBUTE_AMOUNT, firstDistributionAmount); store.insertInstantRecord(account, ModelDistributionTransaction.TYPE, firstDistributionInstant, firstDistributionAttributes); } // Add the anti-distribution that cancels out the others when the transaction is executed. Map<String, Object> antiDistributionAttributes = new HashMap<>(); antiDistributionAttributes.put(ModelBound.ATTRIBUTE_MODEL_ID, model.getId()); antiDistributionAttributes.put(ModelDistributionTransaction.ATTRIBUTE_ACCOUNT_TRANSACTION_ID, modelAccountTransaction.getId()); antiDistributionAttributes.put(ModelDistributionTransaction.ATTRIBUTE_AMOUNT, amountPerDistribution.negate().multiply(BigDecimal.valueOf(distributionMonths - 1))); store.insertInstantRecord(account, ModelDistributionTransaction.TYPE, mutableDateTime.toInstant(), antiDistributionAttributes); }
From source file:org.chaston.oakfunds.model.ModelManagerImpl.java
License:Apache License
private Iterable<Instant> getAllInstantsInRange(Instant start, Instant end) { MutableDateTime mutableDateTime = new MutableDateTime(systemPropertiesManager.getCurrentYear(), 1, 1, 0, 0, 0, 0);/*from ww w. j av a2 s.c o m*/ long maxYear = systemPropertiesManager.getCurrentYear() + systemPropertiesManager.getTimeHorizon(); if (mutableDateTime.isBefore(start)) { mutableDateTime = start.toMutableDateTime(); } ImmutableList.Builder<Instant> instants = ImmutableList.builder(); while (mutableDateTime.isBefore(end) && mutableDateTime.get(DateTimeFieldType.year()) <= maxYear) { instants.add(mutableDateTime.toInstant()); mutableDateTime.add(DurationFieldType.months(), 1); } return instants.build(); }
From source file:org.chaston.oakfunds.util.DateUtil.java
License:Apache License
public static Instant endOfYear(int year) { MutableDateTime mutableDateTime = new MutableDateTime(year, 1, 1, 0, 0, 0, 0); mutableDateTime.add(DurationFieldType.years(), 1); mutableDateTime.add(DurationFieldType.millis(), -1); return mutableDateTime.toInstant(); }
From source file:org.chaston.oakfunds.util.DateUtil.java
License:Apache License
public static Instant endOfMonth(int year, int monthOfYear) { MutableDateTime mutableDateTime = new MutableDateTime(year, monthOfYear, 1, 0, 0, 0, 0); mutableDateTime.add(DurationFieldType.months(), 1); mutableDateTime.add(DurationFieldType.millis(), -1); return mutableDateTime.toInstant(); }
From source file:org.chaston.oakfunds.util.DateUtil.java
License:Apache License
public static Instant endOfDay(int year, int monthOfYear, int dayOfMonth) { MutableDateTime mutableDateTime = new MutableDateTime(year, monthOfYear, dayOfMonth, 0, 0, 0, 0); mutableDateTime.add(DurationFieldType.days(), 1); mutableDateTime.add(DurationFieldType.millis(), -1); return mutableDateTime.toInstant(); }