List of usage examples for java.time LocalDate with
@Override
public LocalDate with(TemporalAdjuster adjuster)
From source file:Main.java
/** * The adjustInto method accepts a Temporal instance * and returns an adjusted LocalDate. If the passed in * parameter is not a LocalDate, then a DateTimeException is thrown. *///w w w. j a va2 s .c om public Temporal adjustInto(Temporal input) { LocalDate date = LocalDate.from(input); int day; if (date.getDayOfMonth() < 15) { day = 15; } else { day = date.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth(); } date = date.withDayOfMonth(day); if (date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY) { date = date.with(TemporalAdjusters.previous(DayOfWeek.FRIDAY)); } return input.with(date); }
From source file:jgnash.ui.report.compiled.MonthlyAccountBalanceChart.java
private TimeSeriesCollection createTimeSeriesCollection(final Account account) { List<LocalDate> dates = Collections.emptyList(); if (subAccountCheckBox.isSelected()) { // Getting the dates to calculate final LocalDate start = startDateField.getLocalDate().with(TemporalAdjusters.firstDayOfMonth()); final LocalDate stop = endDateField.getLocalDate().with(TemporalAdjusters.lastDayOfMonth()); dates = DateUtils.getLastDayOfTheMonths(start, stop); TimeSeries t = new TimeSeries(rb.getString("Column.Month"), rb.getString("Column.Month"), rb.getString("Column.Balance")); // For every month, calculate the total amount for (LocalDate date : dates) { final LocalDate d = date.with(TemporalAdjusters.lastDayOfMonth()); final LocalDate s = date.with(TemporalAdjusters.firstDayOfMonth()); // Get the total amount for the account and every sub accounts for the specified date // and include it in the chart t.add(new Month(DateUtils.asDate(date)), calculateTotal(s, d, account, account.getCurrencyNode())); }//from w w w . j av a2 s.c om return new TimeSeriesCollection(t); } int count = account.getTransactionCount(); if (count > 0) { LocalDate start = account.getTransactionAt(0).getLocalDate(); LocalDate stop = account.getTransactionAt(count - 1).getLocalDate(); dates = DateUtils.getLastDayOfTheMonths(start, stop); } TimeSeries t = new TimeSeries(rb.getString("Column.Month"), rb.getString("Column.Month"), rb.getString("Column.Balance")); AccountType type = account.getAccountType(); for (LocalDate localDate : dates) { // get balance for the whole month LocalDate d = localDate.with(TemporalAdjusters.lastDayOfMonth()); LocalDate s = localDate.with(TemporalAdjusters.firstDayOfMonth()); BigDecimal balance = AccountBalanceDisplayManager.convertToSelectedBalanceMode(type, account.getBalance(s, d)); t.add(new Month(DateUtils.asDate(localDate)), balance); } return new TimeSeriesCollection(t); }
From source file:jgnash.ui.report.compiled.MonthlyAccountBalanceChartCompare.java
private TimeSeriesCollection createTimeSeriesCollection(final Account account, final Account a2) { //always use this method //if (subAccountCheckBox.isApproved()) { // Getting the dates to calculate LocalDate start = startDateField.getLocalDate().with(TemporalAdjusters.firstDayOfMonth()); LocalDate stop = endDateField.getLocalDate().with(TemporalAdjusters.lastDayOfMonth()); List<LocalDate> list = DateUtils.getLastDayOfTheMonths(start, stop); TimeSeries t = new TimeSeries(rb.getString("Column.Month"), rb.getString("Column.Month"), rb.getString("Column.Balance")); TimeSeries t2 = new TimeSeries(rb.getString("Column.Month"), rb.getString("Column.Month"), rb.getString("Column.Balance")); // For every month, calculate the total amount for (final LocalDate localDate : list) { final LocalDate d = localDate.with(TemporalAdjusters.lastDayOfMonth()); final LocalDate s = localDate.with(TemporalAdjusters.firstDayOfMonth()); // Get the total amount for the account and every sub accounts // for the specified date //BigDecimal bd_TotalAmount = calculateTotal(s, d, account, account.getCurrencyNode()); BigDecimal bd_TotalAmount = calculateTotal(s, d, account, subAccountCheckBox.isSelected(), account.getCurrencyNode()); // Include it in the graph t.add(new Month(DateUtils.asDate(localDate)), totalModulus(bd_TotalAmount, account.getAccountType())); if (jcb_compare.isSelected()) { bd_TotalAmount = calculateTotal(s, d, a2, subAccountCheckBox.isSelected(), account.getCurrencyNode()); t2.add(new Month(DateUtils.asDate(localDate)), totalModulus(bd_TotalAmount, a2.getAccountType())); }/* ww w . j ava 2 s . c o m*/ } TimeSeriesCollection tsc = new TimeSeriesCollection(); tsc.addSeries(t); if (jcb_compare.isSelected()) { tsc.addSeries(t2); } return tsc; /* return new TimeSeriesCollection(t); } int count = account.getTransactionCount(); if (count > 0) { Date start = account.getTransactionAt(0).getDate(); Date stop = account.getTransactionAt(count - 1).getDate(); list = DateUtils.getLastDayOfTheMonths(start, stop); } TimeSeries t = new TimeSeries(rb.getString("Column.Month"), rb.getString("Column.Month"), rb.getString("Column.Balance")); AccountType type = account.getAccountType(); for (Date aList : list) { // get balance for the whole month Date d = DateUtils.getLastDayOfTheMonth(aList); Date s = DateUtils.getFirstDayOfTheMonth(aList); BigDecimal balance = AccountBalanceDisplayManager.convertToSelectedBalanceMode(type, account.getBalance(s, d)); t.add(new Month(aList), balance); } return new TimeSeriesCollection(t); */ }