List of usage examples for org.joda.time DateTime parse
public static DateTime parse(String str, DateTimeFormatter formatter)
From source file:org.geosdi.geoplatform.support.primitive.string.responsibility.TemporalParserFromStringHandler.java
License:Open Source License
/** * @param value/*from ww w . j a va2 s .c om*/ * @return {@link Boolean} */ @Override protected Boolean canParseValue(String value) { Locale locale = temporalPatternImplementor.getLocale(); for (String patter : temporalPatternImplementor.getPatterns()) { try { DateTime dateTime = DateTime.parse(value, DateTimeFormat.forPattern(patter).withLocale(locale)); logger.debug("##########################PRIMITIVE_PARSER : {} parse value {} as DateTime : {}.\n", getParserType(), value, dateTime); return TRUE; } catch (Exception ex) { logger.trace("######################ERROR FOR PARSER : {} , trying to parse Value : {} , " + "with Pattern :{} and Locale : {}", getParserType(), value, patter, locale); } } return FALSE; }
From source file:org.graylog2.indexer.searches.timeranges.AbsoluteRange.java
License:Open Source License
public AbsoluteRange(String from, String to) throws InvalidRangeParametersException { if (from == null || from.isEmpty() || to == null || to.isEmpty()) { throw new InvalidRangeParametersException(); }//from w w w .jav a 2 s . c o m try { if (from.contains("T")) { this.from = DateTime.parse(from, ISODateTimeFormat.dateTime()); } else { this.from = DateTime.parse(from, Tools.timeFormatterWithOptionalMilliseconds()); } if (to.contains("T")) { this.to = DateTime.parse(to, ISODateTimeFormat.dateTime()); } else { this.to = DateTime.parse(to, Tools.timeFormatterWithOptionalMilliseconds()); } } catch (IllegalArgumentException e) { throw new InvalidRangeParametersException(); } }
From source file:org.graylog2.inputs.converters.DateConverter.java
License:Open Source License
@Override public Object convert(String value) { if (value == null || value.isEmpty()) { return null; }/*from w ww. j ava2 s . co m*/ final DateTime localNow = Tools.iso8601(); LOG.debug("Trying to parse date <{}> with pattern <{}>.", value, dateFormat); return DateTime.parse(value, DateTimeFormat.forPattern(dateFormat).withDefaultYear(localNow.getYear())); }
From source file:org.graylog2.jackson.MongoJodaDateTimeDeserializer.java
License:Open Source License
@Override public DateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { switch (jsonParser.currentToken()) { case VALUE_EMBEDDED_OBJECT: final Object embeddedObject = jsonParser.getEmbeddedObject(); if (embeddedObject instanceof Date) { final Date date = (Date) embeddedObject; return new DateTime(date, DateTimeZone.UTC); } else {// w ww . j a v a 2 s . co m throw new IllegalStateException("Unsupported token: " + jsonParser.currentToken()); } case VALUE_STRING: final String text = jsonParser.getText(); return DateTime.parse(text, FORMATTER).withZone(DateTimeZone.UTC); default: throw new IllegalStateException("Unsupported token: " + jsonParser.currentToken()); } }
From source file:org.graylog2.plugin.Tools.java
License:Open Source License
/** * Try to parse a date in ES_DATE_FORMAT format considering it is in UTC and convert it to an ISO8601 date. * If an error is encountered in the process, it will return the original string. *///from w ww . j ava2 s.c o m public static String elasticSearchTimeFormatToISO8601(String time) { try { DateTime dt = DateTime.parse(time, ES_DATE_FORMAT_FORMATTER); return getISO8601String(dt); } catch (IllegalArgumentException e) { return time; } }
From source file:org.jasig.cas.adaptors.ldap.LdapPasswordPolicyEnforcer.java
License:Apache License
/** * Parses and formats the retrieved date value from Ldap. * @param ldapResult/*from www . j ava2 s. c om*/ * @return newly constructed date object whose value was passed */ private DateTime formatDateByPattern(final String ldapResult) { final DateTimeFormatter fmt = DateTimeFormat.forPattern(this.dateFormat); final DateTime date = new DateTime(DateTime.parse(ldapResult, fmt), DEFAULT_TIME_ZONE); return date; }
From source file:org.jasig.cas.adaptors.ldap.lppe.PasswordPolicyConfiguration.java
License:Apache License
/** * Construct the static password expiration date based on the formatter defined. * @return the static password expiration date. * @see #setDateTimeFormatter(DateTimeFormatter) * @see #setStaticPasswordExpirationDate(String) *///from ww w . j a v a2 s. c o m public DateTime getStaticPasswordExpirationDate() { if (staticPasswordExpirationDate != null) { return DateTime.parse(this.staticPasswordExpirationDate, this.datetimeFormatter); } return null; }
From source file:org.jasig.cas.adaptors.ldap.lppe.SimpleDateFormatLdapDateConverter.java
License:Apache License
@Override public DateTime convert(final String dateValue) { final DateTimeFormatter fmt = DateTimeFormat.forPattern(this.passwordExpirationDateFormat); return new DateTime(DateTime.parse(dateValue, fmt), this.getTimeZone()); }
From source file:org.jasig.portlet.blackboardvcportlet.mvc.admin.ViewAdminServerConfigController.java
License:Apache License
@ResourceMapping("datafixRecording") public String datafixRecording(PortletRequest request, ResourceResponse response, ModelMap model) { String startDate = (String) request.getParameter("startDate"); String endDate = (String) request.getParameter("endDate"); DateTime sd = DateTime.parse(startDate, DateTimeFormat.forPattern("MM-dd-YYYY")); DateTime ed = DateTime.parse(endDate, DateTimeFormat.forPattern("MM-dd-YYYY")); if (sd != null && ed != null) { int errd = recordingService.datafixRecordings(sd, ed); if (errd > 0) logger.warn("During datafixRecording, " + errd + " failed to insert"); } else {/*w w w. j ava 2 s.c o m*/ response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "400"); response.setProperty("X-Status-Reason", "Validation failed"); } return "json"; }
From source file:org.jasig.portlet.cms.controller.EditPostController.java
License:Apache License
private void savePost(final ActionRequest request, final BindingResult result, Post post, boolean postIsScheduled, String scheduledDate, boolean removeExistingPost) throws PortletRequestBindingException, JcrRepositoryException { final PortletPreferencesWrapper pref = new PortletPreferencesWrapper(request); final Calendar cldr = Calendar.getInstance(request.getLocale()); final DateTimeZone zone = DateTimeZone.forTimeZone(cldr.getTimeZone()); final DateTime today = new DateTime(zone); final DateTimeFormatter fmt = DateTimeFormat.forPattern(PortletPreferencesWrapper.DEFAULT_POST_DATE_FORMAT); post.setLastModifiedDate(today.toString(fmt)); post.setLanguage(request.getLocale().getLanguage()); if (postIsScheduled) { if (StringUtils.isBlank(scheduledDate)) result.rejectValue("scheduledDate", "invalid.scheduled.post.publish.date"); else {//from w w w. jav a 2 s. com logDebug("Post is scheduled to be published on " + scheduledDate); final DateTime dt = DateTime.parse(scheduledDate, fmt); post.setScheduledDate(dt.toString(fmt)); if (removeExistingPost) { if (getRepositoryDao().exists(post.getPath())) { logDebug("Preparing scheduled post. Removing existing post at " + post.getPath()); getRepositoryDao().removePost(post.getPath()); } } getRepositoryDao().schedulePost(post, pref.getPortletRepositoryRoot()); ensureRepositoryRootIsScheduled(pref); } } else { post = preparePost(post, request); getRepositoryDao().setPost(post); } }