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

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

Introduction

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

Prototype

public static String patternForStyle(String style, Locale locale) 

Source Link

Document

Returns the pattern used by a particular style and locale.

Usage

From source file:ca.gc.hc.mds.web.ApplicationController.java

void addDateTimeFormatPatterns(Model uiModel) {
    uiModel.addAttribute("application_entrydate_date_format",
            DateTimeFormat.patternForStyle("M-", LocaleContextHolder.getLocale()));
    uiModel.addAttribute("application_receiptdate_date_format",
            DateTimeFormat.patternForStyle("M-", LocaleContextHolder.getLocale()));
    uiModel.addAttribute("application_licencestatusdate_date_format",
            DateTimeFormat.patternForStyle("M-", LocaleContextHolder.getLocale()));
    uiModel.addAttribute("application_devicematerial_date_format",
            DateTimeFormat.patternForStyle("M-", LocaleContextHolder.getLocale()));
}

From source file:ca.travelagency.components.fields.BirthDateField.java

License:Apache License

String getDatePattern() {
    return DateTimeFormat.patternForStyle("S-", getLocale()).replaceAll("yy", "yyyy");
}

From source file:com.evolveum.midpoint.gui.api.util.WebComponentUtil.java

License:Apache License

public static String getLocalizedDatePattern(String style) {
    return DateTimeFormat.patternForStyle(style, getCurrentLocale());
}

From source file:gg.pistol.sweeper.gui.PollPage.java

License:Open Source License

private AbstractTableModel createTableModel() {
    return new AbstractTableModel() {

        @Override//from   w  w w.  jav  a2 s  . c  o  m
        public int getRowCount() {
            return targets.size();
        }

        @Override
        public int getColumnCount() {
            return 7;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            switch (columnIndex) {
            case 0:
                return sweeper.getCurrentPoll().getMark(targets.get(rowIndex)) == SweeperPoll.Mark.DECIDE_LATER;
            case 1:
                return sweeper.getCurrentPoll().getMark(targets.get(rowIndex)) == SweeperPoll.Mark.RETAIN;
            case 2:
                return sweeper.getCurrentPoll().getMark(targets.get(rowIndex)) == SweeperPoll.Mark.DELETE;
            case 3:
                return targets.get(rowIndex).getName();
            case 4:
                if (targets.get(rowIndex).getType() == Target.Type.FILE) {
                    return i18n.getString(I18n.RESOURCE_TYPE_FILE_ID);
                } else {
                    return i18n.getString(I18n.RESOURCE_TYPE_DIRECTORY_ID);
                }
            case 5:
                return formatSize(targets.get(rowIndex).getSize());
            case 6:
                DateTime date = targets.get(rowIndex).getModificationDate();
                return date == null ? i18n.getString(I18n.PAGE_POLL_TABLE_COLUMN_DATE_UNKNOWN_ID)
                        : date.toString(DateTimeFormat.patternForStyle("MM", i18n.getLocale()));
            }
            return null;
        }

        @Override
        public String getColumnName(int column) {
            switch (column) {
            case 0:
                return i18n.getString(I18n.PAGE_POLL_TABLE_COLUMN_DECIDE_LATER_ID);
            case 1:
                return i18n.getString(I18n.PAGE_POLL_TABLE_COLUMN_RETAIN_ID);
            case 2:
                return i18n.getString(I18n.PAGE_POLL_TABLE_COLUMN_DELETE_ID);
            case 3:
                return i18n.getString(I18n.RESOURCE_NAME_ID);
            case 4:
                return i18n.getString(I18n.PAGE_POLL_TABLE_COLUMN_TYPE_ID);
            case 5:
                return i18n.getString(I18n.RESOURCE_SIZE_ID);
            case 6:
                return i18n.getString(I18n.RESOURCE_MODIFIED_ID);
            }
            return null;
        }

        @Override
        public Class<?> getColumnClass(int columnIndex) {
            return columnIndex < 3 ? Boolean.class : String.class;
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return columnIndex < 3;
        }

        @Override
        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
            SweeperPoll.Mark mark = null;
            switch (columnIndex) {
            case 0:
                mark = SweeperPoll.Mark.DECIDE_LATER;
                break;
            case 1:
                mark = SweeperPoll.Mark.RETAIN;
                break;
            case 2:
                mark = SweeperPoll.Mark.DELETE;
                break;
            }
            sweeper.getCurrentPoll().mark(targets.get(rowIndex), mark);

            // Go to the next poll and back to update the statistics.
            sweeper.nextPoll();
            sweeper.previousPoll();

            statDelete.setText(i18n.getString(I18n.PAGE_POLL_STAT_DELETE_ID,
                    formatInt(sweeper.getCount().getToDeleteTargets()),
                    formatSize(sweeper.getCount().getToDeleteSize())));
            fireTableRowsUpdated(rowIndex, rowIndex);
        }
    };
}

From source file:openmarker.tea.runtime.DefaultContext.java

License:Apache License

