Example usage for org.joda.time LocalDateTime plusMonths

List of usage examples for org.joda.time LocalDateTime plusMonths

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime plusMonths.

Prototype

public LocalDateTime plusMonths(int months) 

Source Link

Document

Returns a copy of this datetime plus the specified number of months.

Usage

From source file:org.gnucash.android.ui.chart.LineChartActivity.java

License:Apache License

/**
 * Returns entries which represent a user data of the specified account type
 * @param accountType account's type which user data will be processed
 * @return entries which represent a user data
 *//*from   w w w. j av  a2s.  c  o  m*/
private List<Entry> getEntryList(AccountType accountType) {
    List<String> accountUIDList = new ArrayList<>();
    for (Account account : mAccountsDbAdapter.getSimpleAccountList()) {
        if (account.getAccountType() == accountType && !account.isPlaceholderAccount()
                && account.getCurrency() == mCurrency) {
            accountUIDList.add(account.getUID());
        }
    }

    LocalDateTime earliest = new LocalDateTime(mEarliestTimestampsMap.get(accountType));
    LocalDateTime latest = new LocalDateTime(mLatestTimestampsMap.get(accountType));
    Log.d(TAG, "Earliest " + accountType + " date " + earliest.toString("dd MM yyyy"));
    Log.d(TAG, "Latest " + accountType + " date " + latest.toString("dd MM yyyy"));
    int months = Months.monthsBetween(earliest.withDayOfMonth(1).withMillisOfDay(0),
            latest.withDayOfMonth(1).withMillisOfDay(0)).getMonths();

    int offset = getXAxisOffset(accountType);
    List<Entry> values = new ArrayList<>(months + 1);
    for (int i = 0; i < months + 1; i++) {
        long start = earliest.dayOfMonth().withMinimumValue().millisOfDay().withMinimumValue().toDate()
                .getTime();
        long end = earliest.dayOfMonth().withMaximumValue().millisOfDay().withMaximumValue().toDate().getTime();
        float balance = (float) mAccountsDbAdapter.getAccountsBalance(accountUIDList, start, end).asDouble();
        values.add(new Entry(balance, i + offset));
        Log.d(TAG, accountType + earliest.toString(" MMM yyyy") + ", balance = " + balance);
        earliest = earliest.plusMonths(1);
    }

    return values;
}

From source file:org.gnucash.android.ui.report.barchart.StackedBarChartFragment.java

License:Apache License

/**
 * Returns a data object that represents a user data of the specified account types
 * @return a {@code BarData} instance that represents a user data
 *//*from   w  w w. j  a v a2 s. co  m*/
