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

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

Introduction

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

Prototype

public static DateTimeFormatter shortDate() 

Source Link

Document

Creates a format that outputs a short date format.

Usage

From source file:com.goodhuddle.huddle.web.site.handlebars.helper.DateTimeHelper.java

License:Open Source License

public DateTimeHelper() {
    defaultDateFormat = DateTimeFormat.shortDate();
    defaultTimeFormat = DateTimeFormat.shortTime();
    defaultDateTimeFormat = DateTimeFormat.shortDateTime();
}

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

License:Apache License

/**
 * Get the short date formatter for the passed locale.
 *
 * @param aDisplayLocale/*from   w  w w.ja v a2  s . c  o m*/
 *        The display locale to be used. May be <code>null</code>.
 * @return The created date time formatter. Never <code>null</code>.
 */
@Nonnull
public static DateTimeFormatter getShortFormatterDate(@Nullable final Locale aDisplayLocale) {
    return getWithLocaleAndChrono(DateTimeFormat.shortDate(), aDisplayLocale);
}

From source file:com.hmsinc.epicenter.velocity.DateTimeFormatTool.java

License:Open Source License

/**
 * Checks a string to see if it matches one of the standard DateTimeFormat
 * style patterns: full, long, medium, short, or default.
 *//*from   w  w w . j av  a  2 s  .c  o m*/
private static DateTimeFormatter getDateStyle(String style, Locale locale, DateTimeZone zone) {
    final DateTimeFormatter ret;

    if (style.equalsIgnoreCase("full")) {
        ret = DateTimeFormat.fullDate();
    } else if (style.equalsIgnoreCase("long")) {
        ret = DateTimeFormat.longDate();
    } else if (style.equalsIgnoreCase("medium")) {
        ret = DateTimeFormat.mediumDate();
    } else if (style.equalsIgnoreCase("short")) {
        ret = DateTimeFormat.shortDate();
    } else if (style.equalsIgnoreCase("none")) {
        ret = null;
    } else {
        ret = DateTimeFormat.forPattern(style);
    }

    return ret == null ? null : ret.withLocale(locale).withZone(zone);
}

From source file:com.moss.joda.swing.LiveDatePicker.java

License:Open Source License

public LiveDatePicker() {
    formats.add(DateTimeFormat.shortDate());
    formats.add(ISODateTimeFormat.date());
    formats.add(ISODateTimeFormat.basicDate());
    formats.add(DateTimeFormat.mediumDate());
    formats.add(DateTimeFormat.fullDate());
    formats.add(DateTimeFormat.longDate());

    //      p = new JXDatePicker();
    //      pButton = p.getComponent(1);
    //      p.getEditor().setVisible(false);

    pButton = new JButton("^");
    pButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Point p = pButton.getLocation();
            popup.show(pButton, 0, 0);//from  w  w  w  .  java  2  s  .c o  m

        }
    });
    popup.add(new DateSelectionListener() {
        public void dateSelected(YearMonthDay date) {
            setDate(date);
            fireSelection();
        }
    });

    t.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            handle();
        }

        public void insertUpdate(DocumentEvent e) {
            handle();
        }

        public void removeUpdate(DocumentEvent e) {
            handle();
        }

        void handle() {
            if (!uiUpdating) {
                String text = t.getText();
                YearMonthDay date = null;
                for (int x = 0; date == null && x < formats.size(); x++) {
                    DateTimeFormatter f = formats.get(x);
                    try {
                        date = f.parseDateTime(text).toYearMonthDay();
                    } catch (IllegalArgumentException e) {
                    }
                }
                value = date;
                if (date != null) {
                    popup.setDate(date);
                }
                fireSelection();
            }
        }

    });

    setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1;
    c.ipadx = 10;
    add(t, c);
    c.weightx = 0;
    c.ipadx = 0;
    //      c.insets.left = 5;
    add(pButton, c);

    setDate(new YearMonthDay());
}

From source file:com.vityuk.ginger.provider.format.JodaTimeUtils.java

License:Apache License

