Search in sources :

Example 91 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project opennms by OpenNMS.

the class HttpCollectionHandler method getTimeStamp.

/**
 * Gets the time stamp.
 *
 * @param document the JSoup document
 * @param group the group
 * @return the time stamp
 */
protected Date getTimeStamp(Document doc, XmlGroup group) {
    if (group.getTimestampXpath() == null) {
        return null;
    }
    String pattern = group.getTimestampFormat() == null ? "yyyy-MM-dd HH:mm:ss" : group.getTimestampFormat();
    LOG.debug("getTimeStamp: retrieving custom timestamp to be used when updating RRDs using selector {} and pattern {}", group.getTimestampXpath(), pattern);
    Elements el = doc.select(group.getTimestampXpath());
    if (el == null) {
        return null;
    }
    String value = el.html();
    Date date = null;
    try {
        DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern);
        DateTime dateTime = dtf.parseDateTime(value);
        date = dateTime.toDate();
    } catch (Exception e) {
        LOG.warn("getTimeStamp: can't convert custom timetime {} using pattern {}", value, pattern);
    }
    return date;
}
Also used : Elements(org.jsoup.select.Elements) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date) DateTime(org.joda.time.DateTime)

Example 92 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project opennms by OpenNMS.

the class AbstractJsonCollectionHandler method getTimeStamp.

/**
 * Gets the time stamp.
 *
 * @param context the JXPath context
 * @param group the group
 * @return the time stamp
 */
protected Date getTimeStamp(JXPathContext context, XmlGroup group) {
    if (group.getTimestampXpath() == null) {
        return null;
    }
    String pattern = group.getTimestampFormat() == null ? "yyyy-MM-dd HH:mm:ss" : group.getTimestampFormat();
    LOG.debug("getTimeStamp: retrieving custom timestamp to be used when updating RRDs using XPATH {} and pattern {}", group.getTimestampXpath(), pattern);
    Date date = null;
    String value = (String) context.getValue(group.getTimestampXpath());
    try {
        DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern);
        DateTime dateTime = dtf.parseDateTime(value);
        date = dateTime.toDate();
    } catch (Exception e) {
        LOG.warn("getTimeStamp: can't convert custom timestamp {} using pattern {}", value, pattern);
    }
    return date;
}
Also used : DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date) DateTime(org.joda.time.DateTime) JXPathException(org.apache.commons.jxpath.JXPathException) ParseException(java.text.ParseException)

Example 93 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project opennms by OpenNMS.

the class Sftp3gppUrlConnection method getTimeStampFromFile.

/**
 * Gets the time stamp from 3GPP XML file name.
 *
 * @param fileName the 3GPP XML file name
 * @return the time stamp from file
 */
public long getTimeStampFromFile(String fileName) {
    Pattern p = Pattern.compile("\\w(\\d+)\\.(\\d+)-(\\d+)-(\\d+)-(\\d+)_.+");
    Matcher m = p.matcher(fileName);
    if (m.find()) {
        // Using end date as a reference
        String value = m.group(1) + '-' + m.group(4);
        try {
            DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyyMMdd-HHmm");
            DateTime dateTime = dtf.parseDateTime(value);
            return dateTime.getMillis();
        } catch (Exception e) {
            LOG.warn("getTimeStampFromFile: malformed 3GPP file {}, because {}", fileName, e.getMessage());
            return 0;
        }
    }
    return 0;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) SftpException(com.jcraft.jsch.SftpException)

Example 94 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project amos-ss17-alexa by c-i-ber.

the class ContactTransferService method performTransfer.

/**
 * Performs the transfer.
 */