protected BarData getData() {
    List<BarEntry> values = new ArrayList<>();
    List<String> labels = new ArrayList<>();
    List<Integer> colors = new ArrayList<>();
    Map<String, Integer> accountToColorMap = new LinkedHashMap<>();
    List<String> xValues = new ArrayList<>();
    LocalDateTime tmpDate = new LocalDateTime(getStartDate(mAccountType).toDate().getTime());
    int count = getDateDiff(new LocalDateTime(getStartDate(mAccountType).toDate().getTime()),
            new LocalDateTime(getEndDate(mAccountType).toDate().getTime()));
    for (int i = 0; i <= count; i++) {
        long start = 0;
        long end = 0;
        switch (mGroupInterval) {
        case MONTH:
            start = tmpDate.dayOfMonth().withMinimumValue().millisOfDay().withMinimumValue().toDate().getTime();
            end = tmpDate.dayOfMonth().withMaximumValue().millisOfDay().withMaximumValue().toDate().getTime();

            xValues.add(tmpDate.toString(X_AXIS_MONTH_PATTERN));
            tmpDate = tmpDate.plusMonths(1);
            break;
        case QUARTER:
            int quarter = getQuarter(tmpDate);
            start = tmpDate.withMonthOfYear(quarter * 3 - 2).dayOfMonth().withMinimumValue().millisOfDay()
                    .withMinimumValue().toDate().getTime();
            end = tmpDate.withMonthOfYear(quarter * 3).dayOfMonth().withMaximumValue().millisOfDay()
                    .withMaximumValue().toDate().getTime();

            xValues.add(String.format(X_AXIS_QUARTER_PATTERN, quarter, tmpDate.toString(" YY")));
            tmpDate = tmpDate.plusMonths(3);
            break;
        case YEAR:
            start = tmpDate.dayOfYear().withMinimumValue().millisOfDay().withMinimumValue().toDate().getTime();
            end = tmpDate.dayOfYear().withMaximumValue().millisOfDay().withMaximumValue().toDate().getTime();

            xValues.add(tmpDate.toString(X_AXIS_YEAR_PATTERN));
            tmpDate = tmpDate.plusYears(1);
            break;
        }
        List<Float> stack = new ArrayList<>();
        for (Account account : mAccountsDbAdapter.getSimpleAccountList()) {
            if (account.getAccountType() == mAccountType && !account.isPlaceholderAccount()
                    && account.getCommodity().equals(mCommodity)) {

                double balance = mAccountsDbAdapter
                        .getAccountsBalance(Collections.singletonList(account.getUID()), start, end).asDouble();
                if (balance != 0) {
                    stack.add((float) balance);

                    String accountName = account.getName();
                    while (labels.contains(accountName)) {
                        if (!accountToColorMap.containsKey(account.getUID())) {
                            for (String label : labels) {
                                if (label.equals(accountName)) {
                                    accountName += " ";
                                }
                            }
                        } else {
                            break;
                        }
                    }
                    labels.add(accountName);

                    if (!accountToColorMap.containsKey(account.getUID())) {
                        Integer color;
                        if (mUseAccountColor) {
                            color = (account.getColor() != Account.DEFAULT_COLOR) ? account.getColor()
                                    : COLORS[accountToColorMap.size() % COLORS.length];
                        } else {
                            color = COLORS[accountToColorMap.size() % COLORS.length];
                        }
                        accountToColorMap.put(account.getUID(), color);
                    }
                    colors.add(accountToColorMap.get(account.getUID()));

                    Log.d(TAG, mAccountType + tmpDate.toString(" MMMM yyyy ") + account.getName() + " = "
                            + stack.get(stack.size() - 1));
                }
            }
        }

        String stackLabels = labels.subList(labels.size() - stack.size(), labels.size()).toString();
        values.add(new BarEntry(floatListToArray(stack), i, stackLabels));
    }

    BarDataSet set = new BarDataSet(values, "");
    set.setDrawValues(false);
    set.setStackLabels(labels.toArray(new String[labels.size()]));
    set.setColors(colors);

    if (set.getYValueSum() == 0) {
        mChartDataPresent = false;
        return getEmptyData();
    }
    mChartDataPresent = true;
    return new BarData(xValues, set);
}

From source file:org.gnucash.android.ui.report.BarChartFragment.java

License:Apache License

/**
 * Returns a data object that represents a user data of the specified account types
 * @return a {@code BarData} instance that represents a user data
 *//*from ww w .jav a  2s  . c  o m*/
