List of usage examples for org.joda.time.format ISODateTimeFormat dateTimeParser
public static DateTimeFormatter dateTimeParser()
From source file:com.activecq.api.utils.TypeUtil.java
License:Apache License
public static <T> T toObjectType(String data, Class<T> klass) { if (Double.class.equals(klass)) { try {/*from w ww . j av a 2 s .c o m*/ return klass.cast(Double.parseDouble(data)); } catch (NumberFormatException ex) { return null; } } else if (Long.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (StringUtils.equalsIgnoreCase("true", data)) { return klass.cast(Boolean.TRUE); } else if (StringUtils.equalsIgnoreCase("false", data)) { return klass.cast(Boolean.FALSE); } else if (JSON_DATE.matcher(data).matches()) { return klass.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(data).toDate()); } else { return klass.cast(data); } }
From source file:com.adobe.acs.commons.util.TypeUtil.java
License:Apache License
/** * Converts a limited set of String representations to their corresponding Objects * <p/>//ww w .j a va 2 s . c om * Supports * * Double * * Long * * Integer * * Boolean (true/false) * * Dates in string format of ISODateTimeFormat * <p/> * Else, null is returned. * * @param data the String representation of the data * @param klass the target class type of the provided data * @param <T> the target class type of the provided data * @return the derived object representing the data as specified by the klass */ public static <T> T toObjectType(String data, Class<T> klass) { if (Double.class.equals(klass)) { try { return klass.cast(Double.parseDouble(data)); } catch (NumberFormatException ex) { return null; } } else if (Long.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (Integer.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (StringUtils.equalsIgnoreCase("true", data)) { return klass.cast(Boolean.TRUE); } else if (StringUtils.equalsIgnoreCase("false", data)) { return klass.cast(Boolean.FALSE); } else if (JSON_DATE.matcher(data).matches()) { return klass.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(data).toDate()); } else { return klass.cast(data); } }
From source file:com.adobe.acs.tools.csv.impl.Column.java
License:Apache License
private <T> T toObjectType(String data, Class<T> klass) { data = StringUtils.trim(data);/*w ww . ja va2 s . c o m*/ if (Double.class.equals(klass)) { try { return klass.cast(Double.parseDouble(data)); } catch (NumberFormatException ex) { return null; } } else if (Long.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (Integer.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (StringUtils.equalsIgnoreCase("true", data)) { return klass.cast(Boolean.TRUE); } else if (StringUtils.equalsIgnoreCase("false", data)) { return klass.cast(Boolean.FALSE); } else if ((Date.class.equals(Date.class) || Calendar.class.equals(Calendar.class)) && ISO_DATE_PATTERN.matcher(data).matches()) { return klass.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(data).toCalendar(Locale.US)); } else { return klass.cast(data); } }
From source file:com.adobe.acs.tools.csv_asset_importer.impl.Column.java
License:Apache License
protected <T> T toObjectType(String data, Class<T> klass) { data = StringUtils.trim(data);/*from w w w . j ava 2 s. c o m*/ if (Double.class.equals(klass)) { try { return klass.cast(Double.parseDouble(data)); } catch (NumberFormatException ex) { return null; } } else if (Long.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (Integer.class.equals(klass)) { try { return klass.cast(Long.parseLong(data)); } catch (NumberFormatException ex) { return null; } } else if (StringUtils.equalsIgnoreCase("true", data) && Boolean.class.equals(klass)) { return klass.cast(Boolean.TRUE); } else if (StringUtils.equalsIgnoreCase("false", data) && Boolean.class.equals(klass)) { return klass.cast(Boolean.FALSE); } else if (Date.class.equals(klass) || Calendar.class.equals(klass)) { return klass.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(data).toCalendar(Locale.US)); } else { return klass.cast(data); } }
From source file:com.claresco.tinman.lrs.XapiStatement.java
License:Open Source License
/** * //from w ww.java2 s. com * Constructor * * Params: * * */ public XapiStatement(XapiActor theActor, XapiVerb theVerb, XapiObject theObject, XapiResult theResult, XapiContext theContext, String theTimeStamp) { this.myID = UUID.randomUUID(); this.myActor = theActor; this.myVerb = theVerb; this.myObject = theObject; this.myResult = theResult; this.myContext = theContext; this.myTimeStampAsString = theTimeStamp; DateTimeFormatter theFormatter = ISODateTimeFormat.dateTimeParser(); if (theTimeStamp != null) { myTimeStamp = theFormatter.parseDateTime(theTimeStamp); } else { myTimeStamp = null; } this.isVoiding = myVerb.isVoided(); }
From source file:com.claresco.tinman.servlet.XapiCredentials.java
License:Open Source License
/** * Constructor //from w ww . jav a 2 s . c om * * Params: * * */ public XapiCredentials(ArrayList<String> theScope, String theExpiry, boolean theHistorical, XapiPerson thePerson, ArrayList<String> theActivityIDs, String theRegistration, DateTime theReceivedTimestamp) throws XapiBadParamException { myScope = theScope; myHistorical = theHistorical; myPerson = thePerson; if (theRegistration != null) { myRegistration = UUID.fromString(theRegistration); } else { theRegistration = null; } myReceivedTimestamp = theReceivedTimestamp; DateTimeFormatter theFormatter = ISODateTimeFormat.dateTimeParser(); if (theExpiry != null) { myExpiry = theFormatter.parseDateTime(theExpiry); } else { // By default, 4 hours myExpiry = DateTime.now().plusHours(4); } for (String s : theActivityIDs) { myActivityIDs.add(new XapiIRI(s)); } populateAcceptedScope(); // Assign appropriate clearance based on its scope for (String scope : theScope) { if (!myAcceptedScope.contains(scope)) { throw new XapiBadParamException("Scope is not accepted"); } else { if (scope.equals("all")) { myReadStatementsClearance = true; myWriteStatementsClearance = true; myReadStateClearance = true; myWriteStateClearance = true; myDefineClearance = true; myReadProfileClearance = true; myWriteProfileClearance = true; myReadAnyoneStatementsClearance = true; } else if (scope.equals("all/read")) { myReadStatementsClearance = true; myReadAnyoneStatementsClearance = true; myReadStateClearance = true; myReadProfileClearance = true; } else if (scope.equals("profile")) { myReadProfileClearance = true; myWriteProfileClearance = true; } else if (scope.equals("state")) { myReadStateClearance = true; myWriteStateClearance = true; } else if (scope.equals("define")) { myDefineClearance = true; } else if (scope.equals("statements/read")) { myReadAnyoneStatementsClearance = true; myReadStatementsClearance = true; } else if (scope.equals("statements/read/mine")) { myReadStatementsClearance = true; } else if (scope.equals("statements/write")) { myWriteStatementsClearance = true; } } } }
From source file:com.claresco.tinman.sql.XapiStatementSQLReader.java
License:Open Source License
private ArrayList<Integer> executeConjQueryStatement(HashMap<String, String> paramMaps, HashMap<String, Integer> locationMaps, String conjQueryStatement) throws SQLException, XapiSQLOperationProblemException { PreparedStatement myConjQueryStatement = myConn.prepareStatement(conjQueryStatement); DateTimeFormatter theFormatter = ISODateTimeFormat.dateTimeParser(); for (String paramName : paramMaps.keySet()) { String paramValue = paramMaps.get(paramName); int locationIndex = locationMaps.get(paramName).intValue(); if (paramName.equals("statementId")) { myConjQueryStatement.setString(locationIndex, paramValue); } else if (paramName.equals("agent")) { myConjQueryStatement.setInt(locationIndex, Integer.parseInt(paramValue)); } else if (paramName.equals("verb")) { myConjQueryStatement.setString(locationIndex, paramValue); } else if (paramName.equals("activity")) { myConjQueryStatement.setString(locationIndex, paramValue); } else if (paramName.equals("since")) { try { DateTime myTimeStamp = theFormatter.parseDateTime(paramValue); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); myConjQueryStatement.setTimestamp(locationIndex, SQLUtility.getTimestamp(myTimeStamp), cal); } catch (IllegalArgumentException exc) { throw new XapiSQLOperationProblemException("Having trouble reading the timestamp"); }//from w ww . jav a 2 s . co m } else if (paramName.equals("until")) { try { DateTime myTimeStamp = theFormatter.parseDateTime(paramValue); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); myConjQueryStatement.setTimestamp(locationIndex, SQLUtility.getTimestamp(myTimeStamp), cal); } catch (IllegalArgumentException exc) { throw new XapiSQLOperationProblemException("Having trouble parsing the timestamp"); } } } myConjQueryStatement.setInt(locationMaps.get("isvoided").intValue(), 0); myResult = myConjQueryStatement.executeQuery(); ArrayList<Integer> arrayIDs = new ArrayList<Integer>(); while (myResult.next()) { arrayIDs.add(new Integer(myResult.getInt("statementid"))); } if (arrayIDs.isEmpty()) { return null; } return arrayIDs; }
From source file:com.dtstack.jlogstash.date.ISODateParser.java
License:Apache License
public ISODateParser(String timezone) { this.formatter = ISODateTimeFormat.dateTimeParser(); if (timezone != null) { this.formatter = this.formatter.withZone(DateTimeZone.forID(timezone)); } else {// w w w . j a v a 2s . c o m this.formatter = this.formatter.withOffsetParsed(); } }
From source file:com.esri.geoevent.clusterSimulator.simulator.DateTimeParser.java
License:Apache License
public static long parseTime(String timeString) { if (timeString == null) return 0; try {// w w w. j a v a 2 s. co m DateTimeFormatter formatter = ISODateTimeFormat.dateTimeParser().withZoneUTC(); return formatter.parseMillis(timeString); } catch (IllegalArgumentException e) { } try { return DateFormat.getDateInstance().parse(timeString).getTime(); } catch (ParseException | NumberFormatException e) { } try { DateTimeFormatter formatter = DateTimeFormat.forPattern("MM/dd/yy hh:mm:ss aa"); return formatter.parseMillis(timeString); } catch (IllegalArgumentException e) { } try { DateTimeFormatter formatter = DateTimeFormat.forPattern("MM/dd/yy HH:mm:ss"); return formatter.parseMillis(timeString); } catch (IllegalArgumentException e) { } return 0; }
From source file:com.ethercis.servicemanager.common.IsoDateJoda.java
License:Apache License
/** * Calculate the difference from the given time to now. * ISO 8601 states: Durations are represented by the format P[n]Y[n]M[n]DT[n]H[n]M[n]S * @param utc Given time, e.g. "1997-07-16T19:20:30.45+01:00" * @return The ISO 8601 Period like "P3Y6M4DT12H30M17S" *///ww w . j av a2s. c o m public static String getDifferenceToNow(String utc) { if (utc == null) return ""; utc = ReplaceVariable.replaceAll(utc, " ", "T"); DateTime now = new DateTime(); DateTimeFormatter f = ISODateTimeFormat.dateTimeParser(); DateTime other = f.parseDateTime(utc); Period period = new Period(other, now); // Period(ReadableInstant startInstant, ReadableInstant endInstant) return period.toString(); }