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

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

Introduction

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

Prototype

public String print(ReadablePartial partial) 

Source Link

Document

Prints a ReadablePartial to a new String.

Usage

From source file:org.finra.datagenerator.engine.scxml.tags.boundary.BoundaryDate.java

License:Apache License

/**
 * @param isNullable isNullable/*from   www  . j av  a2s  .c o m*/
 * @param earliest   lower boundary date
 * @param latest     upper boundary date
 * @return a list of boundary dates
 */
public List<String> negativeCase(boolean isNullable, String earliest, String latest) {
    List<String> values = new LinkedList<>();

    DateTimeFormatter parser = ISODateTimeFormat.date();
    DateTime earlyDate = parser.parseDateTime(earliest);
    DateTime lateDate = parser.parseDateTime(latest);

    String prevDay = parser.print(earlyDate.minusDays(1));
    String nextDay = parser.print(lateDate.plusDays(1));

    values.add(prevDay);
    values.add(nextDay);
    values.add(nextDay.substring(5, 7) + "-" + nextDay.substring(8, 10) + "-" + nextDay.substring(0, 4));
    values.add(getRandomHoliday(earliest, latest));

    if (!isNullable) {
        values.add("");
    }
    return values;
}

From source file:org.flowable.cmmn.engine.impl.behavior.impl.TimerEventListenerActivityBehaviour.java

License:Apache License

public String prepareRepeat(String dueDate, Clock clock) {
    if (dueDate.startsWith("R") && dueDate.split("/").length == 2) {
        DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
        return dueDate.replace("/", "/" + fmt.print(
                new DateTime(clock.getCurrentTime(), DateTimeZone.forTimeZone(clock.getCurrentTimeZone())))
                + "/");
    }//from   ww w .j ava  2 s .  co m
    return dueDate;
}

From source file:org.gdg.frisbee.android.event.EventOverviewFragment.java

License:Apache License

private String formatTime(EventFullDetails eventFullDetails) {
    DateTimeFormatter fmt = DateTimeFormat.shortTime();
    return fmt.print(eventFullDetails.getStart());
}

From source file:org.gdg.frisbee.android.event.EventOverviewFragment.java

License:Apache License

private String formatDate(EventFullDetails eventFullDetails) {

    DateTimeFormatter fmt = DateTimeFormat.fullDate();
    // TODO check whether this is a multi day event
    return fmt.print(eventFullDetails.getStart());
}

From source file:org.georchestra.analytics.StatisticsController.java

License:Open Source License

/**
 * Convert date from UTC to local configured timezone. This method is used to convert dates returns by database.
 * @param rawDate raw date from database with format : "2016-02-12 23" or "2016-02-12" or "2016-06" or "2016-02"
 * @return date in local timezone with hour
 * @throws ParseException if input date is not parsable
 *//*from ww  w. j a  va2  s  .  c  om*/
private String convertUTCDateToLocal(String rawDate, GRANULARITY granularity) throws ParseException {
    DateTimeFormatter inputFormatter = null;
    DateTimeFormatter outputFormatter = null;
    switch (granularity) {
    case HOUR:
        inputFormatter = this.dbHourInputFormatter;
        outputFormatter = this.dbHourOutputFormatter;
        break;
    case DAY:
        inputFormatter = this.dbDayInputFormatter;
        outputFormatter = this.dbDayOutputFormatter;
        break;
    case WEEK:
        inputFormatter = this.dbWeekInputFormatter;
        outputFormatter = this.dbWeekOutputFormatter;
        break;
    case MONTH:
        inputFormatter = this.dbMonthInputFormatter;
        outputFormatter = this.dbMonthOutputFormatter;
        break;
    }
    DateTime localDatetime = inputFormatter.parseDateTime(rawDate);
    return outputFormatter.print(localDatetime.toInstant());
}

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  o m
            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.getwheat.harvest.library.request.BaseReportRequest.java

License:Apache License

private void addRangeDate(final RequestParameter parameter, final Date value) {
    if (parameter != null && value != null) {
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(RANGE_DATE_PATTERN);
        final DateTime date = new DateTime(value.getTime());
        try {/*w  w w  . ja va  2s .  c  o m*/
            helper.addParameter(parameter, formatter.print(date), getParameters());
        } catch (Exception ex) {
            LOG.warn("", ex);
        }
    }
}

