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:org.opensaml.soap.wssecurity.impl.AttributedDateTimeImpl.java

License:Open Source License

/**
 * Constructor.//from w  w  w . j  a va2 s  . c  o  m
 * 
 * @param namespaceURI namespace of the element
 * @param elementLocalName name of the element
 * @param namespacePrefix namespace prefix of the element
 */
public AttributedDateTimeImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
    super(namespaceURI, elementLocalName, namespacePrefix);
    formatter = ISODateTimeFormat.dateTime().withChronology(ISOChronology.getInstanceUTC());
    unknownAttributes = new AttributeMap(this);
}

From source file:org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.DlmsHelperService.java

License:Open Source License

public void validateBufferedDateTime(final DateTime bufferedDateTime, final CosemDateTimeDto cosemDateTime,
        final DateTime beginDateTime, final DateTime endDateTime) throws BufferedDateTimeValidationException {

    if (bufferedDateTime == null) {
        final DateTimeFormatter dtf = ISODateTimeFormat.dateTime();
        throw new BufferedDateTimeValidationException("Not using an object from capture buffer (clock="
                + cosemDateTime/* w w w . ja  v  a2s . c o  m*/
                + "), because the date does not match the given period, since it is not fully specified: ["
                + dtf.print(beginDateTime) + " .. " + dtf.print(endDateTime) + "].");
    }
    if (bufferedDateTime.isBefore(beginDateTime) || bufferedDateTime.isAfter(endDateTime)) {
        final DateTimeFormatter dtf = ISODateTimeFormat.dateTime();
        throw new BufferedDateTimeValidationException("Not using an object from capture buffer (clock="
                + dtf.print(bufferedDateTime) + "), because the date does not match the given period: ["
                + dtf.print(beginDateTime) + " .. " + dtf.print(endDateTime) + "].");
    }
}

From source file:org.opentestsystem.delivery.testreg.domain.JodaDateTimeXStreamConverter.java

License:Open Source License

public JodaDateTimeXStreamConverter(String format) {
    switch (format) {
    case "yyyy-MM-dd":
        dateTimeFormatter = ISODateTimeFormat.yearMonthDay();
        break;/*from w  w  w.jav  a  2 s.  c  o  m*/
    default:
        dateTimeFormatter = ISODateTimeFormat.dateTime();
        break;
    }
}

From source file:org.openvpms.booking.impl.DateHelper.java

License:Open Source License

/**
 * Helper to convert a string query parameter to an ISO 8601 date.
 *
 * @param name  the parameter name/*w w w  .j a  v a  2s  . co m*/
 * @param value the parameter value
 * @return the corresponding date
 * @throws BadRequestException if the value is invalid
 */
static Date getDate(String name, String value) {
    if (value == null) {
        throw new BadRequestException("Missing '" + name + "' parameter");
    }
    DateTime result;
    try {
        result = ISODateTimeFormat.dateTimeNoMillis().parseDateTime(value);
    } catch (IllegalArgumentException e) {
        try {
            result = ISODateTimeFormat.dateTime().parseDateTime(value);
        } catch (IllegalArgumentException nested) {
            throw new BadRequestException("Parameter '" + name + "' is not a valid ISO date/time: " + value);
        }
    }
    return result.toDate();
}

From source file:org.orbeon.oxf.processor.zip.UnzipProcessor.java

License:Open Source License

