Example usage for org.joda.time LocalDate toString

List of usage examples for org.joda.time LocalDate toString

Introduction

In this page you can find the example usage for org.joda.time LocalDate toString.

Prototype

public String toString(String pattern) 

Source Link

Document

Output the date using the specified format pattern.

Usage

From source file:com.mars.test.jodatime.Mars_App.java

public static void main(String[] args) {
    // LocalDate  , TimeZone
    LocalDate dt = new LocalDate();

    // 1.?1~31/* ww w . j  av a 2 s . com*/
    log.info("1.?" + dt.withDayOfMonth(1).toString(pattern) + " ~ "
            + dt.dayOfMonth().withMaximumValue().toString(pattern));

    // 2.?26~25(????)
    log.info("2.?" + dt.minusMonths(1).withDayOfMonth(26).toString(pattern) + " ~ "
            + dt.withDayOfMonth(25).toString(pattern));

    // 3.???
    LocalDate date2 = dt.withDayOfMonth(5);
    if (date2.getDayOfWeek() == DateTimeConstants.SATURDAY
            || date2.getDayOfWeek() == DateTimeConstants.SUNDAY) {
        date2 = date2.plusWeeks(1).withDayOfWeek(1);
    }
    log.info("3." + date2.toString(pattern));

    LocalDate date3 = dt.plusMonths(1).withDayOfMonth(5);
    if (date3.getDayOfWeek() >= 6) {
        date3 = date3.plusWeeks(1).withDayOfWeek(1);
    }
    log.info("4.2014/7" + date3.toString(pattern));

}

From source file:com.mbc.jfin.holiday.impl.financialcalendar.HolidayFile.java

License:Open Source License

private String formatDate(LocalDate date) {
    return date.toString("yyyyMMdd");
}

From source file:com.metinkale.prayerapp.vakit.fragments.MainFragment.java

License:Apache License