public void dateFormat(String format, String timeZoneID) {
    DateTimeZone zone;//www.  j a va 2s  .  c  om
    if (timeZoneID != null) {
        zone = DateTimeZone.forID(timeZoneID);
    } else {
        zone = DateTimeZone.getDefault();
    }
    mDateTimeZone = zone;

    /* --Original before joda upgrade
    DateTimeFormat dtFormat;
    if (mLocale == null) {
    dtFormat = DateTimeFormat.getInstance(zone); --orig
    }
    else {
    dtFormat = DateTimeFormat.getInstance(zone, mLocale);
    }
            
    if (format == null) {
    format = dtFormat.getPatternForStyle("LL"); --orig
    }*/

    if (format == null) {
        format = DateTimeFormat.patternForStyle("LL", mLocale);
    }
    DateTimeFormatter formatter = DateTimeFormat.forPattern(format).withZone(zone);
    if (mLocale != null) {
        formatter = formatter.withLocale(mLocale);
    }

    mDateTimeFormatter = formatter;
    mDateTimePattern = format;
}

From source file:org.apache.wicket.datetime.StyleDateConverter.java

License:Apache License

/**
 * Gets the optional date pattern.//from   w  ww.ja  v a 2s . co m
 * 
 * @return datePattern
 */
@Override
public final String getDatePattern(Locale locale) {
    return DateTimeFormat.patternForStyle(dateStyle, locale);
}

From source file:org.apache.wicket.extensions.yui.calendar.DateTimeField.java

License:Apache License

/**
 * Checks whether the current {@link Locale} uses the 12h or 24h time format. This method can be
 * overridden to e.g. always use 24h format.
 * //w  ww  .  j a  va  2 s. c  om
 * @return true, if the current {@link Locale} uses the 12h format.<br/>
 *         false, otherwise
 */
protected boolean use12HourFormat() {
    String pattern = DateTimeFormat.patternForStyle("-S", getLocale());
    return pattern.indexOf('a') != -1 || pattern.indexOf('h') != -1 || pattern.indexOf('K') != -1;
}

From source file:org.auraframework.util.date.DateServiceImpl.java

License:Apache License

/**
 * Expects a two character style string, based on joda-time's style syntax:
 * /*from   w ww  . ja v  a 2  s.  c o m*/
 * @see <a
 *      href="http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html#patternForStyle(java.lang.String, java.util.Locale)">DateTimeFormat</a>
 *      <p>
 *      Style and results:
 *      <p>
 * 
 *      <pre>
 * SS   6/1/12 10:37 PM
 * SM   6/1/12 10:37:14 PM
 * SL   6/1/12 10:37:14 PM UTC
 * SF   6/1/12 10:37:14 PM UTC
 * S-   6/1/12
 * MS   Jun 1, 2012 10:37 PM
 * MM   Jun 1, 2012 10:37:14 PM
 * ML   Jun 1, 2012 10:37:14 PM UTC
 * MF   Jun 1, 2012 10:37:14 PM UTC
 * M-   Jun 1, 2012
 * LS   June 1, 2012 10:37 PM
 * LM   June 1, 2012 10:37:14 PM
 * LL   June 1, 2012 10:37:14 PM UTC
 * LF   June 1, 2012 10:37:14 PM UTC
 * L-   June 1, 2012
 * FS   Friday, June 1, 2012 10:37 PM
 * FM   Friday, June 1, 2012 10:37:14 PM
 * FL   Friday, June 1, 2012 10:37:14 PM UTC
 * FF   Friday, June 1, 2012 10:37:14 PM UTC
 * F-   Friday, June 1, 2012
 * -S   10:37 PM
 * -M   10:37:14 PM
 * -L   10:37:14 PM UTC
 * -F   10:37:14 PM UTC
 * </pre>
 */
private DateConverter getStyleConverter(Locale locale, String style) {
    if (style.length() != 2) {
        throw new IllegalArgumentException(
                "expecting two characters:  S, M, L, or F.  Use - to indicate that date or time should be repressed.");
    }
    String pattern = DateTimeFormat.patternForStyle(style, locale);
    return new JodaDateConverter(DateTimeFormat.forPattern(pattern).withLocale(locale));
}

From source file:org.dcm4chee.web.common.util.DateUtils.java

License:LGPL

public static String getDatePattern(Component c) {
    String pattern = DateTimeFormat.patternForStyle("S-", c.getLocale());
    int pos1 = pattern.indexOf('y');
    if (pos1 != -1) {
        if (pattern.length() <= pos1 + 2) {
            pattern = pattern + "yy";
        } else if (pattern.charAt(pos1 + 2) != 'y') {
            pattern = pattern.substring(0, pos1) + "yyyy" + pattern.substring(pos1 + 2);
        }/*  ww  w .j a  v  a 2 s  .com*/
    }
    return pattern;
}

From source file:org.efaps.ui.wicket.components.date.DateTimePanel.java

License:Apache License

/**
 * Depending on the locale am/pm is used or not.
 *
 * @return true if 12 hour format else false
 *//*w w  w .ja  va2 s  .  c o m*/
protected boolean use12HourFormat() {
    final String pattern = DateTimeFormat.patternForStyle("-S", getLocale());
    return pattern.indexOf('a') != -1 || pattern.indexOf('h') != -1 || pattern.indexOf('K') != -1;
}