List of usage examples for org.joda.time Instant parse
public static Instant parse(String str, DateTimeFormatter formatter)
From source file:com.fatboyindustrial.gsonjodatime.InstantConverter.java
License:Open Source License
@Override public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (json.getAsString() == null || json.getAsString().isEmpty()) { return null; }//from w w w . jav a2 s. c o m return Instant.parse(json.getAsString(), fmt); }
From source file:com.jbirdvegas.mgerrit.search.AgeSearch.java
License:Apache License
private void parseDate(String param) { try {//from w w w .ja v a 2 s .co m if (param.endsWith("Z")) { /* The string representation of an instant includes a Z at the end, but this is not * a valid format for the parser. */ String newParam = param.substring(0, param.length() - 1); mInstant = Instant.parse(newParam, ISODateTimeFormat.localDateOptionalTimeParser()); } else { mInstant = Instant.parse(param, ISODateTimeFormat.localDateOptionalTimeParser()); } mPeriod = null; } catch (IllegalArgumentException ignored) { mPeriod = toPeriod(param); mInstant = null; } }
From source file:it.d4nguard.rgrpg.util.dynacast.adapters.DateTimeAdapter.java
License:Open Source License
/** * {@inheritDoc}//from www . j av a 2 s. c om */ @Override public ReadableInstant adapt(String value) { // value is a string formatted as: "07/04/1987[dd/MM/yyyy]" String date = ""; DateTimeFormatter fmt; Triplet<String, String, String> tri = StringUtils.getBetween(value, '[', ']'); date = tri.getLeft(); if (tri.hasCenter()) fmt = DateTimeFormat.forPattern(tri.getCenter()); else fmt = ISODateTimeFormat.localDateOptionalTimeParser(); fmt = fmt.withLocale(Locale.getDefault()); if (getType().equals(DateTime.class)) return DateTime.parse(date, fmt); else if (getType().equals(DateMidnight.class)) return DateMidnight.parse(date, fmt); else if (getType().equals(Instant.class)) return Instant.parse(date, fmt); else if (getType().equals(MutableDateTime.class)) return MutableDateTime.parse(date, fmt); else throw new UnsupportedOperationException("type"); }
From source file:org.filteredpush.qc.date.DateUtils.java
License:Apache License
/** * Attempt to extract a time from an eventDate that could contain time information. * //from www. jav a 2 s . c om * @param eventDate dwc:eventDate from which to try to extract a time (in UTC). * @return a string containing a time in UTC or null */ public static String extractZuluTime(String eventDate) { String result = null; if (!isEmpty(eventDate)) { if (eventDate.endsWith("UTC")) { eventDate = eventDate.replace("UTC", "Z"); } DateTimeParser[] parsers = { ISODateTimeFormat.dateHour().getParser(), ISODateTimeFormat.dateTimeParser().getParser(), ISODateTimeFormat.dateHourMinute().getParser(), ISODateTimeFormat.dateHourMinuteSecond().getParser(), ISODateTimeFormat.dateTime().getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); if (eventDate.matches("^[0-9]{4}[-][0-9]{2}[-][0-9]{2}[Tt].+")) { try { result = instantToStringTime(Instant.parse(eventDate, formatter)); logger.debug(result); } catch (Exception e) { // not a date with a time logger.error(e.getMessage()); } } if (isRange(eventDate) && eventDate.contains("/") && result != null) { String[] bits = eventDate.split("/"); if (bits != null && bits.length > 1) { // does either start or end date contain a time? if (bits[0].matches("^[0-9]{4}[-][0-9]{2}[-][0-9]{2}[Tt].+")) { try { result = instantToStringTime(Instant.parse(bits[0], formatter)); logger.debug(result); } catch (Exception e) { // not a date with a time logger.error(e.getMessage()); } } if (bits[1].matches("^[0-9]{4}[-][0-9]{2}[-][0-9]{2}[Tt].+") && result != null) { try { result = instantToStringTime(Instant.parse(bits[1], formatter)); logger.debug(result); } catch (Exception e) { // not a date with a time logger.error(e.getMessage()); } } } } } return result; }
From source file:org.hawkular.metrics.api.jaxrs.influx.query.parse.definition.SelectQueryDefinitionsParser.java
License:Apache License
@Override public void exitDateOperand(@NotNull DateOperandContext ctx) { String dateString = ctx.DATE_STRING().getText(); dateString = dateString.substring(1, dateString.length() - 1); operandQueue.addLast(new DateOperand(Instant.parse(dateString, DATE_FORMATTER))); }