private SpeechletResponse performTransfer(Intent intent, Session session) {
    Object contactsFoundObj = SESSION_STORAGE.getObject(session.getSessionId(), SESSION_PREFIX + ".contactsFound");
    if (contactsFoundObj == null || !(contactsFoundObj instanceof List)) {
        return getResponse(CONTACT_TRANSFER_CARD, "Da ist etwas schiefgegangen. Tut mir Leid.");
    }
    Object choiceObj = session.getAttribute(SESSION_PREFIX + ".choice");
    if (choiceObj == null || !(choiceObj instanceof Integer)) {
        return getResponse(CONTACT_TRANSFER_CARD, "Da ist etwas schiefgegangen. Tut mir Leid.");
    }
    Object amountObj = session.getAttribute(SESSION_PREFIX + ".amount");
    if (amountObj == null || !(amountObj instanceof Double || amountObj instanceof Integer)) {
        return getResponse(CONTACT_TRANSFER_CARD, "Da ist etwas schiefgegangen. Tut mir Leid.");
    }
    Contact contact = ((List<Contact>) contactsFoundObj).get((int) choiceObj - 1);
    double amount;
    if (amountObj instanceof Double) {
        amount = (double) amountObj;
    } else {
        amount = (int) amountObj;
    }
    DateTimeFormatter apiTransactionFmt = DateTimeFormat.forPattern("yyyy-MM-dd");
    String valueDate = DateTime.now().toString(apiTransactionFmt);
    Transaction transaction = TransactionAPI.createTransaction((int) amount, /*"DE50100000000000000001"*/
    AmosAlexaSpeechlet.ACCOUNT_IBAN, contact.getIban(), valueDate, "Beschreibung", "Hans", null);
    Account account = AccountAPI.getAccount(ACCOUNT_NUMBER);
    String balanceAfterTransaction = String.valueOf(account.getBalance());
    // save transaction id to save in db
    session.setAttribute(TRANSACTION_ID_ATTRIBUTE, transaction.getTransactionId().toString());
    // add category ask to success response
    String categoryAsk = "Zu welcher Kategorie soll die Transaktion hinzugefügt werden. Sag zum Beispiel Kategorie " + Category.categoryListText();
    return getAskResponse(CONTACT_TRANSFER_CARD, "Erfolgreich. " + amount + " Euro wurden an " + contact.getName() + " überwiesen. Dein neuer Kontostand beträgt " + balanceAfterTransaction + " Euro. " + categoryAsk);
}
Also used : Account(model.banking.Account) Transaction(model.banking.Transaction) LinkedList(java.util.LinkedList) List(java.util.List) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Contact(model.db.Contact)

Example 95 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project joda-time by JodaOrg.

the class AbstractInterval method toString.

/**
     * Output a string in ISO8601 interval format.
     * <p>
     * From version 2.1, the string includes the time zone offset.
     *
     * @return re-parsable string (in the default zone)
     */
public String toString() {
    DateTimeFormatter printer = ISODateTimeFormat.dateTime();
    printer = printer.withChronology(getChronology());
    StringBuffer buf = new StringBuffer(48);
    printer.printTo(buf, getStartMillis());
    buf.append('/');
    printer.printTo(buf, getEndMillis());
    return buf.toString();
}
Also used : DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Aggregations

DateTimeFormatter (org.joda.time.format.DateTimeFormatter)209 DateTime (org.joda.time.DateTime)95 Date (java.util.Date)40 Test (org.junit.Test)25 DateTimeZone (org.joda.time.DateTimeZone)19 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)16 SolrInputDocument (org.apache.solr.common.SolrInputDocument)12 IndexSchema (org.apache.solr.schema.IndexSchema)12 DateTimeFormatterBuilder (org.joda.time.format.DateTimeFormatterBuilder)12 CswSourceConfiguration (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration)10 IOException (java.io.IOException)9 Calendar (java.util.Calendar)8 Map (java.util.Map)8 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)7 FormatDateTimeFormatter (org.elasticsearch.common.joda.FormatDateTimeFormatter)7 Test (org.testng.annotations.Test)7 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)6 FilterType (net.opengis.filter.v_1_1_0.FilterType)6 Deployment (org.activiti.engine.test.Deployment)6