private static DateTimeFormatter createJodaDateFormatter(FormatType formatType, DateFormatStyle formatStyle) {
    switch (formatType) {
    case TIME:/*from   w  ww.  j a v a 2 s  . c  o m*/
        switch (formatStyle) {
        case SHORT:
            return DateTimeFormat.shortTime();
        case MEDIUM:
            return DateTimeFormat.mediumTime();
        case LONG:
            return DateTimeFormat.longTime();
        case FULL:
            return DateTimeFormat.fullTime();
        case DEFAULT:
            return ISODateTimeFormat.time();
        }
    case DATE:
        switch (formatStyle) {
        case SHORT:
            return DateTimeFormat.shortDate();
        case MEDIUM:
            return DateTimeFormat.mediumDate();
        case LONG:
            return DateTimeFormat.longDate();
        case FULL:
            return DateTimeFormat.fullDate();
        case DEFAULT:
            return ISODateTimeFormat.date();
        }
    case DATETIME:
        switch (formatStyle) {
        case SHORT:
            return DateTimeFormat.shortDateTime();
        case MEDIUM:
            return DateTimeFormat.mediumDateTime();
        case LONG:
            return DateTimeFormat.longDateTime();
        case FULL:
            return DateTimeFormat.fullDateTime();
        case DEFAULT:
            return ISODateTimeFormat.dateTime();
        }
    }

    throw new IllegalArgumentException();
}

From source file:de.geeksfactory.opacclient.frontend.AccountFragment.java

License:MIT License

private void export() {
    if (refreshing) {
        Toast.makeText(getActivity(), R.string.account_no_concurrent, Toast.LENGTH_LONG).show();
        if (!refreshing) {
            refresh();//from   w w w .j  ava  2s  .c o  m
        }
        return;
    }

    Context ctx = getActivity() != null ? getActivity() : OpacClient.getEmergencyContext();
    AccountDataSource adatasource = new AccountDataSource(ctx);
    AccountData data = adatasource.getCachedAccountData(account);
    LocalDateTime dt = new LocalDateTime(adatasource.getCachedAccountDataTime(account));

    if (data == null)
        return;

    StringBuilder string = new StringBuilder();

    DateTimeFormatter fmt1 = DateTimeFormat.shortDateTime()
            .withLocale(getResources().getConfiguration().locale);
    DateTimeFormatter fmt2 = DateTimeFormat.shortDate().withLocale(getResources().getConfiguration().locale);
    String dateStr = fmt1.print(dt);
    string.append(getResources().getString(R.string.accountdata_export_header, account.getLabel(), dateStr));
    string.append("\n\n");
    string.append(getResources().getString(R.string.lent_head));
    string.append("\n\n");
    for (LentItem item : data.getLent()) {
        appendIfNotEmpty(string, item.getTitle(), R.string.accountdata_title);
        appendIfNotEmpty(string, item.getAuthor(), R.string.accountdata_author);
        appendIfNotEmpty(string, item.getFormat(), R.string.accountdata_format);
        appendIfNotEmpty(string, item.getStatus(), R.string.accountdata_status);
        appendIfNotEmpty(string, item.getBarcode(), R.string.accountdata_lent_barcode);
        if (item.getDeadline() != null) {
            appendIfNotEmpty(string, fmt2.print(item.getDeadline()), R.string.accountdata_lent_deadline);
        }
        appendIfNotEmpty(string, item.getHomeBranch(), R.string.accountdata_lent_home_branch);
        appendIfNotEmpty(string, item.getLendingBranch(), R.string.accountdata_lent_lending_branch);
        string.append("\n");
    }

    if (data.getLent().size() == 0) {
        string.append(getResources().getString(R.string.lent_none));
    }

    string.append(getResources().getString(R.string.reservations_head));
    string.append("\n\n");
    for (ReservedItem item : data.getReservations()) {
        appendIfNotEmpty(string, item.getTitle(), R.string.accountdata_title);
        appendIfNotEmpty(string, item.getAuthor(), R.string.accountdata_author);
        appendIfNotEmpty(string, item.getFormat(), R.string.accountdata_format);
        appendIfNotEmpty(string, item.getStatus(), R.string.accountdata_status);
        if (item.getReadyDate() != null) {
            appendIfNotEmpty(string, fmt2.print(item.getReadyDate()), R.string.accountdata_reserved_ready_date);
        }
        if (item.getExpirationDate() != null) {
            appendIfNotEmpty(string, fmt2.print(item.getExpirationDate()),
                    R.string.accountdata_reserved_expiration_date);
        }
        appendIfNotEmpty(string, item.getBranch(), R.string.accountdata_reserved_branch);
        string.append("\n");
    }

    if (data.getReservations().size() == 0) {
        string.append(getResources().getString(R.string.reservations_none));
    }

    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, string.toString());
    sendIntent.setType("text/plain");
    startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.share_dialog_select)));
}