From source file:org.getwheat.harvest.library.request.ParameterHelper.java

License:Apache License

/**
 * Adds the Update Since RequestParameter to the parameters List.
 * <p />/*  ww  w  . j av  a 2s .co  m*/
 * The updatedSince parameter is formatted to UTC time.
 * 
 * @param updatedSince
 * @param parameters
 */
public void addUpdatedSince(final Date updatedSince, final List<NameValuePair> parameters) {
    if (updatedSince != null) {
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(UPDATED_SINCE_PAT)
                .withZone(DateTimeZone.UTC);
        final DateTime date = new DateTime(updatedSince.getTime());
        try {
            addParameter(RequestParameter.UPDATED_SINCE, formatter.print(date), parameters);
        } catch (Exception ex) {
            LOG.warn("", ex);
        }
    }
}

From source file:org.glucosio.android.presenter.OverviewPresenter.java

License:Open Source License

public ArrayList<String> getGraphGlucoseDateTime() {
    ArrayList<String> glucoseDatetime = new ArrayList<>();
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm");

    for (int i = 0; i < glucoseGraphObjects.size(); i++) {
        glucoseDatetime.add(dateTimeFormatter.print(glucoseGraphObjects.get(i).getCreated()));
    }/*from   ww w  .  j  a  v  a2 s .c  o  m*/
    return glucoseDatetime;
}

From source file:org.gluu.oxtrust.service.antlr.scimFilter.util.GluuCustomPersonListSerializer.java

License:MIT License

private void writeStructure(String parent, Map.Entry<String, JsonNode> rootNodeEntry, ObjectMapper mapper,
        ScimPerson scimPerson, JsonGenerator jsonGenerator) throws Exception {

    jsonGenerator.writeFieldName(rootNodeEntry.getKey());

    if (rootNodeEntry.getValue() instanceof ObjectNode) {

        jsonGenerator.writeStartObject();
        processNodes(rootNodeEntry.getKey(), rootNodeEntry.getValue(), mapper, scimPerson, jsonGenerator); // Recursion
        jsonGenerator.writeEndObject();/*from  w  w  w .  j  a va 2 s. c om*/

    } else if (rootNodeEntry.getValue() instanceof ArrayNode) {

        ArrayNode arrayNode = (ArrayNode) rootNodeEntry.getValue();

        jsonGenerator.writeStartArray();

        if (rootNodeEntry.getKey().equalsIgnoreCase("schemas")) {

            for (int i = 0; i < arrayNode.size(); i++) {

                JsonNode arrayNodeElement = arrayNode.get(i);
                jsonGenerator.writeObject(arrayNodeElement);
            }

        } else {

            if (arrayNode.size() > 0) {

                for (int i = 0; i < arrayNode.size(); i++) {

                    JsonNode arrayNodeElement = arrayNode.get(i);

                    if (arrayNodeElement.isObject()) {

                        jsonGenerator.writeStartObject();
                        processNodes(rootNodeEntry.getKey(), arrayNodeElement, mapper, scimPerson,
                                jsonGenerator); // Recursion
                        jsonGenerator.writeEndObject();

                    } else {
                        jsonGenerator.writeObject(arrayNodeElement);
                    }
                }
            }
        }

        jsonGenerator.writeEndArray();

    } else {

        if (parent != null && parent.equalsIgnoreCase("meta")) {

            if (rootNodeEntry.getValue() instanceof LongNode
                    && (rootNodeEntry.getKey().equalsIgnoreCase("created")
                            || rootNodeEntry.getKey().equalsIgnoreCase("lastModified"))) {

                DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC(); // Date should be in UTC format

                // In millis convert to string date
                jsonGenerator.writeObject(
                        dateTimeFormatter.print(Long.valueOf(rootNodeEntry.getValue().asText()).longValue()));

            } else {
                jsonGenerator.writeObject(rootNodeEntry.getValue());
            }

        } else {
            jsonGenerator.writeObject(rootNodeEntry.getValue());
        }
    }
}