@Override
public ProcessorOutput createOutput(String name) {
    final ProcessorOutput output = new ProcessorOutputImpl(UnzipProcessor.this, name) {

        public void readImpl(PipelineContext context, XMLReceiver xmlReceiver) {
            try {
                // Read input in a temporary file
                final File temporaryZipFile;
                {//from   w  ww . jav a2  s .  c  om
                    final FileItem fileItem = NetUtils.prepareFileItem(NetUtils.REQUEST_SCOPE);
                    final OutputStream fileOutputStream = fileItem.getOutputStream();
                    readInputAsSAX(context, getInputByName(INPUT_DATA), new BinaryTextXMLReceiver(null,
                            fileOutputStream, true, false, null, false, false, null, false));
                    temporaryZipFile = ((DiskFileItem) fileItem).getStoreLocation();
                }

                xmlReceiver.startDocument();
                // <files>
                xmlReceiver.startElement("", "files", "files", XMLUtils.EMPTY_ATTRIBUTES);
                ZipFile zipFile = new ZipFile(temporaryZipFile);
                for (Enumeration entries = zipFile.entries(); entries.hasMoreElements();) {
                    // Go through each entry in the zip file
                    ZipEntry zipEntry = (ZipEntry) entries.nextElement();
                    // Get file name
                    String fileName = zipEntry.getName();
                    long fileSize = zipEntry.getSize();
                    String fileTime = ISODateTimeFormat.dateTime().print(zipEntry.getTime());

                    InputStream entryInputStream = zipFile.getInputStream(zipEntry);
                    String uri = NetUtils.inputStreamToAnyURI(entryInputStream, NetUtils.REQUEST_SCOPE);
                    // <file name="filename.ext">uri</file>
                    AttributesImpl fileAttributes = new AttributesImpl();
                    fileAttributes.addAttribute("", "name", "name", "CDATA", fileName);
                    fileAttributes.addAttribute("", "size", "size", "CDATA", Long.toString(fileSize));
                    fileAttributes.addAttribute("", "dateTime", "dateTime", "CDATA", fileTime);
                    xmlReceiver.startElement("", "file", "file", fileAttributes);
                    xmlReceiver.characters(uri.toCharArray(), 0, uri.length());
                    // </file>
                    xmlReceiver.endElement("", "file", "file");
                }
                // </files>
                xmlReceiver.endElement("", "files", "files");
                xmlReceiver.endDocument();

            } catch (IOException e) {
                throw new OXFException(e);
            } catch (SAXException e) {
                throw new OXFException(e);
            }
        }

        // We don't do any caching here since the file we produce are temporary. So we don't want a processor
        // downstream to keep a reference to a document that contains temporary URI that have since been deleted.

    };
    addOutput(name, output);
    return output;
}

From source file:org.osgp.adapter.protocol.dlms.domain.commands.GetPeriodicMeterReadsCommandExecutor.java

License:Open Source License

private void processNextPeriodicMeterReads(final PeriodType periodType, final DateTime beginDateTime,
        final DateTime endDateTime, final List<PeriodicMeterReads> periodicMeterReads,
        final List<DataObject> bufferedObjects, final List<GetResult> results) throws ProtocolAdapterException {

    final CosemDateTime cosemDateTime = this.dlmsHelperService
            .readDateTime(bufferedObjects.get(BUFFER_INDEX_CLOCK), "Clock from " + periodType + " buffer");
    final DateTime bufferedDateTime = cosemDateTime == null ? null : cosemDateTime.asDateTime();
    if (bufferedDateTime == null) {
        final DateTimeFormatter dtf = ISODateTimeFormat.dateTime();
        LOGGER.warn("Not using an object from capture buffer (clock=" + cosemDateTime
                + "), because the date does not match the given period, since it is not fully specified: ["
                + dtf.print(beginDateTime) + " .. " + dtf.print(endDateTime) + "].");
        return;/*from   www .j  a va2s . c  o  m*/
    }
    if (bufferedDateTime.isBefore(beginDateTime) || bufferedDateTime.isAfter(endDateTime)) {
        final DateTimeFormatter dtf = ISODateTimeFormat.dateTime();
        LOGGER.warn("Not using an object from capture buffer (clock=" + dtf.print(bufferedDateTime)
                + "), because the date does not match the given period: [" + dtf.print(beginDateTime) + " .. "
                + dtf.print(endDateTime) + "].");
        return;
    }

    LOGGER.debug("Processing profile (" + periodType + ") objects captured at: {}", cosemDateTime);

    switch (periodType) {
    case INTERVAL:
        this.processNextPeriodicMeterReadsForInterval(periodicMeterReads, bufferedObjects, bufferedDateTime,
                results);
        break;
    case DAILY:
        this.processNextPeriodicMeterReadsForDaily(periodicMeterReads, bufferedObjects, bufferedDateTime,
                results);
        break;
    case MONTHLY:
        this.processNextPeriodicMeterReadsForMonthly(periodicMeterReads, bufferedObjects, bufferedDateTime,
                results);
        break;
    default:
        throw new AssertionError("Unknown PeriodType: " + periodType);
    }
}

From source file:org.osgp.adapter.protocol.dlms.domain.commands.GetPeriodicMeterReadsGasCommandExecutor.java

License:Open Source License