From source file:me.vertretungsplan.additionalinfo.BaseIcalParser.java

License:Mozilla Public License

@Override
public AdditionalInfo getAdditionalInfo() throws IOException {
    AdditionalInfo info = new AdditionalInfo();
    info.setTitle(getTitle());//  w  w  w  .  ja va 2 s .c  om

    String rawdata = httpGet(getIcalUrl(), "UTF-8");

    if (shouldStripTimezoneInfo()) {
        Pattern pattern = Pattern.compile("BEGIN:VTIMEZONE.*END:VTIMEZONE", Pattern.DOTALL);
        rawdata = pattern.matcher(rawdata).replaceAll("");
    }

    DateTime now = DateTime.now().withTimeAtStartOfDay();
    List<ICalendar> icals = Biweekly.parse(rawdata).all();

    List<Event> events = new ArrayList<>();
    for (ICalendar ical : icals) {
        for (VEvent event : ical.getEvents()) {
            Event item = new Event();

            TimeZone timezoneStart = getTimeZoneStart(ical, event);

            if (event.getDescription() != null) {
                item.description = event.getDescription().getValue();
            }
            if (event.getSummary() != null) {
                item.summary = event.getSummary().getValue();
            }
            if (event.getDateStart() != null) {
                item.startDate = new DateTime(event.getDateStart().getValue());
                item.startHasTime = event.getDateStart().getValue().hasTime();
            } else {
                continue;
            }
            if (event.getDateEnd() != null) {
                item.endDate = new DateTime(event.getDateEnd().getValue());
                item.endHasTime = event.getDateEnd().getValue().hasTime();
            }
            if (event.getLocation() != null) {
                item.location = event.getLocation().getValue();
            }
            if (event.getUrl() != null) {
                item.url = event.getUrl().getValue();
            }

            if (event.getRecurrenceRule() == null && item.endDate != null
                    && (item.endDate.compareTo(now) < 0)) {
                continue;
            } else if (event.getRecurrenceRule() == null && (item.startDate.compareTo(now) < 0)) {
                continue;
            }
            if (event.getRecurrenceRule() != null && event.getRecurrenceRule().getValue().getUntil() != null
                    && event.getRecurrenceRule().getValue().getUntil().compareTo(now.toDate()) < 0) {
                continue;
            }

            if (event.getRecurrenceRule() != null) {
                Duration duration = null;
                if (event.getDateEnd() != null) {
                    duration = new Duration(new DateTime(event.getDateStart().getValue()),
                            new DateTime(event.getDateEnd().getValue()));
                }

                DateIterator iterator = event.getDateIterator(timezoneStart);
                while (iterator.hasNext()) {
                    Date date = iterator.next();
                    Event reccitem = item.clone();
                    reccitem.startDate = new DateTime(date);
                    reccitem.endDate = reccitem.startDate.plus(duration);

                    if (item.startDate.equals(reccitem.startDate))
                        continue;

                    if (item.endDate != null && (item.endDate.compareTo(now) < 0)) {
                        continue;
                    } else if (item.endDate == null && (item.startDate.compareTo(now) < 0)) {
                        continue;
                    }

                    events.add(reccitem);
                }
            }

            if (item.endDate != null && (item.endDate.compareTo(now) < 0)) {
                continue;
            } else if (item.endDate == null && (item.startDate.compareTo(now) < 0)) {
                continue;
            }

            events.add(item);
        }
    }
    Collections.sort(events, new Comparator<Event>() {
        @Override
        public int compare(Event o1, Event o2) {
            return o1.startDate.compareTo(o2.startDate);
        }
    });

    StringBuilder content = new StringBuilder();

    int count = 0;

    DateTimeFormatter fmtDt = DateTimeFormat.shortDateTime().withLocale(Locale.GERMANY);
    DateTimeFormatter fmtD = DateTimeFormat.shortDate().withLocale(Locale.GERMANY);
    DateTimeFormatter fmtT = DateTimeFormat.shortTime().withLocale(Locale.GERMANY);

    for (Event item : events) {
        if (count >= getMaxItemsCount()) {
            break;
        } else if (count != 0) {
            content.append("<br><br>\n\n");
        }

        DateTime start = item.startDate;

        if (item.endDate != null) {
            DateTime end = item.endDate;

            if (!item.endHasTime) {
                end = end.minusDays(1);
            }

            content.append((item.startHasTime ? fmtDt : fmtD).print(start));
            if (!end.equals(start)) {
                content.append(" - ");
                if (item.startHasTime && item.endHasTime && end.toLocalDate().equals(start.toLocalDate())) {
                    content.append(fmtT.print(end));
                } else {
                    content.append((item.endHasTime ? fmtDt : fmtD).print(end));
                }
            }
        } else {
            content.append(fmtDt.print(start));
        }
        content.append("<br>\n");

        content.append("<b>");
        content.append(item.summary);
        content.append("</b>");

        count++;
    }

    info.setText(content.toString());

    return info;
}

