Example usage for org.joda.time.format ISODateTimeFormat date

List of usage examples for org.joda.time.format ISODateTimeFormat date

Introduction

In this page you can find the example usage for org.joda.time.format ISODateTimeFormat date.

Prototype

public static DateTimeFormatter date() 

Source Link

Document

Returns a formatter for a full date as four digit year, two digit month of year, and two digit day of month (yyyy-MM-dd).

Usage

From source file:org.gephi.desktop.timeline.TimelineTooltip.java

License:Open Source License

private void buildData(double currentPosition) {
    if (model.getTimeFormat().equals(TimeFormat.DOUBLE)) {
        int exponentMin = (int) Math.round(Math.log10(model.getCustomMin()));

        DecimalFormat decimalFormat = new DecimalFormat();
        decimalFormat.setRoundingMode(RoundingMode.HALF_EVEN);

        if (exponentMin > 0) {
            min = String.valueOf(model.getCustomMin());
            max = String.valueOf(model.getCustomMax());
            position = String.valueOf(currentPosition);
        } else {/*w w w  .  j  av  a  2 s  .c om*/
            decimalFormat.setMaximumFractionDigits(Math.abs(exponentMin) + 2);
            min = decimalFormat.format(model.getCustomMin());
            max = decimalFormat.format(model.getCustomMax());
            position = decimalFormat.format(currentPosition);
        }
    } else if (model.getTimeFormat().equals(TimeFormat.DATE)) {
        DateTime minDate = new DateTime((long) model.getCustomMin());
        DateTime maxDate = new DateTime((long) model.getCustomMax());
        DateTime posDate = new DateTime((long) currentPosition);

        DateTimeFormatter formatter = ISODateTimeFormat.date();
        min = formatter.print(minDate);
        max = formatter.print(maxDate);
        position = formatter.print(posDate);
    } else {
        DateTime minDate = new DateTime((long) model.getCustomMin());
        DateTime maxDate = new DateTime((long) model.getCustomMax());
        DateTime posDate = new DateTime((long) currentPosition);

        DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
        min = formatter.print(minDate);
        max = formatter.print(maxDate);
        position = formatter.print(posDate);
    }

    if (model.getChart() != null) {
        TimelineChart chart = model.getChart();
        Number yNumber = chart.getY(currentPosition);
        y = yNumber != null ? yNumber.toString() : null;
    } else {
        y = null;
    }
}

From source file:org.goobi.production.model.bibliography.course.Granularity.java

License:Open Source License

/**
 * The function format() converts a given LocalDate to a String
 * representation of the date in the given granularity. For the 1st January
 * 2000 it will return:/* w w  w .  j  av  a  2s.c o  m*/
 * <p/>
 *  for DAYS: 2000-01-01  for WEEKS: 1999-W52  for MONTHS: 2000-01  for
 * QUARTERS: 2000/Q1  for YEARS: 2000
 *
 * <p>
 * The remaining cases are undefined and will throw NotImplementedException.
 * </p>
 *
 * @param date
 *            date to format
 * @return an expression of the date in the given granularity
 */
@SuppressWarnings("incomplete-switch")
public String format(LocalDate date) {
    switch (this) {
    case DAYS:
        return ISODateTimeFormat.date().print(date);
    case MONTHS:
        return ISODateTimeFormat.yearMonth().print(date);
    case QUARTERS:
        return ISODateTimeFormat.year().print(date) + "/Q"
                + Integer.toString(((date.getMonthOfYear() - 1) / 3) + 1);
    case WEEKS:
        return ISODateTimeFormat.weekyearWeek().print(date);
    case YEARS:
        return ISODateTimeFormat.year().print(date);
    }
    throw new NotImplementedException();
}

From source file:org.kitodo.production.model.bibliography.course.Granularity.java

License:Open Source License

/**
 * The function format() converts a given LocalDate to a String
 * representation of the date in the given granularity. For the 1st January
 * 2000 it will return:/*from   w ww .  j  av  a  2  s . c  om*/
 * <p/>
 *  for DAYS: 2000-01-01  for WEEKS: 1999-W52  for MONTHS: 2000-01  for
 * QUARTERS: 2000/Q1  for YEARS: 2000
 *
 * <p>
 * The remaining cases are undefined and will throw NotImplementedException.
 * </p>
 *
 * @param date
 *            date to format
 * @return an expression of the date in the given granularity
 */
public String format(LocalDate date) {
    switch (this) {
    case DAYS:
        return ISODateTimeFormat.date().print(date);
    case MONTHS:
        return ISODateTimeFormat.yearMonth().print(date);
    case QUARTERS:
        return ISODateTimeFormat.year().print(date) + "/Q" + ((date.getMonthOfYear() - 1) / 3) + 1;
    case WEEKS:
        return ISODateTimeFormat.weekyearWeek().print(date);
    case YEARS:
        return ISODateTimeFormat.year().print(date);
    default:
        throw new NotImplementedException();
    }
}

From source file:org.mulgara.store.stringpool.xa.SPDateImpl.java