private void processNextPeriodicMeterReads(final PeriodType periodType, final DateTime beginDateTime,
        final DateTime endDateTime, final List<PeriodicMeterReadsGas> periodicMeterReads,
        final List<DataObject> bufferedObjects, final Channel channel, final boolean isSelectiveAccessSupported,
        final List<GetResult> results) throws ProtocolAdapterException {

    final CosemDateTime cosemDateTime = this.dlmsHelperService
            .readDateTime(bufferedObjects.get(BUFFER_INDEX_CLOCK), "Clock from " + periodType + " buffer gas");
    final DateTime bufferedDateTime = cosemDateTime == null ? null : cosemDateTime.asDateTime();
    if (bufferedDateTime == null) {
        final DateTimeFormatter dtf = ISODateTimeFormat.dateTime();
        LOGGER.warn("Not using an object from capture buffer (clock=" + cosemDateTime
                + "), because the date does not match the given period, since it is not fully specified: ["
                + dtf.print(beginDateTime) + " .. " + dtf.print(endDateTime) + "].");
        return;// w w w  .  ja va 2  s .  c o  m
    }
    if (bufferedDateTime.isBefore(beginDateTime) || bufferedDateTime.isAfter(endDateTime)) {
        final DateTimeFormatter dtf = ISODateTimeFormat.dateTime();
        LOGGER.warn("Not using an object from capture buffer (clock=" + dtf.print(bufferedDateTime)
                + "), because the date does not match the given period: [" + dtf.print(beginDateTime) + " .. "
                + dtf.print(endDateTime) + "].");
        return;
    }

    LOGGER.debug("Processing profile (" + periodType + ") objects captured at: {}", cosemDateTime);

    switch (periodType) {
    case INTERVAL:
        this.processNextPeriodicMeterReadsForInterval(periodicMeterReads, bufferedObjects, bufferedDateTime,
                results);
        break;
    case DAILY:
        this.processNextPeriodicMeterReadsForDaily(periodicMeterReads, bufferedObjects, bufferedDateTime,
                channel, isSelectiveAccessSupported, results);
        break;
    case MONTHLY:
        this.processNextPeriodicMeterReadsForMonthly(periodicMeterReads, bufferedObjects, bufferedDateTime,
                channel, isSelectiveAccessSupported, results);
        break;
    default:
        throw new AssertionError("Unknown PeriodType: " + periodType);
    }
}

From source file:org.osiam.client.AbstractIntegrationTestBase.java

License:Open Source License

protected String dateAsString(int year, int month, int date, int hourOfDay, int minute, int second,
        int millisecond) {
    Date completeDate = createDate(year, month, date, hourOfDay, minute, second, millisecond);
    return ISODateTimeFormat.dateTime().withZoneUTC().print(completeDate.getTime());
}

From source file:org.peaceful.banana.git.UserCommitService.java

License:Open Source License

public PageIterator<RepositoryCommit> pageCommits(IRepositoryIdProvider repository, String author, Date since,
        Date until, int size) {
    String id = getId(repository);
    StringBuilder uri = new StringBuilder(SEGMENT_REPOS);
    uri.append('/').append(id);
    uri.append(SEGMENT_COMMITS);/*from  w  ww  .j a v a  2s. c o m*/
    PagedRequest<RepositoryCommit> request = createPagedRequest(PAGE_FIRST, size);
    request.setUri(uri);
    request.setType(new TypeToken<List<RepositoryCommit>>() {
    }.getType());

    if (since != null || until != null || author != null) {
        Map<String, String> params = new HashMap<String, String>();
        DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
        if (since != null) {
            params.put("since", formatter.print(since.getTime())); //$NON-NLS-1$
        }
        if (until != null) {
            params.put("until", formatter.print(until.getTime())); //$NON-NLS-1$
        }
        if (author != null)
            params.put("author", author);
        request.setParams(params);
    }

    return createPageIterator(request);
}

From source file:org.phenotips.data.internal.controller.MetaDataController.java

License:Open Source License

@Override
public PatientData<String> load(Patient patient) {
    try {//from   w  w w .  j a  v a 2 s .c o m
        XWikiDocument doc = (XWikiDocument) this.documentAccessBridge.getDocument(patient.getDocument());

        Map<String, String> result = new LinkedHashMap<String, String>();

        DateTimeFormatter dateFormatter = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC);

        result.put(DOCUMENT_NAME, doc.getDocumentReference().getName());

        result.put(CREATION_DATE, dateFormatter.print(new DateTime(doc.getCreationDate())));

        result.put(AUTHOR,
                (doc.getAuthorReference() != null) ? doc.getAuthorReference().getName() : UNKNOWN_USER);

        result.put(DATE, dateFormatter.print(new DateTime(doc.getDate())));

        return new DictionaryPatientData<>(getName(), result);

    } catch (Exception e) {
        this.logger.error("Could not find requested document or some unforeseen"
                + " error has occurred during controller loading ", e.getMessage());
    }
    return null;
}