private BarData getData() {
    List<BarEntry> values = new ArrayList<>();
    List<String> labels = new ArrayList<>();
    List<Integer> colors = new ArrayList<>();
    Map<String, Integer> accountToColorMap = new LinkedHashMap<>();
    List<String> xValues = new ArrayList<>();
    LocalDateTime tmpDate = new LocalDateTime(getStartDate(mAccountType).toDate().getTime());
    int count = getDateDiff(new LocalDateTime(getStartDate(mAccountType).toDate().getTime()),
            new LocalDateTime(getEndDate(mAccountType).toDate().getTime()));
    for (int i = 0; i <= count; i++) {
        long start = 0;
        long end = 0;
        switch (mGroupInterval) {
        case MONTH:
            start = tmpDate.dayOfMonth().withMinimumValue().millisOfDay().withMinimumValue().toDate().getTime();
            end = tmpDate.dayOfMonth().withMaximumValue().millisOfDay().withMaximumValue().toDate().getTime();

            xValues.add(tmpDate.toString(X_AXIS_MONTH_PATTERN));
            tmpDate = tmpDate.plusMonths(1);
            break;
        case QUARTER:
            int quarter = getQuarter(tmpDate);
            start = tmpDate.withMonthOfYear(quarter * 3 - 2).dayOfMonth().withMinimumValue().millisOfDay()
                    .withMinimumValue().toDate().getTime();
            end = tmpDate.withMonthOfYear(quarter * 3).dayOfMonth().withMaximumValue().millisOfDay()
                    .withMaximumValue().toDate().getTime();

            xValues.add(String.format(X_AXIS_QUARTER_PATTERN, quarter, tmpDate.toString(" YY")));
            tmpDate = tmpDate.plusMonths(3);
            break;
        case YEAR:
            start = tmpDate.dayOfYear().withMinimumValue().millisOfDay().withMinimumValue().toDate().getTime();
            end = tmpDate.dayOfYear().withMaximumValue().millisOfDay().withMaximumValue().toDate().getTime();

            xValues.add(tmpDate.toString(X_AXIS_YEAR_PATTERN));
            tmpDate = tmpDate.plusYears(1);
            break;
        }
        List<Float> stack = new ArrayList<>();
        for (Account account : mAccountsDbAdapter.getSimpleAccountList()) {
            if (account.getAccountType() == mAccountType && !account.isPlaceholderAccount()
                    && account.getCurrency() == mCurrency) {

                double balance = mAccountsDbAdapter
                        .getAccountsBalance(Collections.singletonList(account.getUID()), start, end).asDouble();
                if (balance != 0) {
                    if (!accountToColorMap.containsKey(account.getUID())) {
                        Integer color;
                        if (mUseAccountColor) {
                            color = (account.getColorHexCode() != null)
                                    ? Color.parseColor(account.getColorHexCode())
                                    : COLORS[accountToColorMap.size() % COLORS.length];
                        } else {
                            color = COLORS[accountToColorMap.size() % COLORS.length];
                        }
                        accountToColorMap.put(account.getUID(), color);
                    }

                    stack.add((float) balance);
                    labels.add(account.getName());
                    colors.add(accountToColorMap.get(account.getUID()));
                    Log.d(TAG, mAccountType + tmpDate.toString(" MMMM yyyy ") + account.getName() + " = "
                            + stack.get(stack.size() - 1));
                }
            }
        }

        String stackLabels = labels.subList(labels.size() - stack.size(), labels.size()).toString();
        values.add(new BarEntry(floatListToArray(stack), i, stackLabels));
    }

    BarDataSet set = new BarDataSet(values, "");
    set.setDrawValues(false);
    set.setStackLabels(labels.toArray(new String[labels.size()]));
    set.setColors(colors);

    if (set.getYValueSum() == 0) {
        mChartDataPresent = false;
        return getEmptyData();
    }
    mChartDataPresent = true;
    return new BarData(xValues, set);
}

From source file:org.gnucash.android.ui.report.linechart.CashFlowLineChartFragment.java

License:Apache License

/**
 * Returns entries which represent a user data of the specified account type
 * @param accountType account's type which user data will be processed
 * @return entries which represent a user data
 *//* w  w w .  j a  va2s .  c o m*/