License:Mozilla Public License

public String getLexicalForm() {
    if (timezoneOffset == Integer.MIN_VALUE) {
        // no timezone information
        return ISODateTimeFormat.date().withZone(DateTimeZone.UTC).print(date.getTime());
    }//from  ww  w  .j  a  v  a  2  s .com
    DateTimeZone zone = DateTimeZone.forOffsetMillis(timezoneOffset * MILLIS_IN_MINUTE);
    return outputFormat.withZone(zone).print(date.getTime());
}

From source file:org.nuxeo.ecm.restapi.server.jaxrs.adapters.AuditAdapter.java

License:Open Source License

protected Calendar getCalendarParameter(HttpServletRequest request, String paramName) {
    String param = request.getParameter(paramName);
    if (param != null) {
        DateTime date = ISODateTimeFormat.date().parseDateTime(param);
        if (date != null) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date.toDate());/*from   w ww .j  av a2s  . c om*/
            return cal;
        }
    }
    return null;
}

From source file:org.onebusaway.admin.model.BundleBuildRequest.java

License:Apache License

public LocalDate getBundleStartDate() {
    DateTimeFormatter dtf = ISODateTimeFormat.date();
    return (_bundleStartDate == null ? null : new LocalDate(dtf.parseLocalDate(_bundleStartDate)));
}

From source file:org.onebusaway.admin.model.BundleBuildRequest.java

License:Apache License

public LocalDate getBundleEndDate() {
    DateTimeFormatter dtf = ISODateTimeFormat.date();
    return (_bundleEndDate == null ? null : new LocalDate(dtf.parseLocalDate(_bundleEndDate)));
}

From source file:org.onebusaway.admin.service.bundle.api.BuildResource.java

License:Apache License

/**
 * Performs various validations on start and end dates
 * @param bundleStartDateString//from ww w. j a v a  2 s.co m
 * @param bundleEndDateString
 */
protected void validateDates(String bundleStartDateString, String bundleEndDateString)
        throws DateValidationException {
    if (StringUtils.isBlank(bundleStartDateString)) {
        throw new DateValidationException(bundleStartDateString, bundleEndDateString);
    }
    if (StringUtils.isBlank(bundleEndDateString)) {
        throw new DateValidationException(bundleStartDateString, bundleEndDateString);
    }

    DateTime startDate = ISODateTimeFormat.date().parseDateTime(bundleStartDateString);
    DateTime endDate = ISODateTimeFormat.date().parseDateTime(bundleEndDateString);

    if (startDate.isAfter(endDate)) {
        throw new DateValidationException(bundleStartDateString, bundleEndDateString);
    }
}

From source file:org.opensingular.form.type.core.STypeDate.java

License:Apache License

private static DateTimeFormatter isoFormarter() {
    return ISODateTimeFormat.date();
}

From source file:org.orbeon.oxf.processor.sql.interpreters.GetterInterpreter.java

License:Open Source License

/**
 *
 * Return the String value of a given column using the default XML type for the given SQL type.
 *
 * This is not meant to work with CLOB and BLOB types.
 */// ww w  .j a  v  a 2s  .c o  m
public static String getColumnStringValue(ResultSet resultSet, int columnIndex, int columnType)
        throws SQLException {
    String stringValue = null;
    if (columnType == Types.DATE) {
        final Date value = resultSet.getDate(columnIndex);
        if (value != null)
            stringValue = ISODateTimeFormat.date().print(value.getTime());
    } else if (columnType == Types.TIMESTAMP) {
        final Timestamp value = resultSet.getTimestamp(columnIndex);
        if (value != null)
            stringValue = DateUtils.DateTime().print(value.getTime());
    } else if (columnType == Types.DECIMAL || columnType == Types.NUMERIC) {
        final BigDecimal value = resultSet.getBigDecimal(columnIndex);
        stringValue = (resultSet.wasNull()) ? null : value.toString();
    } else if (columnType == Types.BOOLEAN) {
        final boolean value = resultSet.getBoolean(columnIndex);
        stringValue = (resultSet.wasNull()) ? null : (value ? "true" : "false");
    } else if (columnType == Types.INTEGER || columnType == Types.SMALLINT || columnType == Types.TINYINT
            || columnType == Types.BIGINT) {
        final long value = resultSet.getLong(columnIndex);
        stringValue = (resultSet.wasNull()) ? null : Long.toString(value);
    } else if (columnType == Types.DOUBLE || columnType == Types.FLOAT || columnType == Types.REAL) {
        final double value = resultSet.getDouble(columnIndex);
        // For XPath 1.0, we have to get rid of the scientific notation
        stringValue = resultSet.wasNull() ? null : XMLUtils.removeScientificNotation(value);
    } else if (columnType == Types.CLOB) {
        throw new OXFException("Cannot get String value for CLOB type.");
    } else if (columnType == Types.BLOB) {
        throw new OXFException("Cannot get String value for BLOB type.");
    } else {
        // Assume the type is compatible with getString()
        stringValue = resultSet.getString(columnIndex);
    }
    return stringValue;
}