List of usage examples for org.apache.commons.lang.time DurationFormatUtils formatDuration
public static String formatDuration(long durationMillis, String format)
Formats the time gap as a string, using the specified format, and padding with zeros and using the default timezone.
This method formats durations using the days and lower fields of the format pattern.
From source file:org.jboss.tools.openshift.internal.common.ui.utils.DateTimeUtils.java
public static String formatDuration(long nanoseconds) { String[] parts = DurationFormatUtils.formatDuration(nanoseconds / NANOSECONDS_PER_SEC, "H:m:s:S") .split(":"); StringBuilder builder = new StringBuilder(); if (Integer.valueOf(parts[0]) > 0) { builder.append(parts[0]).append(" hrs."); }/*from w ww . j a v a 2 s .c o m*/ if (Integer.valueOf(parts[1]) > 0) { builder.append(" ").append(parts[1]).append(" min."); } if (Integer.valueOf(parts[2]) > 0) { builder.append(" ").append(parts[2]).append(" sec."); } if (builder.length() == 0) { builder.append("Now"); } return builder.toString().trim(); }
From source file:org.magdaaproject.analysis.rhizome.tasks.StatisticalAnalysis.java
private String getMaxTimeDelayBeforeFirstCopy() throws TaskException { StringBuilder builder = new StringBuilder(); builder.append("SELECT MAX(time_difference) "); builder.append("FROM (SELECT " + tableName + ".file_id, MIN(" + tableName + ".file_insert_time), table_01.file_insert_time, MIN(" + tableName + ".file_insert_time) - table_01.file_insert_time AS time_difference "); builder.append("FROM " + tableName + ", (SELECT file_id, file_insert_time FROM " + tableName + " WHERE origin = 'y' AND file_insert_time IS NOT NULL) AS table_01 "); builder.append("WHERE table_01.file_id = " + tableName + ".file_id "); builder.append("AND table_01.file_insert_time <> " + tableName + ".file_insert_time "); builder.append("AND " + tableName + ".file_insert_time IS NOT NULL "); builder.append("GROUP BY " + tableName + ".file_id) as table_02"); return DurationFormatUtils.formatDuration(Long.parseLong(executeSql(builder.toString())), "H:m:s") + " (H:m:s)\n"; }
From source file:org.magdaaproject.analysis.rhizome.tasks.StatisticalAnalysis.java
private String getMinTimeDelayBeforeFirstCopy() throws TaskException { StringBuilder builder = new StringBuilder(); builder.append("SELECT MIN(time_difference) "); builder.append("FROM (SELECT " + tableName + ".file_id, MIN(" + tableName + ".file_insert_time), table_01.file_insert_time, MIN(" + tableName + ".file_insert_time) - table_01.file_insert_time AS time_difference "); builder.append("FROM " + tableName + ", (SELECT file_id, file_insert_time FROM " + tableName + " WHERE origin = 'y' AND file_insert_time IS NOT NULL) AS table_01 "); builder.append("WHERE table_01.file_id = " + tableName + ".file_id "); builder.append("AND table_01.file_insert_time <> " + tableName + ".file_insert_time "); builder.append("AND " + tableName + ".file_insert_time IS NOT NULL "); builder.append("GROUP BY " + tableName + ".file_id) as table_02 "); builder.append("WHERE time_difference > 0"); return DurationFormatUtils.formatDuration(Long.parseLong(executeSql(builder.toString())), "H:m:s") + " (H:m:s)\n"; }
From source file:org.onehippo.forge.content.exim.repository.jaxrs.ContentEximProcessStatusService.java
@Path("/") @Produces(MediaType.TEXT_PLAIN)// ww w . ja va 2 s . c o m @GET public String getAllProcessInfos() { StringWriter sw = new StringWriter(1024); PrintWriter out = new PrintWriter(sw); printProcessStatusReportHeader(out); if (getProcessMonitor() != null) { List<ProcessStatus> processes = getProcessMonitor().getProcesses(); for (ProcessStatus process : processes) { final long startTime = process.getStartTimeMillis(); final long duration = System.currentTimeMillis() - startTime; out.printf("%8s %5d %15s %8s %8s %1.2f %s\r\n", process.getUsername(), process.getId(), process.getClientInfo(), timeFormat.format(startTime), DurationFormatUtils.formatDuration(duration, "HH:mm:ss"), process.getProgress(), process.getCommandInfo()); } } printProcessStatusReportFooter(out); return sw.toString(); }
From source file:org.onehippo.forge.content.exim.repository.jaxrs.ContentEximProcessStatusService.java
private void printProcessStatus(PrintWriter out, ProcessStatus process) { final long startTime = process.getStartTimeMillis(); final long duration = System.currentTimeMillis() - startTime; out.printf("%8s %5d %15s %8s %8s %1.2f %s\r\n", process.getUsername(), process.getId(), process.getClientInfo(), timeFormat.format(startTime), DurationFormatUtils.formatDuration(duration, "HH:mm:ss"), process.getProgress(), process.getCommandInfo());/*from w w w . j a va2 s .c om*/ }
From source file:org.opencastproject.index.service.catalog.adapter.MetadataField.java
public static MetadataField<String> createDurationMetadataField(String inputID, Opt<String> outputID, String label, boolean readOnly, boolean required, Opt<Map<String, Object>> collection, Opt<String> collectionId, Opt<Integer> order, Opt<String> namespace) { Fn<Opt<String>, JValue> periodToJSON = new Fn<Opt<String>, JValue>() { @Override//from w w w . j a v a 2s . c om public JValue ap(Opt<String> value) { Long returnValue = 0L; DCMIPeriod period = EncodingSchemeUtils.decodePeriod(value.get()); if (period != null && period.hasStart() && period.hasEnd()) { returnValue = period.getEnd().getTime() - period.getStart().getTime(); } else { try { returnValue = Long.parseLong(value.get()); } catch (NumberFormatException e) { logger.debug("Unable to parse duration '{}' as either period or millisecond duration.", value.get()); } } return v(DurationFormatUtils.formatDuration(returnValue, PATTERN_DURATION)); } }; Fn<Object, String> jsonToPeriod = new Fn<Object, String>() { @Override public String ap(Object value) { if (!(value instanceof String)) { logger.warn("The given value for duration can not be parsed."); return ""; } String duration = (String) value; String[] durationParts = duration.split(":"); if (durationParts.length < 3) return null; Integer hours = Integer.parseInt(durationParts[0]); Integer minutes = Integer.parseInt(durationParts[1]); Integer seconds = Integer.parseInt(durationParts[2]); Long returnValue = ((hours.longValue() * 60 + minutes.longValue()) * 60 + seconds.longValue()) * 1000; return returnValue.toString(); } }; return new MetadataField<String>(inputID, outputID, label, readOnly, required, "", TYPE.DURATION, JSON_TYPE.TEXT, collection, collectionId, periodToJSON, jsonToPeriod, order, namespace); }
From source file:org.ossmeter.metricprovider.historic.bugs.opentime.OpenTimeHistoricMetricProvider.java
@Override public Pongo measure(Project project) { BugsOpenTimeHistoricMetric avgBugOpenTime = new BugsOpenTimeHistoricMetric(); if (uses.size() == 1) { BugsBugMetadataTransMetric usedBhm = ((BugMetadataTransMetricProvider) uses.get(0)) .adapt(context.getProjectDB(project)); long seconds = 0; int durations = 0; for (BugData bugData : usedBhm.getBugData()) { if (!bugData.getLastClosedTime().equals("null")) { java.util.Date javaOpenTime = NntpUtil.parseDate(bugData.getCreationTime()); java.util.Date javaCloseTime = NntpUtil.parseDate(bugData.getLastClosedTime()); seconds += (Date.duration(javaOpenTime, javaCloseTime) / 1000); durations++;/*from w ww. ja va 2s .c om*/ } } long avgDuration = 0; if (durations > 0) avgDuration = seconds / durations; double daysReal = ((double) avgDuration) / SECONDS_DAY; avgBugOpenTime.setAvgBugOpenTimeInDays(daysReal); int days = (int) daysReal; long lessThanDay = (avgDuration % SECONDS_DAY); String formatted = DurationFormatUtils.formatDuration(lessThanDay * 1000, "HH:mm:ss:SS"); avgBugOpenTime.setAvgBugOpenTime(days + ":" + formatted); // System.out.println(days + ":" + formatted); avgBugOpenTime.setBugsConsidered(durations); } return avgBugOpenTime; }
From source file:org.ossmeter.metricprovider.historic.bugs.responsetime.ResponseTimeHistoricMetricProvider.java
private String format(long avgDuration) { String formatted = null;//from ww w . j a v a 2s . c o m if (avgDuration > 0) { int days = (int) (avgDuration / SECONDS_DAY); long lessThanDay = (avgDuration % SECONDS_DAY); formatted = days + ":" + DurationFormatUtils.formatDuration(lessThanDay * 1000, "HH:mm:ss:SS"); } else { formatted = 0 + ":" + DurationFormatUtils.formatDuration(0, "HH:mm:ss:SS"); } return formatted; }
From source file:org.ossmeter.metricprovider.trans.requestreplyclassification.RequestReplyClassificationTransMetricProvider.java
private String time(long timeInMS) { return DurationFormatUtils.formatDuration(timeInMS, "HH:mm:ss,SSS"); }
From source file:org.silverpeas.util.time.TimeData.java
/** * @see org.apache.commons.lang.time.DurationFormatUtils#formatDuration *//*from w w w . java 2 s .c o m*/ public String getFormattedDuration(String format) { return DurationFormatUtils.formatDuration(getTimeAsLong(), format); }