Example usage for org.joda.time LocalDateTime toString

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

Introduction

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

Prototype

public String toString(String pattern) 

Source Link

Document

Output the date using the specified format pattern.

Usage

From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java

License:Apache License

private void updateEnd() {
    if (mHours.getEnd() != null) {
        LocalDateTime endDateTime = new LocalDateTime(mHours.getEnd().getTime());
        ((TextView) getView().findViewById(R.id.textview_hours_detail_end_date))
                .setText(endDateTime.toString(DATE_FORMAT_PATTERN));
    }//from   w w  w  . j av a 2s . co  m
}

From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java

License:Apache License

private void configureBeginDate(View view) {
    TextView beginDateTextView = (TextView) view.findViewById(R.id.textview_hours_detail_begin_date);
    beginDateTextView.setEnabled(isThisHoursRecordNotActive());
    if (isThisHoursRecordActive()) {
        beginDateTextView//from ww w .  j ava2  s . c o m
                .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.no_border, null));
    } else {
        beginDateTextView
                .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.rounded_border, null));
    }
    beginDateTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FragmentManager fragmentManager = getFragmentManager();
            // If there is already a Date displayed, use that.
            Date dateToUse = (mHours.getBegin() == null) ? new Date() : mHours.getBegin();
            DateTimePickerFragment datePickerFragment = FragmentFactory.createDatePickerFragment(dateToUse,
                    "Begin", DateTimePickerFragment.BOTH);
            datePickerFragment.setTargetFragment(HoursDetailFragment.this, REQUEST_BEGIN_DATE_PICKER);
            datePickerFragment.show(fragmentManager, DateTimePickerFragment.DIALOG_TAG);
        }
    });
    if (mHours.getBegin() != null) {
        LocalDateTime beginDateTime = new LocalDateTime(mHours.getBegin().getTime());
        beginDateTextView.setText(beginDateTime.toString(DATE_FORMAT_PATTERN));
    }
}

From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java

License:Apache License

private void configureEndDate(View view) {
    TextView endDateTextView = (TextView) view.findViewById(R.id.textview_hours_detail_end_date);
    endDateTextView.setEnabled(isThisHoursRecordNotActive());
    if (isThisHoursRecordActive()) {
        endDateTextView.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.no_border, null));
    } else {//from   w ww.  j a  v a  2 s .c  om
        endDateTextView
                .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.rounded_border, null));
    }
    endDateTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FragmentManager fragmentManager = getFragmentManager();
            // If there is already a Date displayed, use that.
            Date dateToUse = (mHours.getEnd() == null) ? new Date() : mHours.getEnd();
            DateTimePickerFragment datePickerFragment = FragmentFactory.createDatePickerFragment(dateToUse,
                    "End", DateTimePickerFragment.BOTH);
            datePickerFragment.setTargetFragment(HoursDetailFragment.this, REQUEST_END_DATE_PICKER);
            datePickerFragment.show(fragmentManager, DateTimePickerFragment.DIALOG_TAG);
        }
    });
    if (mHours.getEnd() != null) {
        LocalDateTime endDateTime = new LocalDateTime(mHours.getEnd().getTime());
        endDateTextView.setText(endDateTime.toString(DATE_FORMAT_PATTERN));
    }
}

From source file:com.metinkale.prayerapp.vakit.WidgetProviderClock2.java

License:Apache License

