Example usage for java.time LocalDate minusYears

List of usage examples for java.time LocalDate minusYears

Introduction

In this page you can find the example usage for java.time LocalDate minusYears.

Prototype

public LocalDate minusYears(long yearsToSubtract) 

Source Link

Document

Returns a copy of this LocalDate with the specified number of years subtracted.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDate a = LocalDate.of(2014, 6, 30);
    LocalDate b = a.minusYears(6);
    System.out.println(b);//from   w ww . j  av  a2s .co m
}

From source file:org.wallride.job.UpdatePostViewsItemReader.java

@Override
protected void doReadPage() {
    if (results == null) {
        results = new CopyOnWriteArrayList<>();
    } else {/*from   www. j  av a  2 s  .  co  m*/
        results.clear();
    }

    Blog blog = blogService.getBlogById(Blog.DEFAULT_ID);
    GoogleAnalytics googleAnalytics = blog.getGoogleAnalytics();
    if (googleAnalytics == null) {
        logger.warn("Configuration of Google Analytics can not be found");
        return;
    }

    Analytics analytics = GoogleAnalyticsUtils.buildClient(googleAnalytics);

    try {
        LocalDate now = LocalDate.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        Analytics.Data.Ga.Get request = analytics.data().ga()
                .get(googleAnalytics.getProfileId(), now.minusYears(1).format(dateTimeFormatter),
                        now.format(dateTimeFormatter), "ga:pageViews")
                //                  .setDimensions(String.format("ga:dimension%d", googleAnalytics.getCustomDimensionIndex()))
                //                  .setSort(String.format("-ga:dimension%d", googleAnalytics.getCustomDimensionIndex()))
                .setDimensions(String.format("ga:pagePath", googleAnalytics.getCustomDimensionIndex()))
                .setSort(String.format("-ga:pageViews", googleAnalytics.getCustomDimensionIndex()))
                .setStartIndex(getPage() * getPageSize() + 1).setMaxResults(getPageSize());

        logger.info(request.toString());
        final GaData gaData = request.execute();
        if (CollectionUtils.isEmpty(gaData.getRows())) {
            return;
        }

        results.addAll(gaData.getRows());
    } catch (IOException e) {
        logger.warn("Failed to synchronize with Google Analytics", e);
        throw new GoogleAnalyticsException(e);
    }

    //      logger.info("Synchronization to google analytics is now COMPLETE. {} posts updated.", count);
}

From source file:jgnash.ui.report.compiled.RunningAccountBalanceChart.java