private void export(int csvpdf, @NonNull LocalDate from, @NonNull LocalDate to) throws IOException {
    File outputDir = getActivity().getCacheDir();
    if (!outputDir.exists())
        outputDir.mkdirs();/*from ww w  .j a va  2s . c o  m*/
    File outputFile = new File(outputDir, mTimes.getName().replace(" ", "_") + (csvpdf == 0 ? ".csv" : ".pdf"));
    if (outputDir.exists())
        outputFile.delete();
    FileOutputStream outputStream;

    outputStream = new FileOutputStream(outputFile);
    if (csvpdf == 0) {
        outputStream.write("Date;Fajr;Shuruq;Dhuhr;Asr;Maghrib;Ishaa\n".getBytes());

        do {
            outputStream.write((from.toString("yyyy-MM-dd") + ";").getBytes());
            outputStream.write((mTimes.getTime(from, 0) + ";").getBytes());
            outputStream.write((mTimes.getTime(from, 1) + ";").getBytes());
            outputStream.write((mTimes.getTime(from, 2) + ";").getBytes());
            outputStream.write((mTimes.getTime(from, 3) + ";").getBytes());
            outputStream.write((mTimes.getTime(from, 4) + ";").getBytes());
            outputStream.write((mTimes.getTime(from, 5) + "\n").getBytes());
        } while (!(from = from.plusDays(1)).isAfter(to));
        outputStream.close();

    } else {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
            PdfDocument document = new PdfDocument();

            PdfDocument.PageInfo pageInfo = null;
            int pw = 595;
            int ph = 842;
            pageInfo = new PdfDocument.PageInfo.Builder(pw, ph, 1).create();
            PdfDocument.Page page = document.startPage(pageInfo);
            Drawable launcher = Drawable.createFromStream(getActivity().getAssets().open("pdf/launcher.png"),
                    null);
            Drawable qr = Drawable.createFromStream(getActivity().getAssets().open("pdf/qrcode.png"), null);
            Drawable badge = Drawable.createFromStream(
                    getActivity().getAssets().open("pdf/badge_" + Prefs.getLanguage() + ".png"), null);

            launcher.setBounds(30, 30, 30 + 65, 30 + 65);
            qr.setBounds(pw - 30 - 65, 30 + 65 + 5, pw - 30, 30 + 65 + 5 + 65);
            int w = 100;
            int h = w * badge.getIntrinsicHeight() / badge.getIntrinsicWidth();
            badge.setBounds(pw - 30 - w, 30 + (60 / 2 - h / 2), pw - 30, 30 + (60 / 2 - h / 2) + h);

            Canvas canvas = page.getCanvas();

            Paint paint = new Paint();
            paint.setARGB(255, 0, 0, 0);
            paint.setTextSize(10);
            paint.setTextAlign(Paint.Align.CENTER);
            canvas.drawText("com.metinkale.prayer", pw - 30 - w / 2, 30 + (60 / 2 - h / 2) + h + 10, paint);

            launcher.draw(canvas);
            qr.draw(canvas);
            badge.draw(canvas);

            paint.setARGB(255, 61, 184, 230);
            canvas.drawRect(30, 30 + 60, pw - 30, 30 + 60 + 5, paint);

            if (mTimes.getSource().resId != 0) {
                Drawable source = getResources().getDrawable(mTimes.getSource().resId);

                h = 65;
                w = h * source.getIntrinsicWidth() / source.getIntrinsicHeight();
                source.setBounds(30, 30 + 65 + 5, 30 + w, 30 + 65 + 5 + h);
                source.draw(canvas);
            }

            paint.setARGB(255, 0, 0, 0);
            paint.setTextSize(40);
            paint.setTextAlign(Paint.Align.LEFT);
            canvas.drawText(getText(R.string.appName).toString(), 30 + 65 + 5, 30 + 50, paint);
            paint.setTextAlign(Paint.Align.CENTER);
            paint.setFakeBoldText(true);
            canvas.drawText(mTimes.getName(), pw / 2.0f, 30 + 65 + 50, paint);

            paint.setTextSize(12);
            int y = 30 + 65 + 5 + 65 + 30;
            int p = 30;
            int cw = (pw - p - p) / 7;
            canvas.drawText(getString(R.string.date), 30 + (0.5f * cw), y, paint);
            canvas.drawText(Vakit.IMSAK.getString(), 30 + (1.5f * cw), y, paint);
            canvas.drawText(Vakit.GUNES.getString(), 30 + (2.5f * cw), y, paint);
            canvas.drawText(Vakit.OGLE.getString(), 30 + (3.5f * cw), y, paint);
            canvas.drawText(Vakit.IKINDI.getString(), 30 + (4.5f * cw), y, paint);
            canvas.drawText(Vakit.AKSAM.getString(), 30 + (5.5f * cw), y, paint);
            canvas.drawText(Vakit.YATSI.getString(), 30 + (6.5f * cw), y, paint);
            paint.setFakeBoldText(false);
            do {
                y += 20;
                canvas.drawText((from.toString("dd.MM.yyyy")), 30 + (0.5f * cw), y, paint);
                canvas.drawText((mTimes.getTime(from, 0)), 30 + (1.5f * cw), y, paint);
                canvas.drawText((mTimes.getTime(from, 1)), 30 + (2.5f * cw), y, paint);
                canvas.drawText((mTimes.getTime(from, 2)), 30 + (3.5f * cw), y, paint);
                canvas.drawText((mTimes.getTime(from, 3)), 30 + (4.5f * cw), y, paint);
                canvas.drawText((mTimes.getTime(from, 4)), 30 + (5.5f * cw), y, paint);
                canvas.drawText((mTimes.getTime(from, 5)), 30 + (6.5f * cw), y, paint);
            } while (!(from = from.plusDays(1)).isAfter(to));
            document.finishPage(page);

            document.writeTo(outputStream);

            // close the document
            document.close();

        } else {
            Toast.makeText(getActivity(), R.string.versionNotSupported, Toast.LENGTH_LONG).show();
        }
    }

    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setType(csvpdf == 0 ? "text/csv" : "application/pdf");

    Uri uri = FileProvider.getUriForFile(getActivity(), "com.metinkale.prayer.fileprovider", outputFile);
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

    startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.export)));
}

From source file:com.metinkale.prayerapp.vakit.times.WebTimes.java

License:Apache License

@Override
protected synchronized String _getTime(@NonNull LocalDate date, int time) {
    String str = times.get(date.toString("yyyy-MM-dd") + "-" + time);
    if (str == null || str.isEmpty() || str.contains("00:00")) {
        return "00:00";
    }/* w w w. ja v a  2s.c o  m*/
    return str.replace("*", "");
}

From source file:com.metinkale.prayerapp.vakit.times.WebTimes.java

License:Apache License

private synchronized void setTime(@NonNull LocalDate date, int time, @NonNull String value) {
    if (deleted() || value.contains("00:00"))
        return;/*from  ww  w  . j a v a 2s. c o  m*/
    times.put(date.toString("yyyy-MM-dd") + "-" + time, value.replace("*", ""));
    save();
}

From source file:com.metinkale.prayerapp.vakit.times.WebTimes.java

License:Apache License