public static void updateAppWidget(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager,
        int widgetId) {

    if (mDP == 0) {
        Resources r = context.getResources();
        mDP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics());
    }// www.ja  va  2  s .com

    Resources r = context.getResources();
    SharedPreferences widgets = context.getSharedPreferences("widgets", 0);

    int w = widgets.getInt(widgetId + "_width", 500);
    int h = widgets.getInt(widgetId + "_height", 200);

    w = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, w, r.getDisplayMetrics());
    h = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, h, r.getDisplayMetrics());

    float scaleX = (float) w / (float) 2;
    float scaleY = (float) h / (float) 2;
    float scale = Math.min(scaleY, scaleX);

    w = (int) (2 * scale);
    h = (int) (2 * scale);

    if ((w <= 0) || (h <= 0)) {
        SharedPreferences.Editor edit = widgets.edit();
        edit.remove(widgetId + "_width");
        edit.remove(widgetId + "_height");
        edit.apply();
        updateAppWidget(context, appWidgetManager, widgetId);
        return;
    }

    Times times = null;
    long id = 0;
    try {
        id = widgets.getLong(widgetId + "", 0L);
    } catch (ClassCastException e) {
        widgets.edit().remove(widgetId + "").apply();
    }
    if (id != 0) {
        times = Times.getTimes(id);
    }
    if (times == null) {
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_city_removed);
        Intent i = new Intent(context, WidgetConfigureClock.class);
        i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
        remoteViews.setOnClickPendingIntent(R.id.image,
                PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT));
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
        return;
    }

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.vakit_widget);
    remoteViews.setOnClickPendingIntent(R.id.main, Main.getPendingIntent(times));

    Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(bmp);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setDither(true);
    paint.setFilterBitmap(true);

    paint.setStyle(Style.STROKE);
    paint.setAntiAlias(true);
    paint.setSubpixelText(true);
    paint.setShadowLayer(2, 2, 2, 0xFF555555);
    paint.setTextAlign(Align.CENTER);
    paint.setColor(Color.WHITE);

    paint.setColor(0xFFFFFFFF);
    paint.setStrokeWidth(w / 100);

    canvas.drawArc(new RectF(w / 100, w / 100, w - w / 100, h - w / 100), 0, 360, false, paint);

    boolean isKerahat = times.isKerahat();
    if (isKerahat) {
        paint.setColor(0xffbf3f5b);
    } else {
        paint.setColor(Theme.Light.strokecolor);
    }

    int next = times.getNext();
    int last = next - 1;
    if (Prefs.getVakitIndicator().equals("next"))
        last++;

    canvas.drawArc(new RectF(w / 100, w / 100, w - w / 100, h - w / 100), -90, times.getPassedPart() * 360,
            false, paint);

    paint.setStrokeWidth(1);
    LocalDateTime ltime = LocalDateTime.now();

    String[] time = Utils.fixTime(ltime.toString("HH:mm")).replace(":", " ").split(" ");
    paint.setTextSize(h * 0.50f);
    paint.setStyle(Style.FILL);
    paint.setColor(Color.WHITE);

    if (time.length == 3) {
        paint.setTextAlign(Align.RIGHT);
        canvas.drawText(time[0], w * 0.59f, h * 0.65f, paint);

        paint.setTextAlign(Align.LEFT);
        if (isKerahat) {
            paint.setColor(0xffbf3f5b);
        } else {
            paint.setColor(Theme.Light.strokecolor);
        }
        paint.setTextSize(h * 0.18f);
        canvas.drawText(time[1], w * 0.60f, h * 0.45f, paint);
        paint.setTextSize(h * 0.1f);
        paint.setTextSize(h * 0.1f);
        canvas.drawText(time[2], w * 0.80f, h * 0.45f, paint);

        paint.setColor(0xFFFFFFFF);
        paint.setTextSize(h * 0.07f);

        canvas.drawText(Utils.toArabicNrs(ltime.toString("d'.' MMM'.'")), w * 0.60f, h * 0.55f, paint);
        canvas.drawText(Vakit.getByIndex(last).getString(), w * 0.60f, h * 0.65f, paint);
    } else {

        paint.setTextAlign(Align.RIGHT);
        canvas.drawText(time[0], w * 0.62f, h * 0.65f, paint);

        paint.setTextAlign(Align.LEFT);
        if (isKerahat) {
            paint.setColor(0xffbf3f5b);
        } else {
            paint.setColor(Theme.Light.strokecolor);
        }
        paint.setTextSize(h * 0.22f);
        canvas.drawText(time[1], w * 0.63f, h * 0.45f, paint);

        paint.setColor(0xFFFFFFFF);
        paint.setTextSize(h * 0.07f);

        canvas.drawText(Utils.toArabicNrs(ltime.toString("d'.' MMM'.'")), w * 0.63f, h * 0.55f, paint);
        canvas.drawText(Vakit.getByIndex(last).getString(), w * 0.63f, h * 0.65f, paint);
    }

    paint.setTextAlign(Align.CENTER);

    paint.setTextSize(h * 0.15f);

    canvas.drawText(times.getLeft(next, false), w / 2, h * 0.85f, paint);

    paint.setTextSize(h * 0.12f);
    canvas.drawText(ltime.toString("EEEE"), w / 2, h * 0.22f, paint);

    remoteViews.setImageViewBitmap(R.id.widget, bmp);

    try {
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    } catch (RuntimeException e) {
        if (!e.getMessage().contains("exceeds maximum bitmap memory usage")) {
            Crashlytics.logException(e);
        }
    }
}