private List<Entry> getEntryList(AccountType accountType) {
    List<String> accountUIDList = new ArrayList<>();
    for (Account account : mAccountsDbAdapter.getSimpleAccountList()) {
        if (account.getAccountType() == accountType && !account.isPlaceholderAccount()
                && account.getCommodity().equals(mCommodity)) {
            accountUIDList.add(account.getUID());
        }
    }

    LocalDateTime earliest;
    LocalDateTime latest;
    if (mReportPeriodStart == -1 && mReportPeriodEnd == -1) {
        earliest = new LocalDateTime(mEarliestTimestampsMap.get(accountType));
        latest = new LocalDateTime(mLatestTimestampsMap.get(accountType));
    } else {
        earliest = new LocalDateTime(mReportPeriodStart);
        latest = new LocalDateTime(mReportPeriodEnd);
    }
    Log.d(TAG, "Earliest " + accountType + " date " + earliest.toString("dd MM yyyy"));
    Log.d(TAG, "Latest " + accountType + " date " + latest.toString("dd MM yyyy"));

    int xAxisOffset = getDateDiff(new LocalDateTime(mEarliestTransactionTimestamp), earliest);
    int count = getDateDiff(earliest, latest);
    List<Entry> values = new ArrayList<>(count + 1);
    for (int i = 0; i <= count; i++) {
        long start = 0;
        long end = 0;
        switch (mGroupInterval) {
        case QUARTER:
            int quarter = getQuarter(earliest);
            start = earliest.withMonthOfYear(quarter * 3 - 2).dayOfMonth().withMinimumValue().millisOfDay()
                    .withMinimumValue().toDate().getTime();
            end = earliest.withMonthOfYear(quarter * 3).dayOfMonth().withMaximumValue().millisOfDay()
                    .withMaximumValue().toDate().getTime();

            earliest = earliest.plusMonths(3);
            break;
        case MONTH:
            start = earliest.dayOfMonth().withMinimumValue().millisOfDay().withMinimumValue().toDate()
                    .getTime();
            end = earliest.dayOfMonth().withMaximumValue().millisOfDay().withMaximumValue().toDate().getTime();

            earliest = earliest.plusMonths(1);
            break;
        case YEAR:
            start = earliest.dayOfYear().withMinimumValue().millisOfDay().withMinimumValue().toDate().getTime();
            end = earliest.dayOfYear().withMaximumValue().millisOfDay().withMaximumValue().toDate().getTime();

            earliest = earliest.plusYears(1);
            break;
        }
        float balance = (float) mAccountsDbAdapter.getAccountsBalance(accountUIDList, start, end).asDouble();
        values.add(new Entry(balance, i + xAxisOffset));
        Log.d(TAG, accountType + earliest.toString(" MMM yyyy") + ", balance = " + balance);

    }

    return values;
}

From source file:org.gnucash.android.ui.report.LineChartFragment.java

License:Apache License

/**
 * Returns entries which represent a user data of the specified account type
 * @param accountType account's type which user data will be processed
 * @return entries which represent a user data
 */// w w  w.  ja  v  a  2 s .c  o m
private List<Entry> getEntryList(AccountType accountType) {
    List<String> accountUIDList = new ArrayList<>();
    for (Account account : mAccountsDbAdapter.getSimpleAccountList()) {
        if (account.getAccountType() == accountType && !account.isPlaceholderAccount()
                && account.getCurrency() == mCurrency) {
            accountUIDList.add(account.getUID());
        }
    }

    LocalDateTime earliest;
    LocalDateTime latest;
    if (mReportStartTime == -1 && mReportEndTime == -1) {
        earliest = new LocalDateTime(mEarliestTimestampsMap.get(accountType));
        latest = new LocalDateTime(mLatestTimestampsMap.get(accountType));
    } else {
        earliest = new LocalDateTime(mReportStartTime);
        latest = new LocalDateTime(mReportEndTime);
    }
    Log.d(TAG, "Earliest " + accountType + " date " + earliest.toString("dd MM yyyy"));
    Log.d(TAG, "Latest " + accountType + " date " + latest.toString("dd MM yyyy"));

    int xAxisOffset = getDateDiff(new LocalDateTime(mEarliestTransactionTimestamp), earliest);
    int count = getDateDiff(earliest, latest);
    List<Entry> values = new ArrayList<>(count + 1);
    for (int i = 0; i <= count; i++) {
        long start = 0;
        long end = 0;
        switch (mGroupInterval) {
        case QUARTER:
            int quarter = getQuarter(earliest);
            start = earliest.withMonthOfYear(quarter * 3 - 2).dayOfMonth().withMinimumValue().millisOfDay()
                    .withMinimumValue().toDate().getTime();
            end = earliest.withMonthOfYear(quarter * 3).dayOfMonth().withMaximumValue().millisOfDay()
                    .withMaximumValue().toDate().getTime();

            earliest = earliest.plusMonths(3);
            break;
        case MONTH:
            start = earliest.dayOfMonth().withMinimumValue().millisOfDay().withMinimumValue().toDate()
                    .getTime();
            end = earliest.dayOfMonth().withMaximumValue().millisOfDay().withMaximumValue().toDate().getTime();

            earliest = earliest.plusMonths(1);
            break;
        case YEAR:
            start = earliest.dayOfYear().withMinimumValue().millisOfDay().withMinimumValue().toDate().getTime();
            end = earliest.dayOfYear().withMaximumValue().millisOfDay().withMaximumValue().toDate().getTime();

            earliest = earliest.plusYears(1);
            break;
        }
        float balance = (float) mAccountsDbAdapter.getAccountsBalance(accountUIDList, start, end).asDouble();
        values.add(new Entry(balance, i + xAxisOffset));
        Log.d(TAG, accountType + earliest.toString(" MMM yyyy") + ", balance = " + balance);

    }

    return values;
}

