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

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

Introduction

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

Prototype

public static DateTimeFormatter forStyle(String style) 

Source Link

Document

Factory to create a format from a two character style pattern.

Usage

From source file:ca.travelagency.utils.DateUtils.java

License:Apache License

public static String formatDate(Date date) {
    if (date == null) {
        return StringUtils.EMPTY;
    }/* w w  w .j a  v a 2s . co  m*/
    return DateTimeFormat.forStyle(DATE_STYLE).print(date.getTime());
}

From source file:ca.travelagency.utils.DateUtils.java

License:Apache License

public static String formatDateTime(Date date) {
    if (date == null) {
        return StringUtils.EMPTY;
    }/*  w  w  w.  j ava2  s  .  c  om*/
    return DateTimeFormat.forStyle(DATE_TIME_STYLE).print(date.getTime());
}

From source file:ca.travelagency.utils.DateUtils.java

License:Apache License

public static String formatDateShort(Date date) {
    if (date == null) {
        return StringUtils.EMPTY;
    }/* w ww .j  a  v a2 s . c o  m*/
    return DateTimeFormat.forStyle(DATE_STYLE_SHORT).print(date.getTime());
}

From source file:com.evolveum.midpoint.wf.impl.processors.BaseModelInvocationProcessingHelper.java

License:Apache License

/**
 * Determines the root task name (e.g. "Workflow for adding XYZ (started 1.2.2014 10:34)")
 * TODO allow change processor to influence this name
 *///from  w  ww  .j  av a 2  s .  co m
private String determineRootTaskName(ModelContext context) {

    String operation;
    if (context.getFocusContext() != null && context.getFocusContext().getPrimaryDelta() != null
            && context.getFocusContext().getPrimaryDelta().getChangeType() != null) {
        switch (context.getFocusContext().getPrimaryDelta().getChangeType()) {
        case ADD:
            operation = "creation of";
            break;
        case DELETE:
            operation = "deletion of";
            break;
        case MODIFY:
            operation = "change of";
            break;
        default:
            throw new IllegalStateException();
        }
    } else {
        operation = "change of";
    }
    String name = MiscDataUtil.getFocusObjectName(context);

    DateTimeFormatter formatter = DateTimeFormat.forStyle("MM").withLocale(Locale.getDefault());
    String time = formatter.print(System.currentTimeMillis());

    //        DateFormat dateFormat = DateFormat.getDateTimeInstance();
    //        String time = dateFormat.format(new Date());

    return "Approving and executing " + operation + " " + name + " (started " + time + ")";
}

From source file:com.helger.datetime.format.SerializableDateTimeFormatter.java

License:Apache License

@Nonnull
private static DateTimeFormatter _createFormatter(@Nonnull final EFormatStyle eDateStyle,
        @Nonnull final EFormatStyle eTimeStyle, @Nullable final Locale aLocale) {
    return PDTFormatter.getWithLocaleAndChrono(
            DateTimeFormat.forStyle(eDateStyle.getStyleString() + eTimeStyle.getStyleString()), aLocale);
}

From source file:com.iukonline.amule.android.amuleremote.partfile.PartFileDetailsFragment.java

License:Open Source License