From source file:com.pinterest.secor.parser.AnalyticsMessageParser.java

License:Apache License

/**
 * Note that this depends on the {@link #jsonObject} state.
 *///from w  w  w.  j ava2  s.com
@Override
public String[] extractPartitions(Message message) {
    String result[] = { defaultType, defaultDate };
    String event_type = "";
    String analytics_type = "";

    /**
     * The idea is to store a directory structure that looks like
     * analytics-bucket/27/identify/2015/05/19/27/xxxxxxxxxxxx.json
     *
     *                  ^-- repeat the hour to spread the load among 24 shards
     *
     * analytics payloads may be of type: "track", event:"user_definded_name"
     *                           or type: "identify"
     *                           or type: "page"
     *                           or type: "screen"
     */

    if (jsonObject != null) {
        Object fieldType = jsonObject.get(mConfig.getMessageTypeName()); //type
        Object fieldValue = jsonObject.get(mConfig.getMessageTimestampName()); //timestamp

        if (fieldType != null) {
            analytics_type = fieldType.toString();
            if (analytics_type.equals("track")) {
                Object fieldSecondary = jsonObject.get("event");
                event_type = sanitizePath(fieldSecondary.toString());
            } else {
                event_type = analytics_type;
            }
        }

        if (fieldValue != null) {
            try {
                DateTimeFormatter inputFormatter = ISODateTimeFormat.dateOptionalTimeParser();
                LocalDateTime datetime = LocalDateTime.parse(fieldValue.toString(), inputFormatter);
                result[1] = datetime.toString(mConfig.getMessageTimestampBucketFormat());
            } catch (Exception e) {
                LOG.warn("date = " + fieldValue.toString() + " could not be parsed with ISODateTimeFormat."
                        + " Using date default=" + defaultDate);
            }
        }
    }

    // The hour bucket where the event happened
    String hour = result[1].split("/")[3];
    result[0] = hour + "/" + event_type;

    return result;
}

From source file:com.pinterest.secor.parser.DataLakeMessageParser.java

License:Apache License

@Override
public String[] extractPartitions(Message message) {
    JSONObject jsonObject = (JSONObject) JSONValue.parse(message.getPayload());
    String result[] = { defaultType, defaultDate };

    if (jsonObject != null) {
        Object fieldType = jsonObject.get(mConfig.getMessageTypeName()); //type
        Object fieldValue = jsonObject.get(mConfig.getMessageTimestampName()); //@timestamp
        if (fieldType != null) {
            result[0] = sanitizePath(fieldType.toString());
        }//  w w w.  ja  v a2 s  .c  o  m
        if (fieldValue != null) {
            try {

                DateTimeFormatter inputFormatter = ISODateTimeFormat.dateOptionalTimeParser();
                LocalDateTime datetime = LocalDateTime.parse(fieldValue.toString(), inputFormatter);
                result[1] = datetime.toString(mConfig.getMessageTimestampBucketFormat());
            } catch (Exception e) {
                LOG.warn("date = " + fieldValue.toString() + " could not be parsed with ISODateTimeFormat."
                        + " Using date default=" + defaultDate);
            }
        }
    }

    return result;
}

From source file:com.prayer.vakit.WidgetProviderClock2.java

License:Apache License