From source file:org.jtwig.functions.builtin.DateFunctions.java

License:Apache License

private Date modify(String modifyString, LocalDateTime localDateTime) throws FunctionException {

    LocalDateTime result;/*from   ww w  . j  a  va 2 s .  co  m*/

    Matcher matcher = compile(MODIFY_PATTERN).matcher(modifyString);
    matcher.find();

    int signal = 1;

    if (matcher.group(1).equals("-"))
        signal = -1;

    int val = Integer.valueOf(matcher.group(2)) * signal;
    String type = matcher.group(3).toLowerCase();

    if (type.startsWith("day"))
        result = localDateTime.plusDays(val);
    else if (type.startsWith("month"))
        result = localDateTime.plusMonths(val);
    else if (type.startsWith("year"))
        result = localDateTime.plusYears(val);
    else if (type.startsWith("second"))
        result = localDateTime.plusSeconds(val);
    else if (type.startsWith("hour"))
        result = localDateTime.plusHours(val);
    else if (type.startsWith("minute"))
        result = localDateTime.plusMinutes(val);
    else
        throw new FunctionException("Unknown type " + matcher.group(3));

    return result.toDate();
}

From source file:view.popups.shift.ShiftPopup.java

private void initComboboxes() {

    cDate = new ComboBox();
    cDate.setPrefWidth(170);/*w ww. j ava  2  s  . c o  m*/

    LocalDateTime now = new LocalDateTime();
    now = now.withHourOfDay(0);
    now = now.withMinuteOfHour(0);
    LocalDateTime currentWeek = now;

    LocalDateTime threeMonthsForward = now.plusMonths(3);
    ArrayList<LocalDateTime> startDates = Xray.getInstance().getDatesInPeriod(currentWeek, threeMonthsForward);
    for (int i = 0; i < startDates.size(); i++) {
        if (startDates.get(i).getDayOfWeek() == 1) {
            cDate.getItems().add(startDates.get(i));
        }
    }

    Callback<ListView<LocalDateTime>, ListCell<LocalDateTime>> cellFactory = new Callback<ListView<LocalDateTime>, ListCell<LocalDateTime>>() {
        @Override
        public ListCell<LocalDateTime> call(ListView<LocalDateTime> param) {

            return new ListCell<LocalDateTime>() {
                @Override
                public void updateItem(LocalDateTime item, boolean empty) {
                    super.updateItem(item, empty);
                    if (!empty) {
                        String value = ScheduleHeader.WEEK_DAY_NAMES[item.getDayOfWeek() - 1];
                        value = value.replaceFirst(value.substring(1, value.length()),
                                value.substring(1, value.length()).toLowerCase());
                        setText("Uge " + item.getWeekOfWeekyear() + " den " + item.getDayOfMonth() + "/"
                                + item.getMonthOfYear() + " - " + value);
                    }
                }

            };
        }
    };

    cDate.setButtonCell(cellFactory.call(null));
    cDate.setCellFactory(cellFactory);

    cEmployee = new ComboBox();
    cEmployee.setPrefWidth(170);
    cEmployee.setDisable(true);

}

From source file:view.popups.TimeInvestmentPopup.java

