List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime
public DateTime parseDateTime(String text)
From source file:org.specrunner.converters.core.ConverterDateMidnightPatternArgs.java
License:Open Source License
@Override public Object convert(Object value, Object[] args) throws ConverterException { if (value == null) { return null; }/*ww w. ja va2s . c o m*/ if (value instanceof DateMidnight) { return value; } try { if (args.length < 1) { throw new ConverterException("Converter '" + getClass() + "' missing pattern argument information (i.e. arg0=\"dd/MM/yyyy\")."); } String pattern = String.valueOf(args[0]); synchronized (cache) { DateTimeFormatter formatter = cache.get(pattern); if (formatter == null) { formatter = DateTimeFormat.forPattern(pattern); cache.put(pattern, formatter); } TimeZone tz = getZone(); if (tz != null) { formatter = formatter.withZone(DateTimeZone.forTimeZone(tz)); } return formatter.parseDateTime(String.valueOf(value)).toDateMidnight(); } } catch (IllegalArgumentException e) { throw new ConverterException(e); } }
From source file:org.specrunner.converters.core.ConverterDateTimePatternArgs.java
License:Open Source License
@Override public Object convert(Object value, Object[] args) throws ConverterException { if (value == null) { return null; }//from w w w . j a v a2s. co m if (value instanceof DateTime) { return value; } try { if (args.length < 1) { throw new ConverterException("Converter '" + getClass() + "' missing pattern argument information (i.e. arg0=\"dd/MM/yyyy\")."); } String pattern = String.valueOf(args[0]); synchronized (cache) { DateTimeFormatter formatter = cache.get(pattern); if (formatter == null) { formatter = DateTimeFormat.forPattern(pattern); cache.put(pattern, formatter); } TimeZone tz = getZone(); if (tz != null) { formatter = formatter.withZone(DateTimeZone.forTimeZone(tz)); } return formatter.parseDateTime(String.valueOf(value)); } } catch (IllegalArgumentException e) { throw new ConverterException(e); } }
From source file:org.specrunner.converters.core.ConverterMutableDateTimePatternArgs.java
License:Open Source License
@Override public Object convert(Object value, Object[] args) throws ConverterException { if (value == null) { return null; }// w ww. j a v a2 s .c om if (value instanceof DateTime) { return value; } try { if (args.length < 1) { throw new ConverterException("Converter '" + getClass() + "' missing pattern argument information (i.e. arg0=\"dd/MM/yyyy\")."); } String pattern = String.valueOf(args[0]); synchronized (cache) { DateTimeFormatter formatter = cache.get(pattern); if (formatter == null) { formatter = DateTimeFormat.forPattern(pattern); cache.put(pattern, formatter); } TimeZone tz = getZone(); if (tz != null) { formatter = formatter.withZone(DateTimeZone.forTimeZone(tz)); } return formatter.parseDateTime(String.valueOf(value)).toMutableDateTime(); } } catch (IllegalArgumentException e) { throw new ConverterException(e); } }
From source file:org.specrunner.htmlunit.assertions.PluginCompareUtils.java
License:Open Source License
/** * Perform date comparisons.//from ww w .j a v a 2 s . c om * * @param compare * The plugin which hold format and tolerance information. * @param expected * The expected value. * @param received * The received value. * @param comparator * A comparator. * @param block * The block. * @param context * The context. * @param result * The result set. * @param page * The client page. * @return true, of equals considering tolerance, false, otherwise. * @throws PluginException * On comparison errors. */ public static boolean compareDate(PluginCompareDate compare, String expected, String received, IComparator comparator, IBlock block, IContext context, IResultSet result, SgmlPage page) throws PluginException { boolean res = true; DateTimeFormatter fmt = null; try { fmt = DateTimeFormat.forPattern(compare.getFormat()); } catch (Exception e) { if (UtilLog.LOG.isDebugEnabled()) { UtilLog.LOG.debug(e.getMessage(), e); } result.addResult(Failure.INSTANCE, block, new PluginException(e)); res = false; } if (fmt != null) { try { DateTime dtExpected = fmt.parseDateTime(expected); DateTime dtReceived = fmt.parseDateTime(received); if (comparator.match(dtExpected, dtReceived)) { result.addResult(Success.INSTANCE, block); } else { addError(expected, received, block, context, result, page); res = false; } } catch (Exception e) { if (UtilLog.LOG.isDebugEnabled()) { UtilLog.LOG.debug(e.getMessage(), e); } addError(expected, received, block, context, result, page); } } return res; }
From source file:org.specrunner.webdriver.assertions.PluginCompareUtils.java
License:Open Source License
/** * Perform date comparisons./*from www .java 2s . c om*/ * * @param compare * The plugin which hold format and tolerance information. * @param expected * The expected value. * @param received * The received value. * @param iComparator * @param block * The block. * @param context * The context. * @param result * The result set. * @param client * The web driver. * @return true, of equals considering tolerance, false, otherwise. * @throws PluginException * On comparison errors. */ public static boolean compareDate(PluginCompareDate compare, String expected, String received, IComparator comparator, IBlock block, IContext context, IResultSet result, WebDriver client) throws PluginException { boolean res = true; DateTimeFormatter fmt = null; try { fmt = DateTimeFormat.forPattern(compare.getFormat()); } catch (Exception e) { if (UtilLog.LOG.isDebugEnabled()) { UtilLog.LOG.debug(e.getMessage(), e); } result.addResult(Failure.INSTANCE, block, new PluginException(e)); res = false; } if (fmt != null) { try { DateTime dtExpected = fmt.parseDateTime(expected); DateTime dtReceived = fmt.parseDateTime(received); if (comparator.match(dtExpected, dtReceived)) { result.addResult(Success.INSTANCE, block); } else { addError(expected, received, block, context, result, client); res = false; } } catch (Exception e) { if (UtilLog.LOG.isDebugEnabled()) { UtilLog.LOG.debug(e.getMessage(), e); } addError(expected, received, block, context, result, client); } } return res; }
From source file:org.sweble.wom3.impl.Toolbox.java
License:Open Source License
public static DateTime stringToDateTime(String datetime) { DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser(); return parser.parseDateTime(datetime); }
From source file:org.talend.components.netsuite.client.model.search.SearchDateFieldAdapter.java
License:Open Source License
protected XMLGregorianCalendar convertDateTime(String input) { String valueToParse = input;// w w w . ja va 2s. c o m String dateTimeFormatPattern = dateFormatPattern + " " + timeFormatPattern; if (input.length() == dateFormatPattern.length()) { dateTimeFormatPattern = dateFormatPattern; } else if (input.length() == timeFormatPattern.length()) { DateTime dateTime = new DateTime(); DateTimeFormatter dateFormatter = DateTimeFormat.forPattern(dateFormatPattern); valueToParse = dateFormatter.print(dateTime) + " " + input; } DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(dateTimeFormatPattern); DateTime dateTime; try { dateTime = dateTimeFormatter.parseDateTime(valueToParse); } catch (IllegalArgumentException e) { throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.searchDateField.invalidDateTimeFormat", valueToParse)); } XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar(); xts.setYear(dateTime.getYear()); xts.setMonth(dateTime.getMonthOfYear()); xts.setDay(dateTime.getDayOfMonth()); xts.setHour(dateTime.getHourOfDay()); xts.setMinute(dateTime.getMinuteOfHour()); xts.setSecond(dateTime.getSecondOfMinute()); xts.setMillisecond(dateTime.getMillisOfSecond()); xts.setTimezone(dateTime.getZone().toTimeZone().getOffset(dateTime.getMillis()) / 60000); return xts; }
From source file:org.tanrabad.survey.service.ApiSyncInfoPreference.java
License:Apache License
public void backLastUpdateTimeToYesterday() { DateTimeFormatter rfc1123Formatter = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'"); DateTime dateTime = rfc1123Formatter.parseDateTime(get()); save(dateTime.minusDays(1).toString()); }
From source file:org.trakhound.www.trakhound.api.users.UserConfiguration.java
License:Open Source License
public static UserConfiguration get(JSONObject obj) { try {/*from w w w . ja v a 2s .c o m*/ UserConfiguration result = new UserConfiguration(); result.id = obj.getString("id"); result.username = obj.getString("username"); result.firstName = obj.optString("first_name"); result.lastName = obj.optString("last_name"); result.company = obj.optString("company"); result.email = obj.optString("email"); result.phone = obj.optString("phone"); result.address1 = obj.optString("address1"); result.address2 = obj.optString("address2"); result.city = obj.optString("city"); result.state = obj.optString("state"); result.country = obj.optString("country"); result.zipCode = obj.optString("zipcode"); result.imageUrl = obj.optString("imageUrl"); String lastLogin = obj.optString("last_login"); if (lastLogin != null && !lastLogin.equals("null")) { DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); result.lastLogin = formatter.parseDateTime(lastLogin); } result.type = obj.optInt("type"); result.rememberToken = obj.optString("token"); result.sessionToken = obj.optString("session_token"); return result; } catch (JSONException e) { e.printStackTrace(); } return null; }
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Converts calendar day at midnight in ISO no millis format to an * org.joda.time.DateTime Format employs Market time zone. * * @param day/*ww w . j a v a 2 s.c o m*/ * an ISO8601 formatted String (non millis) * @return a DateTime instance at midnight in "Market time" */ public static DateTime isoDayToDateTime(final String day) { final DateTimeFormatter fmt = isoFormat.withZone(marketTimeZone); final DateTime parsed = fmt.parseDateTime(day); // set to start of day final DateTime result = parsed.withMillisOfDay(0); return result; }