List of usage examples for org.joda.time LocalDateTime LocalDateTime
public LocalDateTime(Object instant)
From source file:org.gnucash.android.model.Recurrence.java
License:Apache License
/** * Computes the number of occurrences of this recurrences between start and end date * <p>If there is no end date, it returns -1</p> * @return Number of occurrences, or -1 if there is no end date *///from w w w . ja va 2 s .c o m public int getCount() { if (mPeriodEnd == null) return -1; int multiple = mPeriodType.getMultiplier(); ReadablePeriod jodaPeriod; switch (mPeriodType) { case DAY: jodaPeriod = Days.days(multiple); break; case WEEK: jodaPeriod = Weeks.weeks(multiple); break; case MONTH: jodaPeriod = Months.months(multiple); break; case YEAR: jodaPeriod = Years.years(multiple); break; default: jodaPeriod = Months.months(multiple); } int count = 0; LocalDateTime startTime = new LocalDateTime(mPeriodStart.getTime()); while (startTime.toDateTime().getMillis() < mPeriodEnd.getTime()) { ++count; startTime = startTime.plus(jodaPeriod); } return count; /* //this solution does not use looping, but is not very accurate int multiplier = mPeriodType.getMultiplier(); LocalDateTime startDate = new LocalDateTime(mPeriodStart.getTime()); LocalDateTime endDate = new LocalDateTime(mPeriodEnd.getTime()); switch (mPeriodType){ case DAY: return Days.daysBetween(startDate, endDate).dividedBy(multiplier).getDays(); case WEEK: return Weeks.weeksBetween(startDate, endDate).dividedBy(multiplier).getWeeks(); case MONTH: return Months.monthsBetween(startDate, endDate).dividedBy(multiplier).getMonths(); case YEAR: return Years.yearsBetween(startDate, endDate).dividedBy(multiplier).getYears(); default: return -1; } */ }
From source file:org.gnucash.android.model.Recurrence.java
License:Apache License
/** * Sets the end time of this recurrence by specifying the number of occurences * @param numberOfOccurences Number of occurences from the start time *///from w w w. j a v a 2 s . c o m public void setPeriodEnd(int numberOfOccurences) { LocalDateTime localDate = new LocalDateTime(mPeriodStart.getTime()); LocalDateTime endDate; int occurrenceDuration = numberOfOccurences * mPeriodType.getMultiplier(); switch (mPeriodType) { case DAY: endDate = localDate.plusDays(occurrenceDuration); break; case WEEK: endDate = localDate.plusWeeks(occurrenceDuration); break; default: case MONTH: endDate = localDate.plusMonths(occurrenceDuration); break; case YEAR: endDate = localDate.plusYears(occurrenceDuration); break; } mPeriodEnd = new Timestamp(endDate.toDateTime().getMillis()); }
From source file:org.gnucash.android.ui.chart.BarChartActivity.java
License:Apache License
/** * Returns a data object that represents a user data of the specified account types * @param accountType account's type which will be displayed * @return a {@code BarData} instance that represents a user data *//*from ww w .jav a 2 s .c om*/ private BarData getData(AccountType accountType) { 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(accountType).toDate().getTime()); for (int i = 0; i <= Months.monthsBetween(getStartDate(accountType), getEndDate(accountType)) .getMonths(); i++) { long start = tmpDate.dayOfMonth().withMinimumValue().millisOfDay().withMinimumValue().toDate() .getTime(); long end = tmpDate.dayOfMonth().withMaximumValue().millisOfDay().withMaximumValue().toDate().getTime(); List<Float> stack = new ArrayList<>(); for (Account account : mAccountsDbAdapter.getSimpleAccountList()) { if (account.getAccountType() == accountType && !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, accountType + 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)); xValues.add(tmpDate.toString(X_AXIS_PATTERN)); tmpDate = tmpDate.plusMonths(1); } BarDataSet set = new BarDataSet(values, ""); 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.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 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 = 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.chart.PieChartActivity.java
License:Apache License
/** * Sets up settings and data for the account type spinner. Currently used only {@code EXPENSE} and {@code INCOME} * account types./*from ww w . java 2 s . c o m*/ */ private void setUpSpinner() { Spinner spinner = (Spinner) findViewById(R.id.chart_data_spinner); ArrayAdapter<AccountType> dataAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, Arrays.asList(AccountType.EXPENSE, AccountType.INCOME)); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(dataAdapter); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { mAccountType = (AccountType) ((Spinner) findViewById(R.id.chart_data_spinner)).getSelectedItem(); mEarliestTransactionDate = new LocalDateTime( mTransactionsDbAdapter.getTimestampOfEarliestTransaction(mAccountType, mCurrencyCode)); mLatestTransactionDate = new LocalDateTime( mTransactionsDbAdapter.getTimestampOfLatestTransaction(mAccountType, mCurrencyCode)); mChartDate = mLatestTransactionDate; setData(false); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); }
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 ww. j av a 2s.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 */// w w w .ja v a 2 s.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 a data object that represents a user data of the specified account types * @param accountTypeList account's types which will be displayed * @return a {@code LineData} instance that represents a user data *//* ww w. j av a 2 s . c o m*/ private LineData getData(List<AccountType> accountTypeList) { Log.w(TAG, "getData"); calculateEarliestAndLatestTimestamps(accountTypeList); // LocalDateTime? LocalDate startDate; LocalDate endDate; if (mReportPeriodStart == -1 && mReportPeriodEnd == -1) { startDate = new LocalDate(mEarliestTransactionTimestamp).withDayOfMonth(1); endDate = new LocalDate(mLatestTransactionTimestamp).withDayOfMonth(1); } else { startDate = new LocalDate(mReportPeriodStart).withDayOfMonth(1); endDate = new LocalDate(mReportPeriodEnd).withDayOfMonth(1); } int count = getDateDiff(new LocalDateTime(startDate.toDate().getTime()), new LocalDateTime(endDate.toDate().getTime())); Log.d(TAG, "X-axis count" + count); List<String> xValues = new ArrayList<>(); for (int i = 0; i <= count; i++) { switch (mGroupInterval) { case MONTH: xValues.add(startDate.toString(X_AXIS_PATTERN)); Log.d(TAG, "X-axis " + startDate.toString("MM yy")); startDate = startDate.plusMonths(1); break; case QUARTER: int quarter = getQuarter(new LocalDateTime(startDate.toDate().getTime())); xValues.add("Q" + quarter + startDate.toString(" yy")); Log.d(TAG, "X-axis " + "Q" + quarter + startDate.toString(" MM yy")); startDate = startDate.plusMonths(3); break; case YEAR: xValues.add(startDate.toString("yyyy")); Log.d(TAG, "X-axis " + startDate.toString("yyyy")); startDate = startDate.plusYears(1); break; // default: } } List<LineDataSet> dataSets = new ArrayList<>(); for (AccountType accountType : accountTypeList) { LineDataSet set = new LineDataSet(getEntryList(accountType), accountType.toString()); set.setDrawFilled(true); set.setLineWidth(2); set.setColor(COLORS[dataSets.size()]); set.setFillColor(FILL_COLORS[dataSets.size()]); dataSets.add(set); } LineData lineData = new LineData(xValues, dataSets); if (lineData.getYValueSum() == 0) { mChartDataPresent = false; return getEmptyData(); } return lineData; }
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 va2 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.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 a data object that represents a user data of the specified account types * @param accountTypeList account's types which will be displayed * @return a {@code LineData} instance that represents a user data *///from w ww.j a v a2 s. c o m private LineData getData(List<AccountType> accountTypeList) { Log.w(TAG, "getData"); calculateEarliestAndLatestTimestamps(accountTypeList); // LocalDateTime? LocalDate startDate; LocalDate endDate; if (mReportStartTime == -1 && mReportEndTime == -1) { startDate = new LocalDate(mEarliestTransactionTimestamp).withDayOfMonth(1); endDate = new LocalDate(mLatestTransactionTimestamp).withDayOfMonth(1); } else { startDate = new LocalDate(mReportStartTime).withDayOfMonth(1); endDate = new LocalDate(mReportEndTime).withDayOfMonth(1); } int count = getDateDiff(new LocalDateTime(startDate.toDate().getTime()), new LocalDateTime(endDate.toDate().getTime())); Log.d(TAG, "X-axis count" + count); List<String> xValues = new ArrayList<>(); for (int i = 0; i <= count; i++) { switch (mGroupInterval) { case MONTH: xValues.add(startDate.toString(X_AXIS_PATTERN)); Log.d(TAG, "X-axis " + startDate.toString("MM yy")); startDate = startDate.plusMonths(1); break; case QUARTER: int quarter = getQuarter(new LocalDateTime(startDate.toDate().getTime())); xValues.add("Q" + quarter + startDate.toString(" yy")); Log.d(TAG, "X-axis " + "Q" + quarter + startDate.toString(" MM yy")); startDate = startDate.plusMonths(3); break; case YEAR: xValues.add(startDate.toString("yyyy")); Log.d(TAG, "X-axis " + startDate.toString("yyyy")); startDate = startDate.plusYears(1); break; // default: } } List<LineDataSet> dataSets = new ArrayList<>(); for (AccountType accountType : accountTypeList) { LineDataSet set = new LineDataSet(getEntryList(accountType), accountType.toString()); set.setDrawFilled(true); set.setLineWidth(2); set.setColor(COLORS[dataSets.size()]); set.setFillColor(FILL_COLORS[dataSets.size()]); dataSets.add(set); } LineData lineData = new LineData(xValues, dataSets); if (lineData.getYValueSum() == 0) { mChartDataPresent = false; return getEmptyData(); } return lineData; }