List of usage examples for org.joda.time.format DateTimeFormatter parseLocalDate
public LocalDate parseLocalDate(String text)
From source file:de.geeksfactory.opacclient.objects.Copy.java
License:MIT License
/** * Set property using the following keys: barcode, location, department, branch, status, * returndate, reservations, signature, resinfo, url * * For "returndate", the given {@link DateTimeFormatter} will be used to parse the date. * * If you supply an invalid key, an {@link IllegalArgumentException} will be thrown. * * This method is used to simplify refactoring of old APIs from the Map<String, String> data * structure to this class. If you are creating a new API, you probably don't need to use it. * * @param key one of the keys mentioned above * @param value the value to set. Dates must be in a format parseable by the given {@link * DateTimeFormatter}, otherwise an {@link IllegalArgumentException} will be * thrown.//from w ww . j a v a 2 s .com * @param fmt the {@link DateTimeFormatter} to use for parsing dates */ public void set(String key, String value, DateTimeFormatter fmt) { if (key.equals("returndate")) { setReturnDate(fmt.parseLocalDate(value)); } else { set(key, value); } }
From source file:edu.wayne.cs.fms.controller.CRUD.java
public static DBCursor Search(SearchInfo sInfo, String colName, MongoClient mongoClient) { BasicDBObject query = new BasicDBObject(); //Time Range/* www. j a va 2 s. c o m*/ if (sInfo.getUpDate() != null && sInfo.getDownDate() != null) { String upDateStr = sInfo.getUpDate().toString(); String downDateStr = sInfo.getDownDate().toString(); DateTimeFormatter df = DateTimeFormat.forPattern("yyyy-MM-dd"); LocalDate upDate = df.parseLocalDate(upDateStr); LocalDate downDate = df.parseLocalDate(downDateStr); ArrayList dates = new ArrayList(); for (LocalDate date = downDate; date.isBefore(upDate.plusDays(1)); date = date.plusDays(1)) { dates.add(date.toString()); } query.append("FL_DATE", new BasicDBObject("$in", dates)); } //Carrier if (sInfo.getCarrier() != null) { query.append("UNIQUE_CARRIER", sInfo.getCarrier()); } //TailNum if (sInfo.getTailNum() != 0) { query.append("FL_NUM", sInfo.getTailNum()); } //DepCity if (sInfo.getDepCity() != null) { query.append("ORIGIN_CITY_NAME", sInfo.getDepCity()); } //ArrCity if (sInfo.getArrCity() != null) { query.append("DEST_CITY_NAME", sInfo.getArrCity()); } //DistanceRange query.append("DISTANCE", new BasicDBObject("$gt", sInfo.getDownDis()).append("$lt", sInfo.getUpDis())); //DepTimeRange query.append("CRS_DEP_TIME", new BasicDBObject("$gt", sInfo.getDownDepTime()).append("$lt", sInfo.getUpDepTime())); //ArrTimeRange query.append("CRS_ARR_TIME", new BasicDBObject("$gt", sInfo.getDownArrTime()).append("$lt", sInfo.getUpArrTime())); //Cancel if (sInfo.getCancel() != -1) { query.append("CANCELLED", sInfo.getCancel()); } System.out.println(query); //MongoClient mongoClient = Connector.connect("localhost", 27017); DB db = mongoClient.getDB("project"); DBCollection flight = db.getCollection(colName); DBCursor cursor = flight.find(query); return cursor; }
From source file:gsonjodatime.LocalDateConverter.java
License:Open Source License
/** * Gson invokes this call-back method during deserialization when it encounters a field of the * specified type. <p>/*from w w w . j av a 2 s . c o m*/ * * In the implementation of this call-back method, you should consider invoking * {@link com.google.gson.JsonDeserializationContext#deserialize(com.google.gson.JsonElement, java.lang.reflect.Type)} method to create objects * for any non-trivial field of the returned object. However, you should never invoke it on the * the same type passing {@code json} since that will cause an infinite loop (Gson will call your * call-back method again). * @param json The Json data being deserialized * @param typeOfT The type of the Object to deserialize to * @return a deserialized object of the specified type typeOfT which is a subclass of {@code T} * @throws com.google.gson.JsonParseException if json is not in the expected format of {@code typeOfT} */ @Override public LocalDate deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { // Do not try to deserialize null or empty values if (json.getAsString() == null || json.getAsString().isEmpty()) { return null; } final DateTimeFormatter fmt = DateTimeFormat.forPattern(PATTERN); return fmt.parseLocalDate(json.getAsString()); }
From source file:me.vertretungsplan.parser.ParserUtils.java
License:Mozilla Public License
static LocalDate parseDate(String string) { if (string == null) return null; reinitIfNeeded();// w w w. j av a 2 s . c o m string = string.replace("Stand:", "").replace("Import:", "").replaceAll(", Woche [A-Z]", "").trim(); int i = 0; for (DateTimeFormatter f : dateFormatters) { try { LocalDate d = f.parseLocalDate(string); if (dateFormats[i].contains("yyyy")) { return d; } else { Duration currentYearDifference = abs(new Duration(DateTime.now(), d.toDateTimeAtCurrentTime())); Duration lastYearDifference = abs( new Duration(DateTime.now(), d.minusYears(1).toDateTimeAtCurrentTime())); Duration nextYearDifference = abs( new Duration(DateTime.now(), d.plusYears(1).toDateTimeAtCurrentTime())); if (lastYearDifference.isShorterThan(currentYearDifference)) { return DateTimeFormat.forPattern(dateFormats[i]).withLocale(Locale.GERMAN) .withDefaultYear(f.getDefaultYear() - 1).parseLocalDate(string); } else if (nextYearDifference.isShorterThan(currentYearDifference)) { return DateTimeFormat.forPattern(dateFormats[i]).withLocale(Locale.GERMAN) .withDefaultYear(f.getDefaultYear() + 1).parseLocalDate(string); } else { return d; } } } catch (IllegalArgumentException e) { // Does not match this format, try the next one } i++; } // Does not match any known format :( return null; }
From source file:name.martingeisse.admin.application.converter.LocalDateConverter.java
License:Open Source License
@Override public LocalDate convertToObject(String value, Locale locale) { try {/* ww w. j a v a 2 s . c o m*/ DateTimeFormatter formatter = getFormatter(locale); return formatter.parseLocalDate(value); } catch (Exception e) { throw new ConversionException(e); } }
From source file:name.martingeisse.sql.config.CustomMysqlLocalDateType.java
License:Open Source License
@Override protected LocalDate parse(final DateTimeFormatter formatter, final String value) { return formatter.parseLocalDate(value); }
From source file:org.activiti.dmn.engine.impl.mvel.extension.DateUtil.java
License:Apache License
public static Date toDate(String dateString) { if (StringUtils.isEmpty(dateString)) { throw new IllegalArgumentException("date string cannot be empty"); }//ww w .ja v a 2 s .c o m DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd"); LocalDate dateTime = dtf.parseLocalDate(dateString); return dateTime.toDate(); }
From source file:org.apache.isis.applib.fixturescripts.clock.ClockFixture.java
License:Apache License
private static LocalDate parseAsLocalDate(String dateStr) { for (DateTimeFormatter formatter : new DateTimeFormatter[] { DateTimeFormat.fullDateTime(), DateTimeFormat.mediumDateTime(), DateTimeFormat.shortDateTime(), DateTimeFormat.forPattern("yyyy-MM-dd"), DateTimeFormat.forPattern("yyyyMMdd"), }) { try {/*from ww w. java 2s . c o m*/ return formatter.parseLocalDate(dateStr); } catch (Exception e) { // continue; } } return null; }
From source file:org.apache.isis.applib.services.xmlsnapshot.XmlSnapshotServiceAbstract.java
License:Apache License
@SuppressWarnings("unchecked") public <T> T getChildElementValue(final Element el, final String tagname, final Class<T> expectedCls) { final Element chldEl = getChildElement(el, tagname); final String dataType = chldEl.getAttribute("isis:datatype"); if (dataType == null) { throw new IllegalArgumentException("unable to locate " + tagname + "/@datatype attribute"); }//from www. j ava2 s . c o m if ("isis:String".equals(dataType)) { return (T) getChildTextValue(chldEl); } if ("isis:LocalDate".equals(dataType)) { final String str = getChildTextValue(chldEl); final DateTimeFormatter forPattern = DateTimeFormat.forPattern("dd-MMM-yyyy") .withLocale(Locale.ENGLISH); return (T) forPattern.parseLocalDate(str); } if ("isis:Byte".equals(dataType)) { final String str = getChildTextValue(chldEl); return (T) new Byte(str); } if ("isis:Short".equals(dataType)) { final String str = getChildTextValue(chldEl); return (T) new Short(str); } if ("isis:Integer".equals(dataType)) { final String str = getChildTextValue(chldEl); return (T) new Integer(str); } if ("isis:Long".equals(dataType)) { final String str = getChildTextValue(chldEl); return (T) new Long(str); } if ("isis:Float".equals(dataType)) { final String str = getChildTextValue(chldEl); return (T) new Float(str); } if ("isis:Double".equals(dataType)) { final String str = getChildTextValue(chldEl); return (T) new Double(str); } if ("isis:BigDecimal".equals(dataType)) { final String str = getChildTextValue(chldEl); return (T) new BigDecimal(str); } if ("isis:BigInteger".equals(dataType)) { final String str = getChildTextValue(chldEl); return (T) new BigInteger(str); } if ("isis:Boolean".equals(dataType)) { final String str = getChildTextValue(chldEl); return (T) new Boolean(str); } throw new IllegalArgumentException( "Datatype of '" + dataType + "' for element '" + tagname + "' not recognized"); }
From source file:org.apache.isis.core.metamodel.facets.value.datejodalocal.JodaLocalDateUtil.java
License:Apache License
private static LocalDate parseDate(String dateStr, Iterable<DateTimeFormatter> formatters) { for (DateTimeFormatter formatter : formatters) { try {//from w w w . j a v a 2 s. c o m return formatter.parseLocalDate(dateStr); } catch (final IllegalArgumentException e) { // continue to next } } throw new TextEntryParseException("Not recognised as a date: " + dateStr); }