private void fillContent() {
    //Fyld datoer ind i comboboks til start og slutdato:
    LocalDateTime now = new LocalDateTime();
    LocalDateTime oneWeekBack = now.minusMonths(12);
    LocalDateTime oneMonthForward = now.plusMonths(12);
    ArrayList<LocalDateTime> startDates = Xray.getInstance().getDatesInPeriod(oneWeekBack, oneMonthForward);
    for (int i = 0; i < startDates.size(); i++) {
        cStart.getItems().add(startDates.get(i));
    }//from   www.ja v  a 2 s. co m
    cStart.getSelectionModel().selectFirst();

    //Lav et cellfactory p comboboksen s datoerne vises overskueligt.
    Callback<ListView<LocalDateTime>, ListCell<LocalDateTime>> cellFactory = new Callback<ListView<LocalDateTime>, ListCell<LocalDateTime>>() {
        @Override
        public ListCell<LocalDateTime> call(ListView<LocalDateTime> param) {

            return new ListCell<LocalDateTime>() {
                @Override
                public void updateItem(LocalDateTime item, boolean empty) {
                    super.updateItem(item, empty);
                    if (!empty) {
                        String dayName = ScheduleHeader.WEEK_DAY_NAMES[item.getDayOfWeek() - 1];
                        setText(item.toString("dd/MM/yy") + " " + dayName.substring(0, 1)
                                + dayName.substring(1).toLowerCase());
                    }
                }

            };
        }
    };

    Xray.getInstance().fillDatesInEndDate(cEnd, cStart, 12);

    cStart.setButtonCell(cellFactory.call(null));
    cStart.setCellFactory(cellFactory);
    cEnd.setButtonCell(cellFactory.call(null));
    cEnd.setCellFactory(cellFactory);

}

From source file:view.popups.timePeriod.AddTimePeriodPopup.java

private void fillContent() {
    try {//  w  w w  .  j  a  v  a  2s.  co m
        ArrayList<Employee> employees = Xray.getInstance().getPersonControl().getEmployees();

        for (int i = 0; i < employees.size(); i++) {
            cEmp.getItems().add(employees.get(i));
        }
        cEmp.getSelectionModel().selectFirst();
    } catch (DatabaseException ex) {
        new ExceptionPopup().display(ex.getMessage());
    }

    try {
        ArrayList<Room> rooms = Xray.getInstance().getRoomControl().getRooms();

        for (int i = 0; i < rooms.size(); i++) {
            cRoom.getItems().add(rooms.get(i));
        }
        cRoom.getSelectionModel().selectFirst();
    } catch (DatabaseException ex) {
        new ExceptionPopup().display(ex.getMessage());
    }

    //Fyld datoer ind i comboboks til start og slutdato:
    LocalDateTime now = new LocalDateTime();
    LocalDateTime oneWeekBack = now.minusDays(7);
    LocalDateTime oneMonthForward = now.plusMonths(1);
    ArrayList<LocalDateTime> startDates = Xray.getInstance().getDatesInPeriod(oneWeekBack, oneMonthForward);
    for (int i = 0; i < startDates.size(); i++) {
        cStart.getItems().add(startDates.get(i));
    }
    cStart.getSelectionModel().selectFirst();

    //Lav et cellfactory p comboboksen s datoerne vises overskueligt.
    Callback<ListView<LocalDateTime>, ListCell<LocalDateTime>> cellFactory = new Callback<ListView<LocalDateTime>, ListCell<LocalDateTime>>() {
        @Override
        public ListCell<LocalDateTime> call(ListView<LocalDateTime> param) {

            return new ListCell<LocalDateTime>() {
                @Override
                public void updateItem(LocalDateTime item, boolean empty) {
                    super.updateItem(item, empty);
                    if (!empty) {
                        String dayName = ScheduleHeader.WEEK_DAY_NAMES[item.getDayOfWeek() - 1];
                        setText(item.toString("dd/MM") + " " + dayName.substring(0, 1)
                                + dayName.substring(1).toLowerCase());
                    }
                }

            };
        }
    };

    Xray.getInstance().fillDatesInEndDate(cEnd, cStart, 1);

    cStart.setButtonCell(cellFactory.call(null));
    cStart.setCellFactory(cellFactory);
    cEnd.setButtonCell(cellFactory.call(null));
    cEnd.setCellFactory(cellFactory);

}