public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int widgetId) {

        if (mDP == 0) {
            Resources r = context.getResources();
            mDP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics());
        }// w w  w  .ja va 2 s  .  co m

        Resources r = context.getResources();
        SharedPreferences widgets = context.getSharedPreferences("widgets", 0);

        int w = widgets.getInt(widgetId + "_width", 500);
        int h = widgets.getInt(widgetId + "_height", 200);

        w = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, w, r.getDisplayMetrics());
        h = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, h, r.getDisplayMetrics());

        float scaleX = (float) w / (float) 2;
        float scaleY = (float) h / (float) 2;
        float scale = Math.min(scaleY, scaleX);

        w = (int) (2 * scale);
        h = (int) (2 * scale);

        if ((w <= 0) || (h <= 0)) {
            SharedPreferences.Editor edit = widgets.edit();
            edit.remove(widgetId + "_width");
            edit.remove(widgetId + "_height");
            edit.apply();
            updateAppWidget(context, appWidgetManager, widgetId);
            return;
        }

        Times times = null;
        long id = 0;
        try {
            id = widgets.getLong(widgetId + "", 0L);
        } catch (ClassCastException e) {
            widgets.edit().remove(widgetId + "").apply();
        }
        if (id != 0) {
            times = Times.getTimes(id);
        }
        if (times == null) {
            RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                    R.layout.widget_city_removed_prayer);
            Intent i = new Intent(context, WidgetConfigureClock.class);
            i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
            remoteViews.setOnClickPendingIntent(R.id.image,
                    PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT));
            appWidgetManager.updateAppWidget(widgetId, remoteViews);
            return;
        }

        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.vakit_widget_prayer);
        remoteViews.setOnClickPendingIntent(R.id.main, Main.getPendingIntent(times));

        Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444);
        Canvas canvas = new Canvas(bmp);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setDither(true);
        paint.setFilterBitmap(true);

        paint.setStyle(Style.STROKE);
        paint.setAntiAlias(true);
        paint.setSubpixelText(true);
        paint.setShadowLayer(2, 2, 2, 0xFF555555);
        paint.setTextAlign(Align.CENTER);
        paint.setColor(Color.WHITE);

        paint.setColor(0xFFFFFFFF);
        paint.setStrokeWidth(w / 100);

        canvas.drawArc(new RectF(w / 100, w / 100, w - w / 100, h - w / 100), 0, 360, false, paint);

        boolean isKerahat = times.isKerahat();
        if (isKerahat) {
            paint.setColor(0xffbf3f5b);
        } else {
            paint.setColor(ContextCompat.getColor(context, R.color.accent));
        }

        int next = times.getNext();
        int last = next - 1;
        if (Prefs.getVakitIndicator().equals("next"))
            last++;

        canvas.drawArc(new RectF(w / 100, w / 100, w - w / 100, h - w / 100), -90, times.getPassedPart() * 360,
                false, paint);

        paint.setStrokeWidth(1);
        LocalDateTime ltime = LocalDateTime.now();

        String[] time = Utils.fixTime(ltime.toString("HH:mm")).replace(":", " ").split(" ");
        paint.setTextSize(h * 0.50f);
        paint.setStyle(Style.FILL);
        paint.setColor(Color.WHITE);

        if (time.length == 3) {
            paint.setTextAlign(Align.RIGHT);
            canvas.drawText(time[0], w * 0.59f, h * 0.65f, paint);

            paint.setTextAlign(Align.LEFT);
            if (isKerahat) {
                paint.setColor(0xffbf3f5b);
            } else {
                paint.setColor(ContextCompat.getColor(context, R.color.accent));
            }
            paint.setTextSize(h * 0.18f);
            canvas.drawText(time[1], w * 0.60f, h * 0.45f, paint);
            paint.setTextSize(h * 0.1f);
            paint.setTextSize(h * 0.1f);
            canvas.drawText(time[2], w * 0.80f, h * 0.45f, paint);

            paint.setColor(0xFFFFFFFF);
            paint.setTextSize(h * 0.07f);

            canvas.drawText(Utils.toArabicNrs(ltime.toString("d'.' MMM'.'")), w * 0.60f, h * 0.55f, paint);
            canvas.drawText(Vakit.getByIndex(last).getString(), w * 0.60f, h * 0.65f, paint);
        } else {

            paint.setTextAlign(Align.RIGHT);
            canvas.drawText(time[0], w * 0.62f, h * 0.65f, paint);

            paint.setTextAlign(Align.LEFT);
            if (isKerahat) {
                paint.setColor(0xffbf3f5b);
            } else {
                paint.setColor(ContextCompat.getColor(context, R.color.accent));
            }
            paint.setTextSize(h * 0.22f);
            canvas.drawText(time[1], w * 0.63f, h * 0.45f, paint);

            paint.setColor(0xFFFFFFFF);
            paint.setTextSize(h * 0.07f);

            canvas.drawText(Utils.toArabicNrs(ltime.toString("d'.' MMM'.'")), w * 0.63f, h * 0.55f, paint);
            canvas.drawText(Vakit.getByIndex(last).getString(), w * 0.63f, h * 0.65f, paint);
        }

        paint.setTextAlign(Align.CENTER);

        paint.setTextSize(h * 0.15f);

        canvas.drawText(times.getLeft(next, false), w / 2, h * 0.85f, paint);

        paint.setTextSize(h * 0.12f);
        canvas.drawText(ltime.toString("EEEE"), w / 2, h * 0.22f, paint);

        remoteViews.setImageViewBitmap(R.id.widget, bmp);

        try {
            appWidgetManager.updateAppWidget(widgetId, remoteViews);
        } catch (RuntimeException e) {
            if (!e.getMessage().contains("exceeds maximum bitmap memory usage")) {
            }
        }
    }

