List of usage examples for org.joda.time LocalDate parse
public static LocalDate parse(String str, DateTimeFormatter formatter)
From source file:at.yawk.fiction.impl.ao3.SearchPageParser.java
License:Mozilla Public License
@Override protected void parse(Element root, Pageable.Page<Ao3Story> target) throws Exception { List<Ao3Story> stories = new ArrayList<>(); for (Element element : root.select("#main > .work.index > li")) { Ao3Story story = new Ao3Story(); story.setId(parseIntLenient(element.attr("id"))); story.setUri(URI.create("https://archiveofourown.org/works/" + story.getId())); Elements titleAndAuthor = element.select("> div > h4 > a"); story.setTitle(titleAndAuthor.first().text()); if (titleAndAuthor.size() > 1) { story.setAuthor(new Ao3Author()); story.getAuthor().setName(titleAndAuthor.get(1).text()); }/* w w w . ja v a 2s . c o m*/ story.setUpdateTime(LocalDate.parse(element.select(".datetime").first().text(), DATE_PATTERN) .toDateTimeAtStartOfDay().toInstant()); story.setRequiredTags(map(element.select(".required-tags > li .text"), Element::text)); story.setWarnings(map(element.select(".tags > .warnings"), Element::text)); story.setRelationships(map(element.select(".tags > .relationships"), Element::text)); story.setCharacters(map(element.select(".tags > .characters"), Element::text)); story.setFreeforms(map(element.select(".tags > .freeforms"), Element::text)); Element summary = element.select(".summary").first(); if (summary != null) { HtmlText description = new HtmlText(); description.setHtml(summary.html()); story.setDescription(description); } story.setLanguage(element.select(".stats dd.language").text()); story.setWords(parseIntLenient(element.select(".stats dd.words").first().text())); Element chapters = element.select(".stats dd.chapters").first(); if (chapters != null) { String[] parts = chapters.text().split("/"); List<Ao3Chapter> chapterList; if (story.getChapters() == null) { story.setChapters(chapterList = new ArrayList<>()); } else { //noinspection unchecked chapterList = (List<Ao3Chapter>) story.getChapters(); } int chapterCount = parseIntLenient(parts[0]); for (int i = 0; i < chapterCount; i++) { while (chapterList.size() <= i) { chapterList.add(new Ao3Chapter()); } } story.setChapterGoal(parts[1].equals("?") ? null : parseIntLenient(parts[1])); } else { story.setChapterGoal(null); } Element comments = element.select(".stats dd.comments").first(); if (comments != null) { story.setCommentCount(parseIntLenient(comments.text())); } else { story.setCommentCount(0); } Element kudos = element.select(".stats dd.kudos").first(); if (kudos != null) { story.setKudoCount(parseIntLenient(kudos.text())); } else { story.setKudoCount(0); } Element bookmarks = element.select(".stats dd.bookmarks").first(); if (bookmarks != null) { story.setBookmarkCount(parseIntLenient(bookmarks.text())); } else { story.setBookmarkCount(0); } Element hits = element.select(".stats dd.hits").first(); if (hits != null) { story.setHitCount(parseIntLenient(hits.text())); } else { story.setHitCount(0); } stories.add(story); } target.setPageCount(1); target.setEntries(stories); for (Element pageLink : root.select(".pagination > li")) { if (!pageLink.hasClass("next")) { target.setPageCount(parseIntLenient(pageLink.text())); } else if (!pageLink.select(".disabled").isEmpty()) { target.setLast(true); } } if (target.getPageCount() == 1) { target.setLast(true); } }
From source file:ca.ualberta.physics.cssdp.jaxb.LocalDateAdapter.java
License:Apache License
public LocalDate unmarshal(String v) throws Exception { return LocalDate.parse(v, DateTimeFormat.forPattern("yyyy-MM-dd")); }
From source file:com.datastax.driver.extras.codecs.joda.LocalDateCodec.java
License:Apache License
@Override public LocalDate parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // single quotes are optional for long literals, mandatory for date patterns // strip enclosing single quotes, if any if (isQuoted(value)) { value = unquote(value);//from w w w .j ava 2 s . c o m } if (isLongLiteral(value)) { long raw; try { raw = parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value)); } int days; try { days = fromCqlDateToDaysSinceEpoch(raw); } catch (IllegalArgumentException e) { throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value)); } return EPOCH.plusDays(days); } try { return LocalDate.parse(value, FORMATTER); } catch (RuntimeException e) { throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value)); } }
From source file:com.github.cassandra.jdbc.provider.datastax.codecs.JavaSqlDateCodec.java
License:Apache License
@Override public Date parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // single quotes are optional for long literals, mandatory for date patterns // strip enclosing single quotes, if any if (isQuoted(value)) { value = unquote(value);//from w ww . ja v a 2s . co m } if (isLongLiteral(value)) { long raw; try { raw = parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value)); } int days; try { days = fromCqlDateToDaysSinceEpoch(raw); } catch (IllegalArgumentException e) { throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value)); } return new Date(EPOCH.plusDays(days).toDate().getTime()); } try { return new Date(LocalDate.parse(value, FORMATTER).toDate().getTime()); } catch (RuntimeException e) { throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value)); } }
From source file:com.graph.line.LineGraphData.java
public LineGraphData(String timeIn, String timeOut) { java.sql.Connection con = null; java.sql.PreparedStatement stmt = null; java.sql.ResultSet rs = null; try {//from w w w. j a v a 2 s. com con = ControlPanelPool.getInstance().getConnection(); DateTimeFormatter format = org.joda.time.format.DateTimeFormat.forPattern("MM/dd/yyyy"); LocalDate startDate = LocalDate.parse(timeIn, format); LocalDate endDate = LocalDate.parse(timeOut, format); int days = Days.daysBetween(startDate, endDate).getDays(); //List<LocalDate> dates = new ArrayList<>(days); sessionCount = new ArrayList<>(); addressCount = new ArrayList<>(); dateCount = new ArrayList<>(); for (int i = 0; i < days; i++) { LocalDate d2 = startDate.withFieldAdded(DurationFieldType.days(), i + 1); //dates.add(d); stmt = con.prepareStatement( "SELECT COUNT(DISTINCT remoteAddress) as remoteAdd, COUNT(DISTINCT sessionId) as sess FROM leadSession WHERE timeIn > CONVERT(date, ?) AND timeIn < CONVERT(date, ?)"); stmt.setString(1, startDate.withFieldAdded(DurationFieldType.days(), i).toString()); stmt.setString(2, startDate.withFieldAdded(DurationFieldType.days(), i + 1).toString()); rs = stmt.executeQuery(); while (rs.next()) { sessionCount.add(rs.getString("sess")); addressCount.add(rs.getString("remoteAdd")); } dateCount.add(startDate.withFieldAdded(DurationFieldType.days(), i).toString()); } con.close(); } catch (IOException | SQLException | PropertyVetoException ex) { Logger.getLogger(LineGraphData.class.getName()).log(Level.SEVERE, null, ex); } finally { DbUtils.closeQuietly(con, stmt, rs); } }
From source file:com.gst.portfolio.address.domain.Address.java
License:Apache License
public static Address fromJsonObject(final JsonObject jsonObject, final CodeValue state_province, final CodeValue country) { String street = ""; String addressLine1 = ""; String addressLine2 = ""; String addressLine3 = ""; String townVillage = ""; String city = ""; String countyDistrict = ""; String postalCode = ""; BigDecimal latitude = BigDecimal.ZERO; BigDecimal longitude = BigDecimal.ZERO; String createdBy = ""; Locale locale = Locale.ENGLISH; String updatedBy = ""; LocalDate updatedOnDate = null; LocalDate createdOnDate = null; if (jsonObject.has("street")) { street = jsonObject.get("street").getAsString(); }//from w w w.ja v a 2 s. c om if (jsonObject.has("addressLine1")) { addressLine1 = jsonObject.get("addressLine1").getAsString(); } if (jsonObject.has("addressLine2")) { addressLine2 = jsonObject.get("addressLine2").getAsString(); } if (jsonObject.has("addressLine3")) { addressLine3 = jsonObject.get("addressLine3").getAsString(); } if (jsonObject.has("townVillage")) { townVillage = jsonObject.get("townVillage").getAsString(); } if (jsonObject.has("city")) { city = jsonObject.get("city").getAsString(); } if (jsonObject.has("countyDistrict")) { countyDistrict = jsonObject.get("countyDistrict").getAsString(); } if (jsonObject.has("postalCode")) { postalCode = jsonObject.get("postalCode").getAsString(); } if (jsonObject.has("latitude")) { latitude = jsonObject.get("latitude").getAsBigDecimal(); } if (jsonObject.has("longitude")) { longitude = jsonObject.get("longitude").getAsBigDecimal(); } if (jsonObject.has("createdBy")) { createdBy = jsonObject.get("createdBy").getAsString(); } if (jsonObject.has("createdOn")) { String createdOn = jsonObject.get("createdOn").getAsString(); DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); createdOnDate = LocalDate.parse(createdOn, formatter); } if (jsonObject.has("updatedBy")) { updatedBy = jsonObject.get("updatedBy").getAsString(); } if (jsonObject.has("updatedOn")) { String updatedOn = jsonObject.get("updatedOn").getAsString(); DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); updatedOnDate = LocalDate.parse(updatedOn, formatter); } return new Address(street, addressLine1, addressLine2, addressLine3, townVillage, city, countyDistrict, state_province, country, postalCode, latitude, longitude, createdBy, createdOnDate, updatedBy, updatedOnDate); }
From source file:com.ideaspymes.tesakaplugin.importacion.jpa.RetencionGenerada.java
public RetencionGenerada(Datos d, RecepcionImp r) { this.uuid = d.getAtributos().getUuid(); this.fechaCreacion = LocalDate .parse(d.getAtributos().getFechaCreacion(), DateTimeFormat.forPattern("yyyy-MM-dd")).toDate(); this.fechaHoraCreacion = DateTime .parse(d.getAtributos().getFechaHoraCreacion(), DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")) .toDate();/*from w ww .j av a2 s .c om*/ this.codigoEstablecimiento = d.getInformante().getCodigoEstablecimiento(); this.timbradoComprobante = d.getInformante().getTimbradoComprobante(); this.puntoExpedicionComprobante = d.getInformante().getPuntoExpedicionComprobante(); this.establecimiento = d.getInformante().getEstablecimiento(); this.condicionCompra = d.getTransaccion().getCondicionCompra(); this.tipoComprobante = d.getTransaccion().getTipoComprobante(); this.numeroTimbradoFactura = d.getTransaccion().getNumeroTimbrado(); this.numeroComprobanteVenta = d.getTransaccion().getNumeroComprobanteVenta(); this.fechaFactura = LocalDate.parse(d.getTransaccion().getFecha(), DateTimeFormat.forPattern("yyyy-MM-dd")) .toDate(); this.proveedorRuc = d.getInformado().getRuc(); this.proveedorDv = d.getInformado().getDv(); this.proveedorNombre = d.getInformado().getNombre(); this.proveedorTipoIdentificacion = d.getInformado().getTipoIdentificacionNombre(); this.proveedorIdentificacion = d.getInformado().getIdentificacion(); this.proveedorSituacion = d.getInformado().getSituacion(); this.proveedorCorreo = d.getInformado().getCorreoElectronico(); this.proveedorDomicilio = d.getInformado().getDomicilio() == null ? d.getInformado().getDireccion() : d.getInformado().getDomicilio(); Double total = 0d; for (DetalleImp dt : d.getDetalle()) { total += (dt.getPrecioUnitario() * dt.getCantidad()); } this.totalFactura = total; this.fechaRetencion = LocalDate.parse(d.getRetencion().getFecha(), DateTimeFormat.forPattern("yyyy-MM-dd")) .toDate(); this.moneda = d.getRetencion().getMoneda(); this.tipoCambio = d.getRetencion().getTipoCambio(); this.retencionIva = d.getRetencion().getRetencionIva(); this.retencionRenta = d.getRetencion().getRetencionRenta(); this.conceptoRenta = d.getRetencion().getConceptoRenta(); this.conceptoIva = d.getRetencion().getConceptoIva(); this.habilitadoRentaCabezas = d.getRetencion().getHabilitadoRentaCabezas(); this.habilitadoRentaToneladas = d.getRetencion().getHabilitadoRentaToneladas(); this.ivaBase5 = d.getRetencion().getIvaBase5(); this.ivaTotal5 = d.getRetencion().getIvaTotal5(); this.ivaBase10 = d.getRetencion().getIvaBase10(); this.ivaTotal10 = d.getRetencion().getIvaTotal10(); this.ivaTotal = d.getRetencion().getIvaTotal(); this.rentaBase = d.getRetencion().getRentaBase(); this.rentaTotal = d.getRetencion().getRentaTotal(); this.rentaCabezasBase = d.getRetencion().getRentaCabezasBase(); this.rentaCabezasCantidad = d.getRetencion().getRentaCabezasCantidad(); this.rentaCabezasTotal = d.getRetencion().getRentaCabezasTotal(); this.rentaToneladasBase = d.getRetencion().getRentaToneladasBase(); this.rentaToneladasCantidad = d.getRetencion().getRentaToneladasCantidad(); this.rentaToneladasTotal = d.getRetencion().getRentaToneladasTotal(); this.retencionIvaTotal = d.getRetencion().getRetencionIvaTotal(); this.retencionRentaTotal = d.getRetencion().getRetencionRentaTotal(); this.retencionTotal = d.getRetencion().getRetencionTotal(); this.rentaPorcentaje = d.getRetencion().getRentaPorcentaje(); this.conceptoIvaNombre = d.getRetencion().getConceptoIvaNombre(); this.conceptoRentaNombre = d.getRetencion().getConceptoRentaNombre(); this.ivaPorcentaje5 = d.getRetencion().getIvaPorcentaje5(); this.ivaPorcentaje10 = d.getRetencion().getIvaPorcentaje10(); this.monedaNombre = d.getRetencion().getMonedaNombre(); //totales this.impuestoTotalExento = d.getTotales().getImpuestoTotalExento(); this.impuestoTotalAl5 = d.getTotales().getImpuestoTotalAl5(); this.impuestoTotalAl10 = d.getTotales().getImpuestoTotalAl10(); this.valorTotalExento = d.getTotales().getValorTotalExento(); this.valorTotalAl5 = d.getTotales().getValorTotalAl5(); this.valorTotalAl10 = d.getTotales().getValorTotalAl10(); this.impuestoTotal = d.getTotales().getImpuestoTotal(); this.valorTotal = d.getTotales().getValorTotal(); String[] anumero = r.getNumeroComprobante().split("-"); this.fechaProceso = DateTime.parse(r.getFechaProceso(), DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:SSS")) .toDate(); this.numeroComprobante = anumero[2]; this.fechaEmision = LocalDate.parse(r.getFechaEmision(), DateTimeFormat.forPattern("yyyy-MM-dd")).toDate(); this.cadenaControl = r.getCadenaControl(); this.numero = anumero[2]; this.fechaRecepcion = DateTime .parse(r.getFechaRecepcion(), DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:SSS")).toDate(); this.hashString = r.getHash(); this.recepcionCorrecta = r.getRecepcionCorrecta(); this.mensajeRecepcion = r.getMensajeRecepcion(); this.procesamientoCorrecto = r.getProcesamientoCorrecto(); this.mensajeProcesamiento = r.getMensajeProcesamiento(); this.migrado = false; }
From source file:com.mycompany.ajaxandxml.ws.ReleasedAdapter.java
@Override public LocalDate unmarshal(String v) throws Exception { return LocalDate.parse(v, dateFormatter); }
From source file:com.qubit.solution.fenixedu.integration.cgd.webservices.CgdIntegrationService.java
License:Open Source License
@WebMethod public UpdateMifareOutputMessage updateChip(UpdateMifareInputMessage message) { UpdateMifareOutputMessage outputMessage = new UpdateMifareOutputMessage(); Person person = message.getIdentifiedPerson(); if (person != null) { outputMessage.populate(person, message.getPopulationCode(), message.getMemberCode(), message.getMemberID(), message.getChipData(), message.getCardIdentification(), LocalDate.parse(message.getPersonalizationDate(), DateTimeFormat.forPattern("YYYY-MM-dd"))); }/*from www . ja va2 s. c om*/ return outputMessage; }
From source file:com.sonicle.webtop.core.sdk.BaseSettings.java
License:Open Source License
public LocalDate getDate(String key, String defaultValue, String pattern) { DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern).withZone(DateTimeZone.getDefault()); LocalDate lt = (defaultValue == null) ? null : LocalDate.parse(defaultValue, dtf); return getDate(key, lt, pattern); }