private JPanel createPanel() {
    LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate());
    LocalDate start = end.minusYears(1);

    startDateField.setDate(start);/*from   ww  w  .  j  a v  a  2  s.c om*/

    JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
    refreshButton.setIcon(IconUtils.getIcon("/jgnash/resource/view-refresh.png"));

    subAccountCheckBox = new JCheckBox(rb.getString("Button.IncludeSubAccounts"));
    subAccountCheckBox.setSelected(true);

    hideLockedAccountCheckBox = new JCheckBox(rb.getString("Button.HideLockedAccount"));
    hidePlaceholderAccountCheckBox = new JCheckBox(rb.getString("Button.HidePlaceholderAccount"));

    JFreeChart chart = createVerticalXYBarChart(combo.getSelectedAccount());
    final ChartPanel chartPanel = new ChartPanel(chart);

    FormLayout layout = new FormLayout("p, 4dlu, p:g", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);

    FormLayout dLayout = new FormLayout("p, 4dlu, p, 8dlu, p, 4dlu, p, 8dlu, p", "");
    DefaultFormBuilder dBuilder = new DefaultFormBuilder(dLayout);

    dBuilder.append(rb.getString("Label.StartDate"), startDateField);
    dBuilder.append(rb.getString("Label.EndDate"), endDateField);
    dBuilder.append(refreshButton);

    FormLayout cbLayout = new FormLayout("p, 4dlu, p, 4dlu, p, 4dlu", "");
    DefaultFormBuilder cbBuilder = new DefaultFormBuilder(cbLayout);

    cbBuilder.append(subAccountCheckBox);
    cbBuilder.append(hideLockedAccountCheckBox);
    cbBuilder.append(hidePlaceholderAccountCheckBox);

    builder.append(rb.getString("Label.Account"), combo);
    builder.nextLine();
    builder.append(" ");
    builder.append(cbBuilder.getPanel());
    builder.nextLine();
    builder.appendRelatedComponentsGapRow();
    builder.nextLine();
    builder.append(dBuilder.getPanel(), 3);
    builder.nextLine();
    builder.appendUnrelatedComponentsGapRow();
    builder.nextLine();

    builder.appendRow(RowSpec.decode("fill:p:g"));
    builder.append(chartPanel, 3);

    final JPanel panel = builder.getPanel();

    ActionListener listener = e -> {
        updateSubAccountBox();
        Account a = combo.getSelectedAccount();
        if (a == null) {
            return;
        }
        chartPanel.setChart(createVerticalXYBarChart(a));
        panel.validate();
    };

    hideLockedAccountCheckBox.addActionListener(e -> {
        combo.setHideLocked(hideLockedAccountCheckBox.isSelected());
        updateSubAccountBox();
        Account a = combo.getSelectedAccount();
        if (a == null) {
            return;
        }
        chartPanel.setChart(createVerticalXYBarChart(a));
        panel.validate();
    });

    hidePlaceholderAccountCheckBox.addActionListener(e -> {
        combo.setHidePlaceholder(hidePlaceholderAccountCheckBox.isSelected());
        updateSubAccountBox();
        Account a = combo.getSelectedAccount();
        if (a == null) {
            return;
        }
        chartPanel.setChart(createVerticalXYBarChart(a));
        panel.validate();
    });

    updateSubAccountBox();

    combo.addActionListener(listener);
    refreshButton.addActionListener(listener);

    return panel;
}

From source file:jgnash.ui.report.compiled.MonthlyAccountBalanceChart.java

private JPanel createPanel() {
    LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate());
    LocalDate start = end.minusYears(1);
    startDateField.setDate(start);//from w  w  w.  ja  va  2s .com

    JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
    refreshButton.setIcon(IconUtils.getIcon("/jgnash/resource/view-refresh.png"));

    subAccountCheckBox = new JCheckBox(rb.getString("Button.IncludeSubAccounts"));
    subAccountCheckBox.setSelected(true);

    hideLockedAccountCheckBox = new JCheckBox(rb.getString("Button.HideLockedAccount"));
    hidePlaceholderAccountCheckBox = new JCheckBox(rb.getString("Button.HidePlaceholderAccount"));

    Account a = combo.getSelectedAccount();
    JFreeChart chart = createVerticalXYBarChart(a);
    final ChartPanel chartPanel = new ChartPanel(chart);

    FormLayout layout = new FormLayout("p, 4dlu, p:g", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);

    FormLayout dLayout = new FormLayout("p, 4dlu, p, 8dlu, p, 4dlu, p, 8dlu, p", "");
    DefaultFormBuilder dBuilder = new DefaultFormBuilder(dLayout);

    dBuilder.append(rb.getString("Label.StartDate"), startDateField);
    dBuilder.append(rb.getString("Label.EndDate"), endDateField);
    dBuilder.append(refreshButton);

    FormLayout cbLayout = new FormLayout("p, 4dlu, p, 4dlu, p, 4dlu", "");
    DefaultFormBuilder cbBuilder = new DefaultFormBuilder(cbLayout);

    cbBuilder.append(subAccountCheckBox);
    cbBuilder.append(hideLockedAccountCheckBox);
    cbBuilder.append(hidePlaceholderAccountCheckBox);

    builder.append(rb.getString("Label.Account"), combo);
    builder.nextLine();
    builder.append(" ");
    builder.append(cbBuilder.getPanel());
    builder.nextLine();
    builder.appendRelatedComponentsGapRow();
    builder.nextLine();
    builder.append(dBuilder.getPanel(), 3);
    builder.nextLine();
    builder.appendUnrelatedComponentsGapRow();
    builder.nextLine();

    builder.appendRow(RowSpec.decode("fill:p:g"));
    builder.append(chartPanel, 3);

    final JPanel panel = builder.getPanel();

    ActionListener listener = e -> {
        try {
            Account account = combo.getSelectedAccount();
            if (account == null) {
                return;
            }

            updateSubAccountBox();

            chartPanel.setChart(createVerticalXYBarChart(account));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChart.class.getName()).log(Level.SEVERE,
                    ex.getLocalizedMessage(), ex);
        }
    };

    combo.addActionListener(listener);

    hideLockedAccountCheckBox.addActionListener(e -> {
        combo.setHideLocked(hideLockedAccountCheckBox.isSelected());
        try {
            Account account = combo.getSelectedAccount();
            if (account == null) {
                return;
            }

            updateSubAccountBox();

            chartPanel.setChart(createVerticalXYBarChart(account));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChart.class.getName()).log(Level.SEVERE,
                    ex.getLocalizedMessage(), ex);
        }
    });

    hidePlaceholderAccountCheckBox.addActionListener(e -> {
        combo.setHidePlaceholder(hidePlaceholderAccountCheckBox.isSelected());
        try {
            Account account = combo.getSelectedAccount();
            if (account == null) {
                return;
            }

            updateSubAccountBox();

            chartPanel.setChart(createVerticalXYBarChart(account));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChart.class.getName()).log(Level.SEVERE,
                    ex.getLocalizedMessage(), ex);
        }
    });
    refreshButton.addActionListener(listener);

    updateSubAccountBox();

    return panel;
}

