List of usage examples for org.joda.time.format DateTimeFormatter print
public String print(ReadablePartial partial)
From source file:com.spotify.helios.cli.command.JobHistoryCommand.java
License:Apache License
@Override int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException { final String jobIdString = options.getString(jobIdArg.getDest()); final Map<JobId, Job> jobs = client.jobs(jobIdString).get(); if (jobs.size() == 0) { out.printf("Unknown job: %s%n", jobIdString); return 1; } else if (jobs.size() > 1) { out.printf("Ambiguous job id: %s%n", jobIdString); return 1; }//from ww w . java2s. c o m final JobId jobId = getLast(jobs.keySet()); final TaskStatusEvents result = client.jobHistory(jobId).get(); if (json) { out.println(Json.asPrettyStringUnchecked(result)); return 0; } final Table table = table(out); table.row("HOST", "TIMESTAMP", "STATE", "THROTTLED", "CONTAINERID"); final List<TaskStatusEvent> events = result.getEvents(); final DateTimeFormatter format = DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss.SSS"); for (final TaskStatusEvent event : events) { final String host = checkNotNull(event.getHost()); final long timestamp = checkNotNull(event.getTimestamp()); final TaskStatus status = checkNotNull(event.getStatus()); final State state = checkNotNull(status.getState()); String containerId = status.getContainerId(); containerId = containerId == null ? "<none>" : containerId; table.row(host, format.print(timestamp), state, status.getThrottled(), containerId); } table.print(); return 0; }
From source file:com.superrent.gui.SuperRent.java
private void rentBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rentBtnActionPerformed long ReservationID = rt.genUniqueID(); try {//w w w.j a v a2 s . co m if (rt.validateCustomerInfo(cusNumField1) > 0) { int cusID = rt.validateCustomerInfo(cusNumField1); int brnchID = Integer.parseInt(brnchIdCombo.getSelectedItem().toString()); String vehicleTyp = vehicleCatCombo.getSelectedItem().toString(); Date pickupDate = CommonFunc.changeDateFormat(pickupDt); Date dropoffDate = CommonFunc.changeDateFormat(dropOffDate); String pickuptime = CommonFunc.sqlTime(pickupHour, pickupMin); String dropofftime = CommonFunc.sqlTime(dropoffHHSpin, dropoffMMSpin); DateTime dt = new DateTime(); DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); String now = format.print(dt); if (CommonFunc.compareDates(pickupDate + " " + pickuptime, now) < 0 || CommonFunc .compareDates(pickupDate + " " + pickuptime, dropoffDate + " " + dropofftime) > 0) { JOptionPane.showMessageDialog(null, "Pickup date should be greater than or equal to current date \n\n " + "Dropoff date should be equal to pickup date or greater than pickup date"); return; } else { String vehicleId = (String) unreservedVehiTable.getValueAt(unreservedVehiTable.getSelectedRow(), 0); ConnectDB.exeUpdate( "INSERT INTO reserve (`confirmation_no`, `vin`, `customer_id`, `branch_id`, `phone`, `pickup_time`, `dropoff_time`,`status`, `create_time` )" + " VALUES (" + ReservationID + ", '" + vehicleId + "', " + cusID + ", " + brnchID + ", " + Double.parseDouble(cusNumField1.getText()) + ",'" + pickupDate + " " + pickuptime + "', '" + dropoffDate + " " + dropofftime + "','reserved', '" + pickupDate + " " + pickuptime + "')"); ConnectDB.clearResultSet(); Iterator it = equipSelectedUnits.entrySet().iterator(); if (equipSelectedUnits.size() > 0) { while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); String[] equp = pair.getKey().toString().split(": "); int quantity = (int) pair.getValue(); ConnectDB.exeUpdate( "INSERT INTO `team01`.`equipment_reserved` (`confirmation_no`, `equipment_type`, `quantity`) " + "VALUES (" + ReservationID + ", '" + equp[0] + "', " + quantity + ");"); ConnectDB.clearResultSet(); } } equipSelectedUnits.clear(); confirmationNoDisplayField.setText(String.valueOf(ReservationID)); confirmationNoDisplayField.setEnabled(false); if (CommonFunc.compareDates(pickupDate + " " + pickuptime, now) == 0) { rentConfirmationNO.setText(String.valueOf(ReservationID)); rentPhoneNo.setText(cusNumField1.getText()); } JOptionPane.showMessageDialog(null, "Resvervation done successfully and the Confirmation No is " + ReservationID); resetTable(); Return ret = new Return(); estimatePrice.setText(ret.getEstimateFee(vehicleId, dropoffDate)); CommonFunc.triggerMail(CommonFunc.getEmail(String.valueOf(ReservationID)), "Super Rent Confimation", "Dear customr,\n\n Thank you for choosing SuperRent. Reservation details are below: \n\n" + " Confimation NO: " + ReservationID + "\n\n" + " Pick up time: " + pickupDate + " " + pickuptime + " \n\n" + " Drop off time: " + dropoffDate + " " + dropofftime + "\n\n" + " Estimated price: $ " + estimatePrice.getText() + "\n\n" + "\n\n\n " + " Super Rent"); } } else { JOptionPane.showMessageDialog(null, "Not a valid customer phone number"); } } catch (ClassNotFoundException ex) { JOptionPane.showMessageDialog(null, ex); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, ex); } catch (IOException ex) { JOptionPane.showMessageDialog(null, ex); } catch (ParseException ex) { JOptionPane.showMessageDialog(null, ex); } finally { clearEqupList(); } }
From source file:com.thinkbiganalytics.integration.search.es.SearchEsIntegrationTestBase.java
License:Apache License
protected FeedCategory createKyloCategoryForSearch(String name, String description, boolean includeUserProperties) { DateTime currentTime = DateTime.now(); DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("MM/dd/yyyy HH:mm:ss"); Set<UserProperty> userProperties = new HashSet<>(); if (includeUserProperties) { UserProperty property1 = new UserProperty(); property1.setSystemName("test type"); property1.setValue("T100 ad92"); userProperties.add(property1);/*from w w w . j av a2s . c o m*/ UserProperty property2 = new UserProperty(); property2.setSystemName("run mode"); property2.setValue("AUTO i56 daily"); userProperties.add(property2); } return createCategory(name, description + " - " + dateTimeFormatter.print(currentTime), true, userProperties); }
From source file:com.thinkbiganalytics.util.JdbcCommon.java
License:Apache License
/** * Converts the specified SQL result set to a delimited text file written to the specified output stream. * * @param rs the SQL result set//w ww.ja va 2 s .c o m * @param outStream the output stream for the delimited text file * @param visitor records position of the result set * @param delimiter the column delimiter for the delimited text file * @return the number of rows written * @throws SQLException if a SQL error occurs while reading the result set * @throws IOException if an I/O error occurs while writing to the output stream */ public static long convertToDelimitedStream(final ResultSet rs, final OutputStream outStream, final RowVisitor visitor, String delimiter) throws SQLException, IOException { // avoid overflowing log with redundant messages int dateConversionWarning = 0; if (rs == null || rs.getMetaData() == null) { log.warn("Received empty resultset or no metadata."); return 0; } OutputStreamWriter writer = new OutputStreamWriter(outStream); final ResultSetMetaData meta = rs.getMetaData(); final DelimiterEscaper escaper = new DelimiterEscaper(delimiter); // Write header final int nrOfColumns = meta.getColumnCount(); StringBuffer sb = new StringBuffer(); for (int i = 1; i <= nrOfColumns; i++) { String columnName = meta.getColumnName(i); sb.append(escaper.translate(columnName)); if (i != nrOfColumns) { sb.append(delimiter); } else { sb.append("\n"); } } writer.append(sb.toString()); long nrOfRows = 0; while (rs.next()) { if (visitor != null) { visitor.visitRow(rs); } sb = new StringBuffer(); nrOfRows++; for (int i = 1; i <= nrOfColumns; i++) { String val = null; int colType = meta.getColumnType(i); if (colType == Types.DATE || colType == Types.TIMESTAMP) { Timestamp sqlDate = null; try { // Extract timestamp sqlDate = extractSqlDate(rs, i); } catch (Exception e) { // Still failed, maybe exotic date type if (dateConversionWarning++ < 10) { log.warn("{} is not convertible to timestamp or date", rs.getMetaData().getColumnName(i)); } } if (visitor != null) { visitor.visitColumn(rs.getMetaData().getColumnName(i), colType, sqlDate); } if (sqlDate != null) { DateTimeFormatter formatter = ISODateTimeFormat.dateTime().withZoneUTC(); val = formatter.print(new DateTime(sqlDate.getTime())); } } else if (colType == Types.TIME) { Time time = rs.getTime(i); if (visitor != null) { visitor.visitColumn(rs.getMetaData().getColumnName(i), colType, time); } if (time != null) { DateTimeFormatter formatter = ISODateTimeFormat.time().withZoneUTC(); val = formatter.print(new DateTime(time.getTime())); } } else if (colType == Types.BLOB) { byte[] bytes = rs.getBytes(i); if (bytes != null) val = rs.getBytes(i).toString(); if (visitor != null) { visitor.visitColumn(rs.getMetaData().getColumnName(i), colType, val); } } else { val = rs.getString(i); if (visitor != null) { visitor.visitColumn(rs.getMetaData().getColumnName(i), colType, val); } } sb.append((val == null ? "" : escaper.translate(val))); if (i != nrOfColumns) { sb.append(delimiter); } else { sb.append("\n"); } } writer.append(sb.toString()); } writer.flush(); return nrOfRows; }
From source file:com.thinkbiganalytics.util.JdbcCommon.java
License:Apache License
public static long convertToAvroStream(final ResultSet rs, final OutputStream outStream, final RowVisitor visitor, final Schema schema) throws SQLException, IOException { int dateConversionWarning = 0; final GenericRecord rec = new GenericData.Record(schema); final DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<>(schema); try (final DataFileWriter<GenericRecord> dataFileWriter = new DataFileWriter<>(datumWriter)) { dataFileWriter.create(schema, outStream); final ResultSetMetaData meta = rs.getMetaData(); final int nrOfColumns = meta.getColumnCount(); long nrOfRows = 0; while (rs.next()) { if (visitor != null) { visitor.visitRow(rs);/*from w ww . j a va2 s.c om*/ } for (int i = 1; i <= nrOfColumns; i++) { final int javaSqlType = meta.getColumnType(i); final Object value = rs.getObject(i); if (value == null) { rec.put(i - 1, null); } else if (javaSqlType == BINARY || javaSqlType == VARBINARY || javaSqlType == LONGVARBINARY || javaSqlType == ARRAY || javaSqlType == BLOB || javaSqlType == CLOB) { // bytes requires little bit different handling byte[] bytes = rs.getBytes(i); ByteBuffer bb = ByteBuffer.wrap(bytes); rec.put(i - 1, bb); } else if (value instanceof Byte) { // tinyint(1) type is returned by JDBC driver as java.sql.Types.TINYINT // But value is returned by JDBC as java.lang.Byte // (at least H2 JDBC works this way) // direct put to avro record results: // org.apache.avro.AvroRuntimeException: Unknown datum type java.lang.Byte rec.put(i - 1, ((Byte) value).intValue()); } else if (value instanceof BigDecimal || value instanceof BigInteger) { // Avro can't handle BigDecimal and BigInteger as numbers - it will throw an AvroRuntimeException such as: "Unknown datum type: java.math.BigDecimal: 38" rec.put(i - 1, value.toString()); } else if (value instanceof Number || value instanceof Boolean) { rec.put(i - 1, value); } else if (value instanceof Date) { final DateTimeFormatter formatter = ISODateTimeFormat.dateTime().withZoneUTC(); rec.put(i - 1, formatter.print(new DateTime(((Date) value).getTime()))); } else if (value instanceof Time) { final DateTimeFormatter formatter = ISODateTimeFormat.time().withZoneUTC(); rec.put(i - 1, formatter.print(new DateTime(((Time) value).getTime()))); } else if (value instanceof Timestamp) { final DateTimeFormatter formatter = ISODateTimeFormat.dateTime().withZoneUTC(); rec.put(i - 1, formatter.print(new DateTime(((Timestamp) value).getTime()))); } else { // The different types that we support are numbers (int, long, double, float), // as well as boolean values and Strings. Since Avro doesn't provide // timestamp types, we want to convert those to Strings. So we will cast anything other // than numbers or booleans to strings by using the toString() method. rec.put(i - 1, value.toString()); } //notify the visitor if (javaSqlType == Types.DATE || javaSqlType == Types.TIMESTAMP) { Timestamp sqlDate = null; try { // Extract timestamp sqlDate = extractSqlDate(rs, i); } catch (Exception e) { if (dateConversionWarning++ < 10) { log.warn("{} is not convertible to timestamp or date", rs.getMetaData().getColumnName(i)); } } if (visitor != null) { visitor.visitColumn(rs.getMetaData().getColumnName(i), javaSqlType, sqlDate); } } else if (javaSqlType == Types.TIME) { Time time = rs.getTime(i); if (visitor != null) { visitor.visitColumn(rs.getMetaData().getColumnName(i), javaSqlType, time); } } else { if (visitor != null) { visitor.visitColumn(rs.getMetaData().getColumnName(i), javaSqlType, (value != null) ? value.toString() : null); } } } dataFileWriter.append(rec); nrOfRows += 1; } return nrOfRows; } }
From source file:com.thoughtworks.studios.shine.cruise.ZuluDateTimeFormatter.java
License:Apache License
public static String toZuluString(DateTime dateTime) { DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"); return format.print(dateTime.toDateTime(DateTimeZone.forID("UTC"))); }
From source file:com.tkmtwo.timex.DateTimeFields.java
License:Apache License
public String roundFloorString(DateTimeFormatter dateTimeFormatter, DateTime dateTime) { return dateTimeFormatter.print(roundFloor(dateTime)); }
From source file:com.tkmtwo.timex.DateTimeFields.java
License:Apache License
public String roundFloorAddString(DateTimeFormatter dateTimeFormatter, DateTime dateTime, int i) { return dateTimeFormatter.print(roundFloorAdd(dateTime, i)); }
From source file:com.tkmtwo.timex.DateTimeFields.java
License:Apache License
public String roundCeilingString(DateTimeFormatter dateTimeFormatter, DateTime dateTime) { return dateTimeFormatter.print(roundCeiling(dateTime)); }
From source file:com.tkmtwo.timex.DateTimeFields.java
License:Apache License
public String roundCeilingAddString(DateTimeFormatter dateTimeFormatter, DateTime dateTime, int i) { return dateTimeFormatter.print(roundCeilingAdd(dateTime, i)); }