From source file:net.schweerelos.timeline.model.Timeline.java

License:Open Source License

public String extractLabel(int slice) {
    Interval interval;/*w  w  w  .j a  v  a2s  .c om*/
    try {
        interval = convertSliceToInterval(slice);
    } catch (IllegalArgumentException iae) {
        iae.printStackTrace();
        return "";
    }
    DateTimeFormatter format = DateTimeFormat.shortDate();
    if (incrementMode == Mode.Days) {
        return interval.getStart().toString(format);
    } else {
        String incrementString = "";
        switch (incrementMode) {
        case Years:
            incrementString = "Year " + sliceLabelExtractor.extractLabel(interval.getStart()) + " (";
            break;
        case Months:
            incrementString = "Month " + sliceLabelExtractor.extractLabel(interval.getStart()) + " (";
            break;
        case Weeks:
            incrementString = "Week " + sliceLabelExtractor.extractLabel(interval.getStart()) + " (";
            break;
        }
        return incrementString + interval.getStart().toString(format) + " to "
                + interval.getEnd().toString(format) + ")";
    }
}

From source file:org.efaps.esjp.accounting.report.ExpenseReport_Base.java

License:Apache License

/**
 * Get the name for the report./*from ww w  .j a v  a 2 s . com*/
 * @param _parameter Parameter as passed form the eFaps API
 * @param _from fromdate
 * @param _to   to date
 * @return name of the report
 */
protected String getReportName(final Parameter _parameter, final DateTime _from, final DateTime _to) {
    return DBProperties.getProperty("Accounting_ExpenseReport.Label", "es") + "-"
            + _from.toString(DateTimeFormat.shortDate()) + "-" + _to.toString(DateTimeFormat.shortDate());
}

From source file:org.emonocot.harvest.media.ImageMetadataExtractorImpl.java

License:Open Source License

public ImageMetadataExtractorImpl() {

    dateTimeFormatters.add(ISODateTimeFormat.dateTimeParser());
    dateTimeFormatters.add(DateTimeFormat.fullDate());
    dateTimeFormatters.add(DateTimeFormat.fullDateTime());
    dateTimeFormatters.add(DateTimeFormat.shortDate());
    dateTimeFormatters.add(DateTimeFormat.shortDateTime());
    dateTimeFormatters.add(DateTimeFormat.mediumDate());
    dateTimeFormatters.add(DateTimeFormat.mediumDateTime());

}