List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime
public DateTime parseDateTime(String text)
From source file:com.pinterest.deployservice.scm.GithubManager.java
License:Apache License
private long getDate(Map<String, Object> jsonMap) { Map<String, Object> commiterMap = (Map<String, Object>) jsonMap.get("committer"); String dateGMTStr = (String) commiterMap.get("date"); DateTimeFormatter parser = ISODateTimeFormat.dateTimeNoMillis(); DateTime dt = parser.parseDateTime(dateGMTStr); return dt.getMillis(); }
From source file:com.primovision.lutransport.service.ImportMainSheetServiceImpl.java
private int calculateDuration(String startTime, String endTime) { if (StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)) { return 0; }/*from w ww. ja v a2 s. com*/ DateTimeFormatter durationFormat = DateTimeFormat.forPattern("HH:mm"); DateTime dtStart = durationFormat.parseDateTime(startTime); DateTime dtStop = durationFormat.parseDateTime(endTime); if (dtStop.isBefore(dtStart)) { DateTime temp = dtStart; dtStart = dtStop; dtStop = temp; } /*System.out.print(Days.daysBetween(dtStart, dtStop).getDays() + " days, "); System.out.print(Hours.hoursBetween(dtStart, dtStop).getHours() % 24 + " hours, "); System.out.print(org.joda.time.Minutes.minutesBetween(dtStart, dtStop).getMinutes() % 60 + " minutes, "); System.out.println(Seconds.secondsBetween(dtStart, dtStop).getSeconds() % 60 + " seconds.");*/ int hours = Hours.hoursBetween(dtStart, dtStop).getHours() % 24; int mins = org.joda.time.Minutes.minutesBetween(dtStart, dtStop).getMinutes() % 60; return mins + (hours * 60); }
From source file:com.pungwe.db.io.DBObjectReader.java
License:Apache License
private static DateTime readTimestamp(DataInput input) throws IOException { String dateString = input.readUTF(); DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); return fmt.parseDateTime(dateString); }
From source file:com.pzybrick.iote2e.stream.request.Iote2eRequestRouterHandlerSparkDbImpl.java
License:Apache License
/** * Insert each block./*from w ww. j a va 2 s. c o m*/ * * @param iote2eRequests the iote 2 e requests * @param con the con * @param cachePrepStmtsByTableName the cache prep stmts by table name * @throws Exception the exception */ private void insertEachBlock(List<Iote2eRequest> iote2eRequests, Connection con, Map<String, PreparedStatement> cachePrepStmtsByTableName) throws Exception { final DateTimeFormatter dtfmt = ISODateTimeFormat.dateTime(); String tableName = null; String request_uuid = null; PreparedStatement pstmt = null; try { int cntToCommit = 0; for (Iote2eRequest iote2eRequest : iote2eRequests) { tableName = iote2eRequest.getSourceType().toString(); pstmt = getPreparedStatement(tableName, con, cachePrepStmtsByTableName); if (pstmt != null) { cntToCommit++; request_uuid = iote2eRequest.getRequestUuid().toString(); int offset = 1; // First set of values are the same on every table pstmt.setString(offset++, request_uuid); pstmt.setString(offset++, iote2eRequest.getLoginName().toString()); pstmt.setString(offset++, iote2eRequest.getSourceName().toString()); Timestamp timestamp = new Timestamp( dtfmt.parseDateTime(iote2eRequest.getRequestTimestamp().toString()).getMillis()); pstmt.setTimestamp(offset++, timestamp); // Next value(s)/types are specific to the table // For this simple example, assume one value passed as string String value = iote2eRequest.getPairs().values().iterator().next().toString(); if ("temperature".compareToIgnoreCase(tableName) == 0) { // temp_f pstmt.setFloat(offset++, new Float(value)); } else if ("humidity".compareToIgnoreCase(tableName) == 0) { // pct_humidity pstmt.setFloat(offset++, new Float(value)); } else if ("switch".compareToIgnoreCase(tableName) == 0) { // switch_state pstmt.setInt(offset++, Integer.parseInt(value)); } else if ("heartbeat".compareToIgnoreCase(tableName) == 0) { // heartbeat_state pstmt.setInt(offset++, Integer.parseInt(value)); } pstmt.execute(); } } if (cntToCommit > 0) con.commit(); } catch (SQLException sqlEx) { con.rollback(); // Suppress duplicate rows, assume the are the same and were sent over Kafka > 1 time if (iote2eRequests.size() == 1) { if (sqlEx.getSQLState() != null && sqlEx.getSQLState().startsWith("23")) logger.debug("Skipping duplicate row, table={}, request_uuid={}", tableName, request_uuid); else { logger.error("Error on insert for pstmt: {}", pstmt.toString()); throw sqlEx; } } else { throw sqlEx; } } catch (Exception e2) { con.rollback(); throw e2; } }
From source file:com.qcadoo.model.internal.types.DateTimeType.java
License:Open Source License
@Override public ValueAndError toObject(final FieldDefinition fieldDefinition, final Object value) { if (value instanceof Date) { return ValueAndError.withoutError(value); }// w w w . j a va2 s. com try { DateTimeFormatter fmt = DateTimeFormat.forPattern(DateUtils.L_DATE_TIME_FORMAT); DateTime dt = fmt.parseDateTime(String.valueOf(value)); int year = dt.getYear(); if (year < 1500 || year > 2500) { return ValueAndError.withError("qcadooView.validate.field.error.invalidDateTimeFormat"); } return ValueAndError.withoutError(dt.toDate()); } catch (IllegalArgumentException e) { return ValueAndError.withError("qcadooView.validate.field.error.invalidDateTimeFormat"); } }
From source file:com.qcadoo.model.internal.types.DateType.java
License:Open Source License
@Override public ValueAndError toObject(final FieldDefinition fieldDefinition, final Object value) { if (value instanceof Date) { return ValueAndError.withoutError(value); }/*www . j a va2 s .co m*/ try { DateTimeFormatter fmt = DateTimeFormat.forPattern(DateUtils.L_DATE_FORMAT); DateTime dt = fmt.parseDateTime(String.valueOf(value)); int year = dt.getYear(); if (year < 1500 || year > 2500) { return ValueAndError.withError("qcadooView.validate.field.error.invalidDateFormat.range"); } Date date = dt.toDate(); if (year < 2000) { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, dt.getYear()); c.set(Calendar.MONTH, dt.getMonthOfYear() - 1); c.set(Calendar.DAY_OF_MONTH, dt.getDayOfMonth()); c.set(Calendar.HOUR_OF_DAY, dt.hourOfDay().get()); c.set(Calendar.MINUTE, dt.getMinuteOfHour()); c.set(Calendar.SECOND, dt.getSecondOfMinute()); c.set(Calendar.MILLISECOND, dt.getMillisOfSecond()); date = c.getTime(); } return ValueAndError.withoutError(date); } catch (IllegalArgumentException e) { return ValueAndError.withError("qcadooView.validate.field.error.invalidDateFormat"); } }
From source file:com.qubit.solution.fenixedu.bennu.webservices.services.server.SecurityHeader.java
License:Open Source License
private boolean isTimestampValid() { DateTimeFormatter forPattern = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); try {// ww w .ja va 2 s .co m DateTime parseDateTime = forPattern.parseDateTime(getTimestamp()); Interval interval = new Interval(new DateTime().minusMinutes(5), new DateTime().plusMinutes(5)); return interval.contains(parseDateTime); } catch (Throwable t) { t.printStackTrace(); return false; } }
From source file:com.rapidminer.operator.GenerateDateSeries.java
License:Open Source License
@Override public ExampleSet createExampleSet() throws OperatorException { // TODO Auto-generated method stub // init//from www .java2s . c om DateTimeFormatter dtf = DateTimeFormat.forPattern(getParameterAsString(STARTDATEFORMAT)); // Parsing the date DateTime startTime = dtf.parseDateTime(getParameterAsString(STARTDATE)); dtf = DateTimeFormat.forPattern(getParameterAsString(ENDDATEFORMAT)); // Parsing the date DateTime endTime = dtf.parseDateTime(getParameterAsString(ENDDATE)); //numberofExamples may be needed to add the progress loop, //todo // long numberOfExamples = calculateNumberOfExample(startTime, endTime); List<Attribute> attributes = new ArrayList<Attribute>(); Attribute dateattribute = AttributeFactory.createAttribute("Date", Ontology.DATE_TIME); attributes.add(dateattribute); MemoryExampleTable table = new MemoryExampleTable(attributes); int increment = getParameterAsInt(INTERVAL); switch (getParameterAsString(PARAMETER_INTERVALTYPE)) { case "YEAR": for (DateTime n = startTime; n.isBefore(endTime); n = n.plusYears(increment)) { double[] values = new double[1]; values[0] = n.getMillis(); table.addDataRow(new DoubleArrayDataRow(values)); } break; case "MONTH": for (DateTime n = startTime; n.isBefore(endTime); n = n.plusMonths(increment)) { double[] values = new double[1]; values[0] = n.getMillis(); table.addDataRow(new DoubleArrayDataRow(values)); } break; case "DAY": for (DateTime n = startTime; n.isBefore(endTime); n = n.plusDays(increment)) { double[] values = new double[1]; values[0] = n.getMillis(); ; table.addDataRow(new DoubleArrayDataRow(values)); } break; case "HOUR": for (DateTime n = startTime; n.isBefore(endTime); n = n.plusHours(increment)) { double[] values = new double[1]; values[0] = n.getMillis(); table.addDataRow(new DoubleArrayDataRow(values)); } break; case "MINUTE": for (DateTime n = startTime; n.isBefore(endTime); n = n.plusMinutes(increment)) { double[] values = new double[1]; values[0] = n.getMillis(); table.addDataRow(new DoubleArrayDataRow(values)); } break; case "SECOND": for (DateTime n = startTime; n.isBefore(endTime); n = n.plusSeconds(increment)) { double[] values = new double[1]; values[0] = n.getMillis(); table.addDataRow(new DoubleArrayDataRow(values)); } break; case "MILLISECOND": for (DateTime n = startTime; n.isBefore(endTime); n = n.plusMillis(increment)) { double[] values = new double[1]; values[0] = n.getMillis(); table.addDataRow(new DoubleArrayDataRow(values)); } break; default: break; } //numberOfExamples++; return table.createExampleSet(); }
From source file:com.redprairie.moca.server.db.translate.filter.TU_FunctionAddMonths.java
License:Open Source License
public void testAddMonths() throws Exception { String sql;/*from w w w.j a v a 2s. c o m*/ DateTimeFormatter dateFormat = DateTimeFormat.forPattern("yyyyMMdd"); sql = "select add_months(to_date('20100101', 'yyyymmdd'), 0) result from dual"; runTest(sql, "result", dateFormat.parseDateTime("20100101").toDate()); sql = "select add_months(to_date('20100101', 'yyyymmdd'), 2) result from dual"; runTest(sql, "result", dateFormat.parseDateTime("20100301").toDate()); sql = "select add_months(to_date('20100101', 'yyyymmdd'), -2) result from dual"; runTest(sql, "result", dateFormat.parseDateTime("20091101").toDate()); }
From source file:com.redprairie.moca.server.db.translate.filter.TU_FunctionToDate.java
License:Open Source License
public void testToDate() throws Exception { String sql;/*from w w w .ja v a2s.com*/ DateTimeFormatter dateFormat = DateTimeFormat.forPattern("yyyyMMddHHmmss"); sql = "select to_date('20100123012345', 'YYYYMMDDHH24MISS') result from dual"; runTest(sql, "result", dateFormat.parseDateTime("20100123012345").toDate()); sql = "select to_date('20100123 01:23:45', 'YYYYMMDD HH24:MI:SS') result from dual"; runTest(sql, "result", dateFormat.parseDateTime("20100123012345").toDate()); sql = "select to_date('20100123', 'YYYYMMDD') result from dual"; runTest(sql, "result", dateFormat.parseDateTime("20100123000000").toDate()); sql = "select to_date('20100123') result from dual"; runTest(sql, "result", dateFormat.parseDateTime("20100123000000").toDate()); sql = "select to_date('20100123123456') result from dual"; runTest(sql, "result", dateFormat.parseDateTime("20100123123456").toDate()); }