Example usage for org.joda.time.format DateTimeFormat forPattern

List of usage examples for org.joda.time.format DateTimeFormat forPattern

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormat forPattern.

Prototype

public static DateTimeFormatter forPattern(String pattern) 

Source Link

Document

Factory to create a formatter from a pattern string.

Usage

From source file:com.metawiring.load.generators.DateSequenceFieldGenerator.java

License:Apache License

public DateSequenceFieldGenerator(int increment, String format) {
    this.increment = increment;
    this.formatter = DateTimeFormat.forPattern(format);
}

From source file:com.mfizz.binlog.type.DateTimePeriod.java

License:Apache License

private DateTimePeriod(String pattern, long millis) {
    this.pattern = pattern;
    if (pattern != null) {
        this.formatter = DateTimeFormat.forPattern(pattern).withZone(DateTimeZone.UTC);
    }//from   w  ww  . j  a v a2  s .  c o  m
    this.millis = millis;
}

From source file:com.microsoft.azure.credentials.AzureCliToken.java

License:Open Source License

Date expiresOn() {
    if (expiresOnDate == null) {
        try {/*  www. j  a  va2 s  . c o  m*/
            expiresOnDate = DateTime.parse(expiresOn, DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSSSSS"))
                    .toDate();
        } catch (IllegalArgumentException e) {
            expiresOnDate = DateTime.parse(expiresOn).toDate();
        }
    }
    return expiresOnDate;
}

From source file:com.miserablemind.api.consumer.tradeking.api.impl.response_entities.TKMarketStatusResponse.java

License:Open Source License

/**
 * Deserializer does not understand the milliseconds, need to do it manually here
 *
 * @param dateResponse a String date from Json
 */// ww  w. j  a v  a  2 s . com
@JsonSetter("date")
public void setDate(String dateResponse) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
    this.date = LocalDateTime.parse(dateResponse, formatter);
}

From source file:com.money.manager.ex.adapter.AllDataAdapter.java

License:Open Source License