private void refreshView() {

    View v = getView();//from w w w. j  a v  a 2  s  .c  om

    if (mPartFile != null) {

        mFileNameText.setText(mPartFile.getFileName());

        String textCat = getResources().getString(R.string.partfile_details_cat_unknown);
        int backgroundColorCat = 0;
        int textColorCat = getResources().getColor(R.color.secondary_text);
        long cat = mPartFile.getCat();
        if (cat == 0) {
            textCat = getResources().getString(R.string.partfile_details_cat_nocat);

        } else {
            ECCategory[] catList = mApp.mECHelper.getCategories();
            if (catList != null) {
                for (int i = 0; i < catList.length; i++) {
                    if (catList[i].getId() == cat) {
                        textCat = catList[i].getTitle();

                        backgroundColorCat = 0xff000000 | (int) catList[i].getColor();
                        textColorCat = 0xff000000 | GUIUtils.chooseFontColor((int) catList[i].getColor());

                        break;
                    }
                }
            }
        }
        mCategoryText.setText(textCat);
        ((GradientDrawable) mCategoryText.getBackground()).setColor(backgroundColorCat);
        mCategoryText.setTextColor(textColorCat);

        mLinkText.setText(mPartFile.getEd2kLink());
        mDoneText.setText(GUIUtils.longToBytesFormatted(mPartFile.getSizeDone()));
        mSizeText.setText(GUIUtils.longToBytesFormatted(mPartFile.getSizeFull()));
        mRemainingText.setText(GUIUtils.getETA(getActivity(), mPartFile.getSizeFull() - mPartFile.getSizeDone(),
                mPartFile.getSpeed()));

        Date lastSeenComplateDate = mPartFile.getLastSeenComp();
        DateTime lastSeenComplateDateTime = new DateTime(lastSeenComplateDate);
        DateTime now = new DateTime();
        if (lastSeenComplateDate == null || lastSeenComplateDate.getTime() == 0L) {
            mLastSeenText.setText(getResources().getString(R.string.partfile_last_seen_never));
        } else {
            long lastSeenSeconds = (System.currentTimeMillis() - mPartFile.getLastSeenComp().getTime()) / 1000L;

            if (lastSeenSeconds <= 60L) {
                mLastSeenText.setText(getResources().getString(R.string.partfile_last_seen_now));
            } else if (lastSeenSeconds <= 3600L) {
                mLastSeenText.setText(getResources().getQuantityString(R.plurals.partfile_last_seen_mins,
                        (int) (lastSeenSeconds / 60L), lastSeenSeconds / 60L));
            } else if (lastSeenSeconds <= 86400L) {
                int lastSeenHours = (int) (lastSeenSeconds / 3600);
                if (lastSeenHours < 12 || lastSeenComplateDateTime.getDayOfMonth() == now.getDayOfMonth()) {
                    mLastSeenText.setText(getResources().getQuantityString(R.plurals.partfile_last_seen_hours,
                            lastSeenHours, lastSeenHours));
                } else {
                    mLastSeenText.setText(getResources().getString(R.string.partfile_last_seen_yesterday));
                }
            } else {
                int diffDays = Days.daysBetween(lastSeenComplateDateTime, now).getDays();
                if (diffDays <= 31) {
                    mLastSeenText.setText(getResources().getQuantityString(R.plurals.partfile_last_seen_days,
                            diffDays, diffDays));
                } else if (diffDays <= 180) {
                    int diffMonths = Months.monthsBetween(lastSeenComplateDateTime, now).getMonths();
                    mLastSeenText.setText(getResources().getQuantityString(R.plurals.partfile_last_seen_months,
                            diffMonths, diffMonths));
                } else {
                    mLastSeenText.setText(getResources().getString(R.string.partfile_last_seen_date,
                            lastSeenComplateDateTime.toString(DateTimeFormat.forStyle("L-")
                                    .withLocale(getResources().getConfiguration().locale))));
                }
            }
        }

        mSourcesAvailableText
                .setText(Integer.toString(mPartFile.getSourceCount() - mPartFile.getSourceNotCurrent()));
        mSourcesActiveText.setText(Integer.toString(mPartFile.getSourceXfer()));
        mSourcesA4AFText.setText(Integer.toString(mPartFile.getSourceA4AF()));
        mSourcesNotCurrentText.setText(Integer.toString(mPartFile.getSourceNotCurrent()));

        switch (mPartFile.getPrio()) {
        case ECPartFile.PR_LOW:
            mPriorityText.setText(R.string.partfile_prio_low);
            break;
        case ECPartFile.PR_NORMAL:
            mPriorityText.setText(R.string.partfile_prio_normal);
            break;
        case ECPartFile.PR_HIGH:
            mPriorityText.setText(R.string.partfile_prio_high);
            break;
        case ECPartFile.PR_AUTO_LOW:
            mPriorityText.setText(R.string.partfile_prio_auto_low);
            break;
        case ECPartFile.PR_AUTO_NORMAL:
            mPriorityText.setText(R.string.partfile_prio_auto_normal);
            break;
        case ECPartFile.PR_AUTO_HIGH:
            mPriorityText.setText(R.string.partfile_prio_auto_high);
            break;
        default:
            mPriorityText.setText(R.string.partfile_prio_unknown);
            break;
        }

        int statusColor = R.color.progressWaitingMid;

        switch (mPartFile.getStatus()) {

        case ECPartFile.PS_ALLOCATING:
            mStatusText.setText(R.string.partfile_status_allocating);
            break;
        case ECPartFile.PS_COMPLETE:
            mStatusText.setText(R.string.partfile_status_complete);
            statusColor = R.color.progressRunningMid;
            break;
        case ECPartFile.PS_COMPLETING:
            mStatusText.setText(R.string.partfile_status_completing);
            statusColor = R.color.progressRunningMid;
            break;
        case ECPartFile.PS_EMPTY:
            mStatusText.setText(R.string.partfile_status_empty);
            statusColor = R.color.progressBlockedMid;
            break;
        case ECPartFile.PS_ERROR:
            mStatusText.setText(R.string.partfile_status_error);
            statusColor = R.color.progressBlockedMid;
            break;
        case ECPartFile.PS_WAITINGFORHASH:
        case ECPartFile.PS_HASHING:
            mStatusText.setText(R.string.partfile_status_hashing);
            break;
        case ECPartFile.PS_INSUFFICIENT:
            mStatusText.setText(R.string.partfile_status_insuffcient);
            statusColor = R.color.progressBlockedMid;
            break;
        case ECPartFile.PS_PAUSED:
            mStatusText.setText(R.string.partfile_status_paused);
            break;
        case ECPartFile.PS_READY:
            if (mPartFile.getSourceXfer() > 0) {
                mStatusText.setText(R.string.partfile_status_downloading);
                mStatusText.append(" " + GUIUtils.longToBytesFormatted(mPartFile.getSpeed()) + "/s");
                statusColor = R.color.progressRunningMid;
            } else {
                mStatusText.setText(R.string.partfile_status_waiting);
                statusColor = R.color.progressWaitingMid;
            }
            break;
        case ECPartFile.PS_UNKNOWN:
            mStatusText.setText(R.string.partfile_status_unknown);
            statusColor = R.color.progressStoppedMid;
            break;
        default:
            mStatusText.setText("UNKNOWN-" + mPartFile.getStatus());
            break;
        }
        mStatusText.setTextColor(getResources().getColor(statusColor));
    }
}