From source file:com.sandata.lab.common.utils.date.DateUtil.java

License:Open Source License

public static String convertJodaDateTimetoString(LocalDate localDate, LocalTime localTime, String dateFormat) {
    LocalDateTime localDateTime = new LocalDateTime(localDate.toString() + "T" + localTime.toString());
    DateTimeFormatter fmt = DateTimeFormat.forPattern(dateFormat);
    return localDateTime.toString(fmt);
}

From source file:it.smartcommunitylab.model.ext.LocalDateTimeSerializer.java

License:Apache License

@Override
public void serialize(LocalDateTime value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {
    jgen.writeFieldName(value.toString(PointConcept.PERIOD_KEY_FORMAT));
}

From source file:org.apache.fineract.infrastructure.dataexport.service.DataExportWritePlatformServiceImpl.java

License:Apache License

@Override
public CommandProcessingResult createDataExport(final JsonCommand jsonCommand) {
    try {/*from  w  w w. j a  v a 2  s  . c  om*/
        // validate the request to create a new data export entity
        this.exportDataValidator.validateCreateDataExportRequest(jsonCommand);

        final DataExportCreateRequestData dataExportCreateRequestData = this.fromJsonHelper
                .fromJson(jsonCommand.json(), DataExportCreateRequestData.class);
        final String name = dataExportCreateRequestData.getName();
        final String baseEntityName = dataExportCreateRequestData.getBaseEntityName();
        final String[] datatableNames = dataExportCreateRequestData.getDatatables();
        final String[] columnNames = dataExportCreateRequestData.getColumns();
        final Map<String, String> filters = dataExportCreateRequestData.getFilters();
        final DataExportEntityData dataExportEntityData = this.dataExportReadPlatformService
                .retrieveTemplate(baseEntityName);
        final Collection<DatatableData> baseEntityDatatables = dataExportEntityData.getDatatables();
        final Collection<EntityColumnMetaData> baseEntityColumns = dataExportEntityData.getColumns();
        final Collection<DatatableData> selectedDatatables = new ArrayList<>();
        final Collection<EntityColumnMetaData> selectedColumns = new ArrayList<>();
        final Map<EntityColumnMetaData, String> selectedFilters = new HashMap<>();
        final Iterator<Map.Entry<String, String>> filterEntries = filters.entrySet().iterator();

        while (filterEntries.hasNext()) {
            Map.Entry<String, String> filterEntry = filterEntries.next();
            EntityColumnMetaData entityColumnMetaData = this.getEntityColumnMetaData(filterEntry.getKey(),
                    baseEntityColumns);

            if (entityColumnMetaData != null) {
                selectedFilters.put(entityColumnMetaData, filterEntry.getValue());
            }
        }

        for (String datatableName : datatableNames) {
            DatatableData datatableData = this.getDatatableData(datatableName, baseEntityDatatables);

            if (datatableData != null) {
                selectedDatatables.add(datatableData);
            }
        }

        for (String columnName : columnNames) {
            EntityColumnMetaData entityColumnMetaData = this.getEntityColumnMetaData(columnName,
                    baseEntityColumns);

            if (entityColumnMetaData != null) {
                selectedColumns.add(entityColumnMetaData);
            }
        }

        final String dataSql = this.generateDataSql(dataExportEntityData, selectedDatatables, selectedColumns,
                selectedFilters);
        final DataExport dataExport = DataExport.newInstance(name, baseEntityName, jsonCommand.json(), dataSql);
        final LocalDateTime currentDataTime = new LocalDateTime();
        final String dateTimeString = currentDataTime
                .toString(DataExportApiConstants.DATA_EXPORT_FILENAME_DATETIME_FORMAT_PATTERN);
        final String filename = FileHelper.sanitizeFilename(name) + "_" + dateTimeString;

        dataExport.updateFilename(filename);

        // save the new data export entity
        this.dataExportRepository.save(dataExport);

        return new CommandProcessingResultBuilder().withCommandId(jsonCommand.commandId())
                .withEntityId(dataExport.getId()).build();
    } catch (final DataIntegrityViolationException dve) {
        handleDataIntegrityIssues(jsonCommand, dve);

        return CommandProcessingResult.empty();
    }
}