@Override
public void bindView(View view, Context context, Cursor cursor) {
    // take a holder
    AllDataViewHolder holder = (AllDataViewHolder) view.getTag();

    String transactionType = cursor.getString(cursor.getColumnIndex(TRANSACTIONTYPE));
    boolean isTransfer = TransactionTypes.valueOf(transactionType).equals(TransactionTypes.Transfer);

    // header index
    int accountId = cursor.getInt(cursor.getColumnIndex(TOACCOUNTID));
    if (!mHeadersAccountIndex.containsKey(accountId)) {
        mHeadersAccountIndex.put(accountId, cursor.getPosition());
    }//from   w w w  .  j ava2  s  . co  m

    // Status
    String status = cursor.getString(cursor.getColumnIndex(STATUS));
    holder.txtStatus.setText(TransactionStatus.getStatusAsString(mContext, status));
    // color status
    int colorBackground = TransactionStatus.getBackgroundColorFromStatus(mContext, status);
    holder.linDate.setBackgroundColor(colorBackground);
    holder.txtStatus.setTextColor(Color.GRAY);

    // Date

    String dateString = cursor.getString(cursor.getColumnIndex(DATE));
    if (!TextUtils.isEmpty(dateString)) {
        DateTime dateTime = MmxDateTimeUtils.from(dateString);

        Locale locale = MoneyManagerApplication.getApp().getAppLocale();

        String month = DateTimeFormat.forPattern("MMM").withLocale(locale).print(dateTime);
        holder.txtMonth.setText(month);

        String year = DateTimeFormat.forPattern("yyyy").withLocale(locale).print(dateTime);
        holder.txtYear.setText(year);

        String day = DateTimeFormat.forPattern("dd").withLocale(locale).print(dateTime);
        holder.txtDay.setText(day);
    }

    // Amount

    double amount;
    if (useDestinationValues(isTransfer, cursor)) {
        amount = cursor.getDouble(cursor.getColumnIndex(TOAMOUNT));
        setCurrencyId(cursor.getInt(cursor.getColumnIndex(TOCURRENCYID)));
    } else {
        amount = cursor.getDouble(cursor.getColumnIndex(AMOUNT));
        setCurrencyId(cursor.getInt(cursor.getColumnIndex(CURRENCYID)));
    }

    CurrencyService currencyService = new CurrencyService(mContext);
    holder.txtAmount
            .setText(currencyService.getCurrencyFormatted(getCurrencyId(), MoneyFactory.fromDouble(amount)));

    // text color amount
    if (isTransfer) {
        holder.txtAmount.setTextColor(mContext.getResources().getColor(R.color.material_grey_700));
    } else if (TransactionTypes.valueOf(transactionType).equals(TransactionTypes.Deposit)) {
        holder.txtAmount.setTextColor(mContext.getResources().getColor(R.color.material_green_700));
    } else {
        holder.txtAmount.setTextColor(mContext.getResources().getColor(R.color.material_red_700));
    }

    // Group header - account name.
    if (isShowAccountName()) {
        if (mHeadersAccountIndex.containsValue(cursor.getPosition())) {
            holder.txtAccountName.setText(cursor.getString(cursor.getColumnIndex(TOACCOUNTNAME)));
            holder.txtAccountName.setVisibility(View.VISIBLE);
        } else {
            holder.txtAccountName.setVisibility(View.GONE);
        }
    } else {
        holder.txtAccountName.setVisibility(View.GONE);
    }

    // Payee
    String payee = getPayeeName(cursor, isTransfer);
    holder.txtPayee.setText(payee);

    // compose category description

    String categorySub;
    if (!isTransfer) {
        categorySub = cursor.getString(cursor.getColumnIndex(CATEGORY));
        // check sub category
        if (!(TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(SUBCATEGORY))))) {
            categorySub += " : <i>" + cursor.getString(cursor.getColumnIndex(SUBCATEGORY)) + "</i>";
        }
        // write category/subcategory format html
        if (!TextUtils.isEmpty(categorySub)) {
            // Display category/sub-category.
            categorySub = Html.fromHtml(categorySub).toString();
        } else {
            // It is either a Transfer or a split category.
            // then it is a split? todo: improve this check to make it explicit.
            categorySub = mContext.getString(R.string.split_category);
        }
    } else {
        categorySub = mContext.getString(R.string.transfer);
    }
    holder.txtCategorySub.setText(categorySub);

    // notes
    if (!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(NOTES)))) {
        holder.txtNotes.setText(
                Html.fromHtml("<small>" + cursor.getString(cursor.getColumnIndex(NOTES)) + "</small>"));
        holder.txtNotes.setVisibility(View.VISIBLE);
    } else {
        holder.txtNotes.setVisibility(View.GONE);
    }
    // check if item is checked
    if (mCheckedPosition.get(cursor.getPosition(), false)) {
        view.setBackgroundResource(R.color.material_green_100);
    } else {
        view.setBackgroundResource(android.R.color.transparent);
    }

    // Display balance account or days left.
    displayBalanceAmountOrDaysLeft(holder, cursor, context);
}

From source file:com.money.manager.ex.investment.morningstar.MorningstarPriceUpdater.java

License:Open Source License

/**
 * Parse Morningstar response into price information.
 * @param symbol Morningstar symbol/*  w  ww . j a va 2  s.c  o  m*/
 * @param html Result
 * @return An object containing price details
 */
private PriceDownloadedEvent parse(String symbol, String html) {
    Document doc = Jsoup.parse(html);

    // symbol
    String yahooSymbol = symbolConverter.getYahooSymbol(symbol);

    // price
    String priceString = doc.body().getElementById("last-price-value").text();
    Money price = MoneyFactory.fromString(priceString);
    // currency
    String currency = doc.body().getElementById("curency").text();
    if (currency.equals("GBX")) {
        price = price.divide(100, MoneyFactory.MAX_ALLOWED_PRECISION);
    }

    // date
    String dateString = doc.body().getElementById("asOfDate").text();
    DateTimeFormatter formatter = DateTimeFormat.forPattern("MM/dd/YYYY HH:mm:ss");
    // the time zone is EST
    DateTime date = formatter.withZone(DateTimeZone.forID("America/New_York")).parseDateTime(dateString)
            .withZone(DateTimeZone.forID("Europe/Vienna"));

    // todo: should this be converted to the exchange time?

    return new PriceDownloadedEvent(yahooSymbol, price, date);
}

From source file:com.money.manager.ex.investment.PriceCsvParser.java

License:Open Source License

/**
 * Parses CSV content and fires an PriceDownloadedEvent.
 * @param content CSV content to parse into price information.
 */// w  w w. j a v  a  2  s  . c om
