Example usage for org.joda.time.format DateTimeFormatter parseMutableDateTime

List of usage examples for org.joda.time.format DateTimeFormatter parseMutableDateTime

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormatter parseMutableDateTime.

Prototype

public MutableDateTime parseMutableDateTime(String text) 

Source Link

Document

Parses a date-time from the given text, returning a new MutableDateTime.

Usage

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

License:Apache License

/**
 * Method to get for the parameters returned from the form as a datetimes.
 *
 * @param _date date//from w w  w  . j a va2  s  . c  o  m
 * @param _hour hour
 * @param _minute minutes
 * @param _ampm am/pm
 * @return valid string
 * @throws EFapsException on error
 */
public List<DateTime> getDateList(final List<StringValue> _date, final List<StringValue> _hour,
        final List<StringValue> _minute, final List<StringValue> _ampm) throws EFapsException {
    final List<DateTime> ret = new ArrayList<>();
    if (_date != null) {
        Iterator<StringValue> hourIter = null;
        Iterator<StringValue> minuteIter = null;
        Iterator<StringValue> ampmIter = null;
        if (_hour != null) {
            hourIter = _hour.iterator();
        }
        if (_minute != null) {
            minuteIter = _minute.iterator();
        }
        if (_ampm != null) {
            ampmIter = _ampm.iterator();
        }

        for (final StringValue date : _date) {
            if (!date.isNull() && !date.isEmpty()) {
                final DateTimeFormatter fmt = DateTimeFormat
                        .forPattern(this.converter.getDatePattern(Context.getThreadContext().getLocale()))
                        .withChronology(Context.getThreadContext().getChronology());
                fmt.withLocale(getLocale());
                final MutableDateTime mdt = fmt.parseMutableDateTime(date.toString());
                if (hourIter != null) {
                    final StringValue hourStr = hourIter.next();
                    final int hour = Integer.parseInt(hourStr.toString("0"));
                    mdt.setHourOfDay(hour);
                    if (ampmIter != null) {
                        final StringValue ampmStr = ampmIter.next();
                        if ("am".equals(ampmStr.toString("am"))) {
                            if (hour == 12) {
                                mdt.setHourOfDay(0);
                            }
                        } else {
                            if (hour != 12) {
                                mdt.setHourOfDay(hour + 12);
                            }
                        }
                    }
                    if (minuteIter != null) {
                        final StringValue minuteStr = minuteIter.next();
                        final int minute = Integer.parseInt(minuteStr.toString("0"));
                        mdt.setMinuteOfHour(minute);
                    }
                }
                ret.add(mdt.toDateTime());
            }
        }
    }
    return ret;
}