List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime
public DateTime parseDateTime(String text)
From source file:io.github.romankl.bitcoinvalue.util.DateUtility.java
License:Open Source License
public static String convertDateRepresentationToIsoDate(final Context context, String entryDate) { if (isNullOrEmpty(entryDate)) return ""; DateTimeFormatter formatter = DateTimeFormat.forPattern(getDateRepresentation(context)); return formatter.parseDateTime(entryDate).toString(); }
From source file:io.konig.runtime.io.BaseJsonReader.java
License:Apache License
protected GregorianCalendar dateTime(JsonParser parser) throws IOException { DateTimeFormatter fmt = ISODateTimeFormat.dateOptionalTimeParser(); String text = parser.getValueAsString(); DateTime joda = fmt.parseDateTime(text); return joda.toGregorianCalendar(); }
From source file:io.prestosql.operator.scalar.DateTimeFunctions.java
License:Apache License
private static DateTime parseDateTimeHelper(DateTimeFormatter formatter, String datetimeString) { try {/*from w w w. j ava 2 s . co m*/ return formatter.parseDateTime(datetimeString); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e); } }
From source file:io.spikex.filter.internal.Rule.java
License:Apache License
private int compareToDateTime(final DateTime d1, final Object obj) { DateTimeFormatter fmt = (DateTimeFormatter) m_fmt; String dateStr = String.valueOf(obj); DateTime d2 = fmt.parseDateTime(dateStr); // https://github.com/JodaOrg/joda-time/issues/73 return d1.toLocalDateTime().compareTo(d2.toLocalDateTime()); }
From source file:io.spikex.filter.internal.Rule.java
License:Apache License
private static DateTime createDateTime(final JsonObject config, final String field) { DateTime dt;// w w w. ja v a 2s . c om String dateStr = config.getString(field); m_logger.trace("date string: {}", dateStr); if (dateStr != null && dateStr.startsWith(BUILTIN_NOW)) { dt = Variables.createDateTimeNow(dateStr); } else { DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); dt = fmt.parseDateTime(dateStr); } return dt; }
From source file:it.geosolutions.geobatch.destination.ingestion.ObuIngestionProcess.java
License:Open Source License
public static void main(String[] args) throws IOException, ParseException { File importFile = new File("D:\\Develop\\destination\\OBU\\OBU.csv"); BufferedReader reader = null; TimeZone tz = TimeZone.getTimeZone("UTC"); DateTimeFormatter dateFormat = ISODateTimeFormat.dateTimeNoMillis(); DateFormat outputDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try {// ww w . j a v a2s. c o m reader = new BufferedReader(new FileReader(importFile)); String line = null; int count = 0; while ((line = reader.readLine()) != null) { String[] parts = line.split(";"); int idSorgente = Integer.parseInt(parts[0]); Date dataTrasmissione = dateFormat.parseDateTime(parts[1]).toDate(); Date dataRicezione = dateFormat.parseDateTime(parts[2]).toDate(); Date dataCreazione = dateFormat.parseDateTime(parts[3]).toDate(); String autista = parts[4]; String trattore = parts[5]; String semirimorchio = parts[6]; String cim = parts[7]; String ultimoMsg = parts[8]; Double latitude = Double.parseDouble(parts[9]); if (latitude > 90.0) { latitude = null; } Double longitude = Double.parseDouble(parts[10]); if (longitude > 900.0) { longitude = null; } String type = parts[11]; String value = parts[12]; String originalValue = value; Map<String, Object> values = new HashMap<String, Object>(); if (type.equals("01")) { int n = Integer.parseInt(value.substring(0, 2), 16); value = value.substring(2); List<String> subcodes = new ArrayList<String>(); for (int i = 0; i < n; i++) { subcodes.add(value.substring(0, 2)); value = value.substring(2); } for (String subcode : subcodes) { if (subcode.equals("01")) { values.put("velocita_gps", Integer.parseInt(value.substring(0, 2), 16)); value = value.substring(2); } else if (subcode.equals("02")) { values.put("direzione_gps", Integer.parseInt(value.substring(0, 3), 16)); value = value.substring(3); } else if (subcode.equals("03")) { values.put("pressione_sospensioni", Integer.parseInt(value.substring(0, 4), 16)); value = value.substring(4); } else if (subcode.equals("04")) { values.put("distanza", Long.parseLong(value.substring(0, 8), 16)); value = value.substring(8); } else if (subcode.equals("05")) { values.put("velocita_odometro", Integer.parseInt(value.substring(0, 2), 16)); value = value.substring(2); } else if (subcode.equals("06")) { values.put("inclinazione_longitudinale", Integer.parseInt(value.substring(0, 2), 16)); value = value.substring(2); } else if (subcode.equals("07")) { values.put("inclinazione_trasversale", Integer.parseInt(value.substring(0, 2), 16)); value = value.substring(2); } else if (subcode.equals("0D")) { // TODO: Dati CAN bus trattore String prefix = value.substring(0, 18); value = value.substring(18); int len = Integer.parseInt(prefix.substring(16, 18)); int globallen = 3 * len; for (int j = 1; j <= len; j++) { globallen += 2 * (Integer.parseInt(value.substring(3 * j - 1, 3 * j))); } value = value.substring(globallen + 2); } else if (subcode.equals("0F")) { // TODO: quantita prodotto negli scomparti int len = Integer.parseInt(value.substring(0, 2), 16); value = value.substring(2); value = value.substring(5 * len); } else if (subcode.equals("10")) { // TODO: pressione prodotto int len = Integer.parseInt(value.substring(0, 2), 16); value = value.substring(2 + 5 * len); } else if (subcode.equals("11")) { // TODO: temperatura prodotto int len = Integer.parseInt(value.substring(0, 2), 16); value = value.substring(2 + 5 * len); } else if (subcode.equals("14")) { // TODO: tipo prodotto negli scomparti int len = Integer.parseInt(value.substring(0, 2), 16); value = value.substring(2); value = value.substring(3 * len); } else if (subcode.equals("16")) { values.put("distanza_grezza", Long.parseLong(value.substring(0, 8), 16)); value = value.substring(8); } else { value = ""; } } } //0;2012-11-20T07:50:09+01:00;2012-11-20T07:50:09+01:00;2012-11-20T07:46:44+01:00; //UNKNOWNA;UNKNOWNT;LOM1406;UNKNOWNCIM;0;+47.9977;+011.6758;01;020F140412CB320F943181B42CAF04100200300400 count++; int velocita = 0; int direzione = 0; if (values.containsKey("velocita_gps")) { velocita = (Integer) values.get("velocita_gps"); } else if (values.containsKey("velocita_odometro")) { velocita = (Integer) values.get("velocita_odometro"); } if (values.containsKey("direzione_gps")) { direzione = (Integer) values.get("direzione_gps"); } System.out.print( "insert into siig_geo_obu(id,source,data_trasmissione,data_ricezione,data_creazione,autista,trattore,semirimorchio,cim,geometria,tipo,valore,velocita,direzione) "); if (longitude == null) { System.out.println( "values(" + count + "," + idSorgente + ",'" + outputDateFormat.format(dataTrasmissione) + "','" + outputDateFormat.format(dataRicezione) + "','" + outputDateFormat.format(dataCreazione) + "','" + autista + "','" + trattore + "','" + semirimorchio + "','" + cim + "',null,'" + type + "','" + value + "'," + velocita + "," + direzione + ");"); } else { System.out.println("values(" + count + "," + idSorgente + ",'" + outputDateFormat.format(dataTrasmissione) + "','" + outputDateFormat.format(dataRicezione) + "','" + outputDateFormat.format(dataCreazione) + "','" + autista + "','" + trattore + "','" + semirimorchio + "','" + cim + "',ST_GeomFromText('POINT(" + longitude + " " + latitude + ")',4326),'" + type + "','" + value + "'," + velocita + "," + direzione + ");"); } } } finally { if (reader != null) { reader.close(); } } }
From source file:jongo.demo.Demo.java
License:Open Source License
private static void generateDemoDatabase(final DatabaseConfiguration dbcfg) { final String database = dbcfg.getDatabase(); QueryRunner run = new QueryRunner(JDBCConnectionFactory.getDataSource(dbcfg)); l.info("Generating Demo resources in database {}", database); update(run, getCreateAuthTable());//from w w w .ja va2 s . c om update(run, getCreateUserTable()); update(run, getCreateMakersTable()); update(run, getCreateCarsTable()); update(run, getCreateCommentsTable()); update(run, getCreatePicturesTable()); update(run, getCreateSalesStatsTable()); update(run, getCreateSalesByMakerAndModelStatsTable()); update(run, getCreateEmptyTable()); l.info("Generating Demo Data in database {}", database); final String insertAuthQuery = "INSERT INTO jongo_auth (email, password) VALUES (?,?)"; update(run, insertAuthQuery, "a@a.com", JongoUtils.getHashedPassword("123456")); update(run, insertAuthQuery, "a@b.com", JongoUtils.getHashedPassword("This is a test")); final String insertUserQuery = "INSERT INTO users (name, age, birthday, credit) VALUES (?,?,?,?)"; update(run, insertUserQuery, "foo", 30, "1982-12-13", 32.5); update(run, insertUserQuery, "bar", 33, "1992-01-15", 0); for (CarMaker maker : CarMaker.values()) { update(run, "INSERT INTO maker (name, realname) VALUES (?,?)", maker.name(), maker.getRealName()); } final String insertCar = "INSERT INTO car (maker, model, year, fuel, transmission, currentMarketValue, newValue) VALUES (?,?,?,?,?,?,?)"; update(run, insertCar, "CITROEN", "C2", 2008, "Gasoline", "Manual", 9000, 13000); update(run, "INSERT INTO car (maker, model, year, transmission, currentMarketValue, newValue) VALUES (?,?,?,?,?,?)", "FIAT", "500", 2010, "Manual", 19000, 23.000); update(run, insertCar, "BMW", "X5", 2011, "Diesel", "Automatic", 59000, 77000); final String insertComment = "INSERT INTO comments (car_id, car_comment) VALUES (?,?)"; update(run, insertComment, 0, "The Citroen C2 is a small car with a great attitude"); update(run, insertComment, 0, "I Love my C2"); update(run, insertComment, 2, "BMW's X5 costs too much for what it's worth. Checkout http://www.youtube.com/watch?v=Bg1TB4dRobY"); final String insertPicture = "INSERT INTO pictures (car_id, picture) VALUES (?,?)"; update(run, insertPicture, 0, "http://www.babez.de/citroen/c2/picth01.jpg"); update(run, insertPicture, 0, "http://www.babez.de/citroen/c2/pic02.jpg"); update(run, insertPicture, 0, "http://www.babez.de/citroen/c2/picth03.jpg"); update(run, insertPicture, 1, "http://www.dwsauto.com/wp-content/uploads/2008/07/fiat-500-photo.jpg"); update(run, insertPicture, 1, "http://www.cochesadictos.com/coches/fiat-500/imagenes/index1.jpg"); update(run, insertPicture, 1, "http://www.cochesadictos.com/coches/fiat-500/imagenes/index4.jpg"); update(run, insertPicture, 2, "http://www.coches21.com/fotos/100/bmw_x5_457.jpg"); update(run, insertPicture, 2, "http://www.coches21.com/fotos/100/bmw_x5_460.jpg"); update(run, insertPicture, 2, "http://www.coches21.com/modelos/250/bmw_x5_65.jpg"); // generate some random data for the stats page DateTimeFormatter isofmt = ISODateTimeFormat.dateTime(); DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS"); DateTime dt;// = isofmt.parseDateTime("2012-01-16T13:34:00.000Z"); for (int year = 2000; year < 2012; year++) { for (int month = 1; month <= 12; month++) { int val = 1910 + new Random().nextInt(100); dt = isofmt.parseDateTime(year + "-" + month + "-01T01:00:00.000Z"); update(run, "INSERT INTO sales_stats (year, month, sales, last_update) VALUES (?,?,?,?)", year, month, val, fmt.print(dt)); for (CarMaker maker : CarMaker.values()) { val = new Random().nextInt(100); update(run, "INSERT INTO maker_stats (year, month, sales, maker, last_update) VALUES (?,?,?,?,?)", year, month, val, maker.name(), fmt.print(dt)); } } } update(run, "SET TABLE maker READONLY TRUE"); //load the sp update(run, "CREATE FUNCTION simpleStoredProcedure () RETURNS TINYINT RETURN 1"); update(run, "CREATE PROCEDURE insert_comment (IN car_id INTEGER, IN car_comment VARCHAR(255)) MODIFIES SQL DATA INSERT INTO comments VALUES (DEFAULT, car_id, car_comment)"); update(run, "CREATE PROCEDURE get_year_sales (IN in_year INTEGER, OUT out_total INTEGER) READS SQL DATA SELECT COUNT(sales) INTO out_total FROM sales_stats WHERE year = in_year"); update(run, getCreateView()); }
From source file:jongo.JongoUtils.java
License:Open Source License
/** * Check if a string has the ISO date time format. Uses the ISODateTimeFormat.dateTime() from JodaTime * and returns a DateTime instance. The correct format is yyyy-MM-ddTHH:mm:ss.SSSZ * @param arg the string to check// ww w. ja v a2 s . co m * @return a DateTime instance if the string is in the correct ISO format. */ public static DateTime isDateTime(final String arg) { if (arg == null) return null; DateTimeFormatter f = ISODateTimeFormat.dateTime(); DateTime ret = null; try { ret = f.parseDateTime(arg); } catch (IllegalArgumentException e) { l.debug(arg + " is not a valid ISO DateTime"); } return ret; }
From source file:jongo.JongoUtils.java
License:Open Source License
/** * Check if a string has the ISO date format. Uses the ISODateTimeFormat.date() from JodaTime * and returns a DateTime instance. The correct format is yyyy-MM-dd or yyyyMMdd * @param arg the string to check/* ww w. java 2s . co m*/ * @return a DateTime instance if the string is in the correct ISO format. */ public static DateTime isDate(final String arg) { if (arg == null) return null; DateTime ret = null; DateTimeFormatter df; if (arg.contains("-")) { df = ISODateTimeFormat.date(); } else { df = ISODateTimeFormat.basicDate(); } try { ret = df.parseDateTime(arg); } catch (IllegalArgumentException e) { l.debug(arg + " is not a valid ISO date"); } return ret; }
From source file:jongo.JongoUtils.java
License:Open Source License
/** * Check if a string has the ISO time format. Uses the ISODateTimeFormat.time() from JodaTime * and returns a DateTime instance. The correct format is HH:mm:ss.SSSZZ or HHmmss.SSSZ * @param arg the string to check//from ww w . ja v a 2 s . co m * @return a DateTime instance if the string is in the correct ISO format. */ public static DateTime isTime(final String arg) { if (arg == null) return null; DateTime ret = null; DateTimeFormatter df; if (arg.contains(":")) { df = ISODateTimeFormat.time(); } else { df = ISODateTimeFormat.basicTime(); } try { ret = df.parseDateTime(arg); } catch (IllegalArgumentException e) { l.debug(arg + " is not a valid ISO time"); } return ret; }