private int getSyncedDays() {
    LocalDate date = LocalDate.now().plusDays(1);
    int i = 0;/*from ww w.j  a  v a  2 s  .c  o  m*/
    while (i < 45) {
        String prefix = date.toString("yyyy-MM-dd") + "-";
        String times[] = { this.times.get(prefix + 0), this.times.get(prefix + 1), this.times.get(prefix + 2),
                this.times.get(prefix + 3), this.times.get(prefix + 4), this.times.get(prefix + 5) };
        for (String time : times) {
            if (time == null || time.contains("00:00"))
                return i;
        }
        i++;
        date = date.plusDays(1);
    }
    return i;

}

From source file:com.metinkale.prayerapp.vakit.times.WebTimes.java

License:Apache License

@NonNull
public LocalDate getFirstSyncedDay() {
    LocalDate date = LocalDate.now();
    int i = 0;//from   ww w.  j a  v  a2  s.co m
    while (true) {
        String prefix = date.toString("yyyy-MM-dd") + "-";
        String times[] = { this.times.get(prefix + 0), this.times.get(prefix + 1), this.times.get(prefix + 2),
                this.times.get(prefix + 3), this.times.get(prefix + 4), this.times.get(prefix + 5) };
        for (String time : times) {
            if (time == null || time.contains("00:00") || i > this.times.size())
                return date.plusDays(1);
        }
        i++;
        date = date.minusDays(1);
    }
}

From source file:com.metinkale.prayerapp.vakit.times.WebTimes.java

License:Apache License

@NonNull
public LocalDate getLastSyncedDay() {
    LocalDate date = LocalDate.now();
    int i = 0;//from ww w  . j  a v  a 2  s.c o m
    while (true) {
        String prefix = date.toString("yyyy-MM-dd") + "-";
        String times[] = { this.times.get(prefix + 0), this.times.get(prefix + 1), this.times.get(prefix + 2),
                this.times.get(prefix + 3), this.times.get(prefix + 4), this.times.get(prefix + 5) };
        for (String time : times) {
            if (time == null || time.contains("00:00") || i > this.times.size())
                return date.minusDays(1);
        }
        i++;
        date = date.plusDays(1);
    }
}

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

License:Open Source License

@Override
public OptionQuote getQuoteForOption(String ticker, LocalDate expirationDate, OptionQuote.OptionType type,
        double strikePrice) throws OptionQuoteNotFoundException {

    String timeString = expirationDate.toString("yyMMdd");

    String optionType = (type == OptionQuote.OptionType.CALL) ? "C" : "P";
    String paddedPrice = String.format("%08d", (int) (strikePrice * 1000));

    String optionSymbol = ticker + timeString + optionType + paddedPrice;

    String tickersParamString = this.buildCommaSeparatedParameterValue(new String[] { optionSymbol });

    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    parameters.set("symbols", tickersParamString);

    try {/*  ww w.j  av  a2  s.  c  o m*/
        URI url = this.buildUri(URL_QUOTES, parameters);
        ResponseEntity<TKOptionQuoteResponse> response = this.getRestTemplate().getForEntity(url,
                TKOptionQuoteResponse.class);
        if (null != response.getBody().getError())
            throw new ApiException(TradeKingServiceProvider.PROVIDER_ID, response.getBody().getError());
        return response.getBody().getQuotes()[0];
    } catch (Exception e) {
        throw new OptionQuoteNotFoundException("Ticker: " + ticker, e);
    }

}

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

License:Open Source License

@Override
public OptionQuote[] searchOptions(String ticker, Double minStrikePrice, Double maxStrikePrice,
        OptionQuote.OptionType type, LocalDate startDate, LocalDate endDate) {

    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    String queryString = "put_call-eq:" + type;

    //Strike Prices
    if (null != minStrikePrice)
        queryString += " AND strikeprice-gte:" + minStrikePrice;
    if (null != maxStrikePrice)
        queryString += " AND strikeprice-lte:" + maxStrikePrice;

    //Dates//from  ww  w.j a  v a 2  s .  com
    if (null != startDate)
        queryString += " AND xdate-gte:" + startDate.toString("yyyyMMdd");
    if (null != endDate)
        queryString += " AND xdate-lte:" + endDate.toString("yyyyMMdd");

    parameters.set("symbol", ticker);
    parameters.set("query", queryString);

    URI url = this.buildUri(URL_SEARCH_OPTIONS, parameters);
    ResponseEntity<TKOptionQuoteResponse> response = this.getRestTemplate().getForEntity(url,
            TKOptionQuoteResponse.class);

    if (null != response.getBody().getError())
        throw new ApiException(TradeKingServiceProvider.PROVIDER_ID, response.getBody().getError());

    return response.getBody().getQuotes();

}