public PriceDownloadedEvent parse(String content) {
    // cleanup
    content = content.trim();

    // validation
    if (TextUtils.isEmpty(content)) {
        throw new IllegalArgumentException("Downloaded CSV contents are empty");
    }

    // parse CSV contents to get proper fields that can be saved to the database.
    CSVParser csvParser = new CSVParser();
    String[] values;
    try {
        values = csvParser.parseLineMulti(content);
    } catch (IOException e) {
        Timber.e(e, "parsing downloaded CSV contents");
        return null;
    }

    // convert csv values to their original type.

    String symbol = values[0];

    // price
    String priceString = values[1];
    if (!NumericHelper.isNumeric(priceString))
        return null;
    Money price = MoneyFactory.fromString(priceString);
    // LSE stocks are expressed in GBp (pence), not Pounds.
    // From stockspanel.cpp, line 785: if (StockQuoteCurrency == "GBp") dPrice = dPrice / 100;
    String currency = values[3];
    if (currency.equals("GBp")) {
        price = price.divide(100, MoneyFactory.MAX_ALLOWED_PRECISION);
    }

    // date
    DateTimeFormatter format = DateTimeFormat.forPattern("MM/dd/yyyy");
    DateTime date = format.parseDateTime(values[2]);

    // Note: For currencies, the symbol is i.e. AUDEUR=X

    return new PriceDownloadedEvent(symbol, price, date);
}

From source file:com.money.manager.ex.investment.yql.YqlSecurityPriceUpdaterRetrofit.java

License:Open Source License

private SecurityPriceModel getSecurityPriceFor(JsonObject quote) {
    SecurityPriceModel priceModel = new SecurityPriceModel();
    priceModel.symbol = quote.get("symbol").getAsString();

    ExceptionHandler handler = new ExceptionHandler(getContext(), this);

    // Price/*from   w  ww. j a  va  2s  .c o m*/

    JsonElement priceElement = quote.get("LastTradePriceOnly");
    if (priceElement == JsonNull.INSTANCE) {
        handler.showMessage(
                getContext().getString(R.string.error_no_price_found_for_symbol) + " " + priceModel.symbol);
        return null;
    }
    String priceString = priceElement.getAsString();
    if (!NumericHelper.isNumeric(priceString)) {
        handler.showMessage(
                getContext().getString(R.string.error_no_price_found_for_symbol) + " " + priceModel.symbol);
        return null;
    }

    priceModel.price = readPrice(priceString, quote);

    // Date

    DateTime date = MmxDateTimeUtils.today();
    JsonElement dateElement = quote.get("LastTradeDate");
    if (dateElement != JsonNull.INSTANCE) {
        // Sometimes the date is not available. For now we will use today's date.
        DateTimeFormatter format = DateTimeFormat.forPattern("MM/dd/yyyy");
        date = format.parseDateTime(dateElement.getAsString());
    }
    priceModel.date = date;

    return priceModel;
}

From source file:com.money.manager.ex.search.OnDateButtonClickListener.java

License:Open Source License

@Override
public void onClick(View v) {
    DateTime dateTime = MmxDateTimeUtils.today();
    String calendarValue = mTextView.getText().toString();

    if (!TextUtils.isEmpty(calendarValue)) {
        String userDatePattern = new MmxDateTimeUtils(mParent.getApplicationContext()).getUserDatePattern();
        DateTimeFormatter formatter = DateTimeFormat.forPattern(userDatePattern);
        dateTime = formatter.parseDateTime(calendarValue);
    }/*w ww. ja  v a 2s  .  c om*/

    CalendarDatePickerDialogFragment datePicker = new CalendarDatePickerDialogFragment()
            .setFirstDayOfWeek(MmxDateTimeUtils.getFirstDayOfWeek()).setOnDateSetListener(mDateSetListener)
            .setPreselectedDate(dateTime.getYear(), dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth());
    if (new UIHelper(mParent).isDarkTheme()) {
        datePicker.setThemeDark();
    }
    datePicker.show(mParent.getSupportFragmentManager(), DATEPICKER_TAG);
}

From source file:com.money.manager.ex.servicelayer.qif.QifRecord.java

License:Open Source License

private String parseDate(AccountTransactionDisplay transaction) throws ParseException {
    DateTime date = transaction.getDate();

    // todo: get Quicken date format from settings.
    DateTimeFormatter qifFormat = DateTimeFormat.forPattern("MM/dd''yy");

    return qifFormat.print(date);
}