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;
}
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;
}
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;
}
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);
}
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();
}
Aggregations