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

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

Introduction

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

Prototype

public static DateTimeFormatter dateTime() 

Source Link

Document

Returns a formatter that combines a full date and time, separated by a 'T' (yyyy-MM-dd'T'HH:mm:ss.SSSZZ).

Usage

From source file:uk.ac.soton.itinnovation.ecc.service.utils.Convert.java

License:Open Source License

public static EccGenericMeasurementSet eccMeasurementSetToEccGenericMeasurementSet(EccMeasurementSet ms) {
    if (ms == null) {
        return null;
    } else {// www .j a  va  2  s . c  o  m
        EccGenericMeasurementSet result = new EccGenericMeasurementSet();
        result.setType(ms.getType());
        result.setUnit(ms.getUnit());
        result.setTimestamp(ms.getTimestamp());
        ArrayList<EccGenericMeasurement> data = new ArrayList<EccGenericMeasurement>();

        for (EccMeasurement e : ms.getData()) {
            data.add(new EccGenericMeasurement(ISODateTimeFormat.dateTime().print(e.getTimestamp().getTime()),
                    e.getValue()));
        }

        result.setData(data);

        return result;
    }
}

From source file:uk.co.visalia.brightpearl.apiclient.client.adaptors.DateTimeAdaptor.java

License:Apache License

@Override
public void write(JsonWriter jsonWriter, DateTime dateTime) throws IOException {
    if (dateTime == null) {
        jsonWriter.nullValue();//from  www.j a v a2s .  c  o  m
        return;
    }
    jsonWriter.value(ISODateTimeFormat.dateTime().print(dateTime));
}

From source file:xc.mst.oai.Facade.java

License:Open Source License

/**
 * Returns response date element//w  ww.  j  av  a  2 s .  co m
 * 
 * @return response date element
 */
public String getResponseDate() {
    // Add the element with the timestamp of the response
    try {
        Element responseDate = new Element("responseDate");
        DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
        String formattedDate = fmt.print(new DateTime());
        responseDate.addContent(formattedDate);

        if (log.isDebugEnabled())
            log.debug("Setting the responseDate in the OAI response header to " + formattedDate);

        return XMLUtil.format.outputString(responseDate);
    } catch (Exception e) {
        log.error("An exception occurred setting the response date.", e);
        return null;
    }
}

From source file:yuan.flood.ses.SESConnector.java

License:Open Source License

private String[] splitObservations(String inputObservation) throws Exception {

    try {//from ww w .j a v a 2s.c om
        // Determining how many observations are contained in the observation collection
        Pattern countPattern = Pattern.compile("<swe:value>(.*?)</swe:value>");
        Matcher countMatcher = countPattern.matcher(inputObservation);
        String countString = null;
        if (countMatcher.find()) {
            countString = countMatcher.group(1).trim();
        }
        int observationCount = Integer.parseInt(countString);

        // This array will contain one observation string for each observation of the observation
        // collection
        String[] outputStrings;

        // If the observation collection contains only one value it can be directly returned
        if (observationCount == 1) {
            outputStrings = new String[] { inputObservation };
        }

        // If the observation collection contains more than one value it must be split
        else {

            // Extracting the values that are contained in the observation collection and creating a
            // StringTokenizer that allows to access the values
            Pattern valuesPattern = Pattern.compile("<swe:values>(.*?)</swe:values>");
            Matcher valuesMatcher = valuesPattern.matcher(inputObservation);
            String valuesString = null;
            if (valuesMatcher.find()) {
                valuesString = valuesMatcher.group(1).trim();
            }

            // Read the id of the observation collection
            Pattern idPattern = Pattern
                    .compile("ObservationCollection gml:id=\"(.*?)\"(.*?)xsi:schemaLocation=");
            Matcher idMatcher = idPattern.matcher(inputObservation);
            String idString = "";
            if (idMatcher.find()) {
                idString = idMatcher.group(1).trim();
            }

            StringTokenizer valuesTokenizer = new StringTokenizer(valuesString, ";");
            // If only the latest observation is wished, find youngest
            // observation.
            if (true) {
                DateTime youngest = new DateTime(0);
                String youngestValues = "";
                DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
                while (valuesTokenizer.hasMoreElements()) {
                    String valueString = (String) valuesTokenizer.nextElement();
                    DateTime time = fmt.parseDateTime(valueString.split(",")[0]);
                    if (time.isAfter(youngest.getMillis())) {
                        youngest = time;
                        youngestValues = valueString;
                    }
                }
                outputStrings = new String[] {
                        createSingleObservationString(inputObservation, youngestValues) };
            } else {
                outputStrings = new String[observationCount];

                for (int i = 0; i < observationCount; i++) {

                    // Add the extracted observation to an array containing
                    // all extracted observations
                    outputStrings[i] = createSingleObservationString(inputObservation,
                            valuesTokenizer.nextToken());
                }
            }

        }
        // Returning the extracted observations
        return outputStrings;
    }

    catch (Exception e) {
        throw e;
    }
}

From source file:z.splunk.system.SplunkSystemProducer.java

License:Apache License

@Override
public void send(String source, OutgoingMessageEnvelope envelope) {
    SplunkKey key = (SplunkKey) envelope.getKey();
    String message = (String) envelope.getMessage();

    StringBuilder builder = new StringBuilder();

    builder.append("SPLUNK-MESSAGE:");
    appendKeyValue(builder, SOURCETYPE, key.getSourceType());
    appendKeyValue(builder, SOURCE, key.getSource());
    appendKeyValue(builder, HOST, key.getHost());
    appendKeyValue(builder, TIMESTAMP, ISODateTimeFormat.dateTime().print(key.getTimestamp()));

    builder.append("\n");
    builder.append(message);//from   w  w  w .ja  va 2 s  .co  m
    builder.append("\n---\n");

    try {
        OutputStreamWriter writer = getWriter();
        writer.write(builder.toString());
        writer.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
}