From source file:jgnash.ui.report.compiled.MonthlyAccountBalanceChartCompare.java

private JPanel createPanel() {
    LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate());
    LocalDate start = end.minusYears(1);

    startDateField.setDate(start);//from   www.j av a 2  s. c om

    JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
    refreshButton.setIcon(IconUtils.getIcon("/jgnash/resource/view-refresh.png"));

    subAccountCheckBox = new JCheckBox(rb.getString("Button.IncludeSubAccounts"));
    subAccountCheckBox.setSelected(true);

    hideLockedAccountCheckBox = new JCheckBox(rb.getString("Button.HideLockedAccount"));
    hidePlaceholderAccountCheckBox = new JCheckBox(rb.getString("Button.HidePlaceholderAccount"));

    jcb_compare = new JCheckBox(rb.getString("Button.Compare"));
    jcb_compare.setSelected(true);

    Account a = combo1.getSelectedAccount();
    Account a2 = combo2.getSelectedAccount();

    JFreeChart chart = createVerticalXYBarChart(a, a2);
    final ChartPanel chartPanel = new ChartPanel(chart);

    FormLayout layout = new FormLayout("p, 4dlu, p:g", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);

    FormLayout dLayout = new FormLayout("p, 4dlu, p, 8dlu, p, 4dlu, p, 8dlu, p", "");
    DefaultFormBuilder dBuilder = new DefaultFormBuilder(dLayout);

    dBuilder.append(rb.getString("Label.StartDate"), startDateField);
    dBuilder.append(rb.getString("Label.EndDate"), endDateField);
    dBuilder.append(refreshButton);

    FormLayout cbLayout = new FormLayout("p, 4dlu, p, 4dlu, p, 4dlu", "");
    DefaultFormBuilder cbBuilder = new DefaultFormBuilder(cbLayout);

    cbBuilder.append(subAccountCheckBox);
    cbBuilder.append(hideLockedAccountCheckBox);
    cbBuilder.append(hidePlaceholderAccountCheckBox);

    builder.append(rb.getString("Label.Account"), combo1);
    builder.nextLine();
    builder.append(rb.getString("Label.Compare"), combo2);
    builder.nextLine();
    builder.append(jcb_compare);
    builder.append(cbBuilder.getPanel());
    builder.nextLine();
    builder.appendRelatedComponentsGapRow();
    builder.nextLine();
    builder.append(dBuilder.getPanel(), 3);
    builder.nextLine();
    builder.appendUnrelatedComponentsGapRow();
    builder.nextLine();

    builder.appendRow(RowSpec.decode("fill:p:g"));
    builder.append(chartPanel, 3);

    final JPanel panel = builder.getPanel();

    ActionListener listener = e -> {
        try {
            if (e.getSource() == jcb_compare) {
                combo2.setEnabled(jcb_compare.isSelected());
            }

            Account account = combo1.getSelectedAccount();
            if (account == null) {
                return;
            }

            Account account2 = combo2.getSelectedAccount();
            if (jcb_compare.isSelected() && account2 == null) {
                return;
            }

            updateSubAccountBox();

            chartPanel.setChart(createVerticalXYBarChart(account, account2));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChartCompare.class.getName()).log(Level.SEVERE,
                    ex.getLocalizedMessage(), ex);
        }
    };

    combo1.addActionListener(listener);
    combo2.addActionListener(listener);
    jcb_compare.addActionListener(listener);
    subAccountCheckBox.addActionListener(listener);

    hideLockedAccountCheckBox.addActionListener(e -> {
        combo1.setHideLocked(hideLockedAccountCheckBox.isSelected());
        combo2.setHideLocked(hideLockedAccountCheckBox.isSelected());
        try {
            Account account = combo1.getSelectedAccount();
            if (account == null) {
                return;
            }

            Account account2 = combo2.getSelectedAccount();
            if (jcb_compare.isSelected() && account2 == null) {
                return;
            }

            updateSubAccountBox();

            chartPanel.setChart(createVerticalXYBarChart(account, account2));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChartCompare.class.getName()).log(Level.SEVERE,
                    ex.getLocalizedMessage(), ex);
        }
    });

    hidePlaceholderAccountCheckBox.addActionListener(e -> {
        combo1.setHidePlaceholder(hidePlaceholderAccountCheckBox.isSelected());
        combo2.setHidePlaceholder(hidePlaceholderAccountCheckBox.isSelected());
        try {
            Account account = combo1.getSelectedAccount();
            if (account == null) {
                return;
            }
            Account account2 = combo2.getSelectedAccount();
            if (jcb_compare.isSelected() && account2 == null) {
                return;
            }

            updateSubAccountBox();

            chartPanel.setChart(createVerticalXYBarChart(account, account2));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChartCompare.class.getName()).log(Level.SEVERE,
                    ex.getLocalizedMessage(), ex);
        }
    });
    refreshButton.addActionListener(listener);

    updateSubAccountBox();

    return panel;
}

From source file:com.romeikat.datamessie.core.base.ui.page.StatisticsPage.java

private LocalDate getFromDate() {
    final LocalDate toDate = getToDate();
    if (toDate == null) {
        return LocalDate.now();
    }/*from  w ww  . jav a  2  s.  com*/

    Integer statisticsPeriod = DataMessieSession.get().getStatisticsPeriodModel().getObject();
    if (statisticsPeriod == null) {
        return LocalDate.now();
    }

    final StatisticsInterval statisticsInterval = DataMessieSession.get().getStatisticsIntervalModel()
            .getObject();
    if (statisticsInterval == null) {
        return LocalDate.now();
    }

    // Minimum value is 1
    statisticsPeriod = Math.max(statisticsPeriod, 1);

    // Calculate
    final LocalDate fromDate = toDate.plusDays(1);
    switch (statisticsInterval) {
    case DAY:
        return fromDate.minusDays(statisticsPeriod);
    case WEEK:
        return fromDate.minusWeeks(statisticsPeriod);
    case MONTH:
        return fromDate.minusMonths(statisticsPeriod);
    case YEAR:
        return fromDate.minusYears(statisticsPeriod);
    default:
        return LocalDate.now();
    }
}