From source file:com.xpn.xwiki.plugin.jodatime.JodaTimePlugin.java

License:Open Source License

/**
 * @see org.joda.time.format.DateTimeFormat#forStyle(String)
 *///from  w  w  w.  j av a 2 s  .  c om
public DateTimeFormatter getDateTimeFormatterForStyle(String style, XWikiContext context) {
    return DateTimeFormat.forStyle(style).withLocale((Locale) context.get("locale"));
}

From source file:ddf.metrics.plugin.webconsole.MetricsWebConsolePlugin.java

License:Open Source License

private void addCellLabelForRange(PrintWriter pw, DateMidnight startDate, DateTime endDate) {
    DateTimeFormatter dateFormatter = DateTimeFormat.forStyle(DATE_DISPLAY_FORMAT);
    String urlText = dateFormatter.print(startDate) + " - " + dateFormatter.print(endDate);
    LOGGER.debug("URL text = [{}]", urlText);
    addCellLabel(pw, urlText);/*from   ww  w  .  j a  va2  s . c om*/
}

From source file:dk.teachus.frontend.utils.Formatters.java

License:Apache License

public static DateTimeFormatter getFormatTime() {
    return DateTimeFormat.forStyle("-S") //$NON-NLS-1$
            .withLocale(Session.get().getLocale());
}

From source file:gov.nih.nci.calims2.ui.generic.crud.CRUDTableDecorator.java

License:BSD License

/**
 * Get the formatter for the DateTime column.
 * @param column The column//from   w  w  w .  j  ava2 s  .  co  m
 * @return The formatter for the DateTime column
 */
DateTimeFormatter getDateTimeFormatter(Column column) {
    DateTimeFormatter formatter = dateTimeFormatters.get(column.getName());
    if (formatter == null) {
        String format = (column.getFormat() != null) ? column.getFormat() : "S-";
        formatter = DateTimeFormat.forStyle(format).withLocale(locale);
        dateTimeFormatters.put(column.getName(), formatter);
    }
    return formatter;
}