List of usage examples for org.apache.commons.lang.time DurationFormatUtils formatDuration
public static String formatDuration(long durationMillis, String format, boolean padWithZeros)
Formats the time gap as a string, using the specified format.
From source file:com.sky8the2flies.KOTH.util.TimeParser.java
public static String parseToTimeFormat(String time) { int millis = (parseToSeconds(time) * 1000); return DurationFormatUtils.formatDuration(millis, "H:mm:ss", true); }
From source file:de.tor.tribes.util.report.AgeFilter.java
@Override public String getStringRepresentation() { return "Bericht lter als " + DurationFormatUtils.formatDuration(maxAge, "dd", false) + " Tag(e)"; }
From source file:net.resheim.eclipse.timekeeper.internal.TaskActivationListener.java
@Override public void preTaskActivated(ITask task) { LocalDateTime now = LocalDateTime.now(); String startString = Activator.getValue(task, Activator.START); String tickString = Activator.getValue(task, Activator.TICK); if (startString != null) { LocalDateTime ticked = LocalDateTime.parse(tickString); LocalDateTime stopped = LocalDateTime.now(); long seconds = ticked.until(stopped, ChronoUnit.SECONDS); String time = DurationFormatUtils.formatDuration(seconds * 1000, "H:mm", true); boolean confirm = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Add elapsed time?", "Work was already started and task was last updated on " + ticked.format(DateTimeFormatter.ofPattern("EEE e, HH:mm", Locale.US)) + ". Continue and add the elapsed time since (" + time + ") to the task total?"); if (confirm) { Activator.accumulateTime(task, startString, ticked.until(LocalDateTime.now(), ChronoUnit.MILLIS)); }/*from w ww.j av a 2 s. c o m*/ } Activator.setValue(task, Activator.TICK, now.toString()); Activator.setValue(task, Activator.START, now.toString()); }
From source file:net.resheim.eclipse.timekeeper.ui.views.ExportToClipboard.java
private void append(LocalDate firstDayOfWeek, StringBuilder sb, Object object) { if (object instanceof String) { sb.append("<tr style=\"background: #eeeeee;\"><td>"); sb.append(object);/* w ww . j a v a 2 s. c o m*/ for (int i = 0; i < 7; i++) { sb.append("</td><td style=\"text-align: right; border-left: 1px solid #aaa\">"); LocalDate weekday = firstDayOfWeek.plusDays(i); int seconds = getSum(provider.getFiltered(), weekday, (String) object); if (seconds > 60) { sb.append(DurationFormatUtils.formatDuration(seconds * 1000, "H:mm", true)); } } sb.append("</td></tr>"); } if (object instanceof WeeklySummary) { sb.append("<tr style=\"background: #dedede; border-top: 1px solid #aaa;\"><td>"); sb.append("Daily total"); for (int i = 0; i < 7; i++) { sb.append("</td><td style=\"text-align: right; border-left: 1px solid #aaa\">"); LocalDate weekday = firstDayOfWeek.plusDays(i); int seconds = getSum(provider.getFiltered(), weekday); if (seconds > 60) { sb.append(DurationFormatUtils.formatDuration(seconds * 1000, "H:mm", true)); } } sb.append("</td></tr>"); } if (object instanceof ITask) { sb.append("<tr><td> "); AbstractTask task = (AbstractTask) object; String taskKey = task.getTaskKey(); if (taskKey != null) { sb.append("<a href=\"" + task.getUrl() + "\">"); sb.append(taskKey); sb.append("</a>"); sb.append(": "); } sb.append(task.getSummary()); for (int i = 0; i < 7; i++) { sb.append("</td><td style=\"text-align: right; border-left: 1px solid #aaa\">"); LocalDate weekday = firstDayOfWeek.plusDays(i); int seconds = Activator.getActiveTime(task, weekday); if (seconds > 60) { sb.append(DurationFormatUtils.formatDuration(seconds * 1000, "H:mm", true)); } } sb.append("</td></tr>"); } sb.append(System.lineSeparator()); if (object instanceof String) { Object[] children = provider.getChildren(object); for (Object o : children) { append(firstDayOfWeek, sb, o); } } }
From source file:net.resheim.eclipse.timekeeper.ui.Activator.java
/** * Must be called by the UI-thread// w w w. j a v a2 s .c o m * * @param idleTimeMillis */ private void handleReactivation(long idleTimeMillis) { // We want only one dialog open. if (dialogIsOpen) { return; } synchronized (this) { if (idleTimeMillis < lastIdleTime && lastIdleTime > IDLE_INTERVAL) { // If we have an active task ITask task = TasksUi.getTaskActivityManager().getActiveTask(); if (task != null && Activator.getValue(task, Activator.START) != null) { dialogIsOpen = true; String tickString = Activator.getValue(task, Activator.TICK); LocalDateTime started = getActiveSince(); LocalDateTime ticked = LocalDateTime.parse(tickString); LocalDateTime lastTick = ticked; // Subtract the IDLE_INTERVAL time the computer _was_ // idle while counting up to the threshold. During this // period fields were updated. Thus must be adjusted for. ticked = ticked.minusNanos(IDLE_INTERVAL); String time = DurationFormatUtils.formatDuration(lastIdleTime, "H:mm:ss", true); StringBuilder sb = new StringBuilder(); if (task.getTaskKey() != null) { sb.append(task.getTaskKey()); sb.append(": "); } sb.append(task.getSummary()); MessageDialog md = new MessageDialog(Display.getCurrent().getActiveShell(), "Disregard idle time?", null, MessageFormat.format( "The computer has been idle since {0}, more than {1}. The active task \"{2}\" was started on {3}. Deactivate the task and disregard the idle time?", ticked.format(DateTimeFormatter.ofPattern("EEE e, HH:mm:ss", Locale.US)), time, sb.toString(), started.format(DateTimeFormatter.ofPattern("EEE e, HH:mm:ss", Locale.US))), MessageDialog.QUESTION, new String[] { "No", "Yes" }, 1); int open = md.open(); dialogIsOpen = false; if (open == 1) { // Stop task, subtract initial idle time TasksUi.getTaskActivityManager().deactivateTask(task); reduceTime(task, ticked.toLocalDate().toString(), IDLE_INTERVAL / 1000); } else { // Continue task, add idle time LocalDateTime now = LocalDateTime.now(); long seconds = lastTick.until(now, ChronoUnit.MILLIS); accumulateTime(task, ticked.toLocalDate().toString(), seconds); Activator.setValue(task, Activator.TICK, now.toString()); } } } } }
From source file:net.resheim.eclipse.timekeeper.ui.views.WorkWeekView.java
private void createTimeColumn(int weekday) { TreeViewerColumn column = createTableViewerColumn("-", 50, 1 + weekday); column.getColumn().setMoveable(false); column.getColumn().setAlignment(SWT.RIGHT); column.setEditingSupport(new TimeEditingSupport(column.getViewer(), weekday)); column.setLabelProvider(new ViewColumnLabelProvider() { @Override//from w ww . jav a2 s . c o m public String getText(Object element) { int seconds = 0; LocalDate date = contentProvider.getFirstDayOfWeek().plusDays(weekday); if (element instanceof String) { seconds = getSum(contentProvider.getFiltered(), date, (String) element); } else if (element instanceof ITask) { AbstractTask task = (AbstractTask) element; seconds = Activator.getActiveTime(task, getDate(weekday)); } else if (element instanceof WeeklySummary) { seconds = getSum(contentProvider.getFiltered(), date); } if (seconds > 0) { return DurationFormatUtils.formatDuration(seconds * 1000, "H:mm", true); } return ""; } }); }
From source file:net.resheim.eclipse.timekeeper.ui.views.WorkWeekView.java
private String getFormattedPeriod(int seconds) { if (seconds > 0) { return DurationFormatUtils.formatDuration(seconds * 1000, "H:mm", true); }/* w ww . j a v a 2s .c o m*/ return "0:00"; }
From source file:nz.ac.massey.cs.gql4jung.browser.ResultBrowser.java
private void updateComputationTime() { if (this.computationStarted == -1) { this.timeField.setText(""); } else {/*ww w . j a v a2s. c om*/ String dur = DurationFormatUtils.formatDuration(System.currentTimeMillis() - this.computationStarted, "H:m:s.S", true); this.timeField.setText(dur); } }
From source file:nz.ac.massey.cs.gql4jung.script.AnalysisBatchJob.java
public static void analyse(File querySource, final File graphSource, final String cursorLog) throws Exception { DirectedGraph<Vertex, Edge> graph = loadGraph(graphSource); Motif motif = loadMotif(querySource); if (graph.getVertices() == null) { log("Skipping ", graphSource.getName(), " - no vertices found"); return;// w ww .ja v a 2 s . c o m } QueryResults results = new QueryResults(); results.addListener(new QueryResultListener() { @Override public void progressMade(int progress, int total) { log(progress, "/", total, " done in ", graphSource.getName(), " ", cursorLog); } @Override public void resultsChanged(QueryResults source) { } }); log("Starting query ", querySource.getName(), " on data ", graphSource.getName()); // query GQL engine = new GQLImpl(); long before = System.currentTimeMillis(); engine.query(graph, motif, results, true); long after = System.currentTimeMillis(); log("Query finished, this took ", "" + (after - before), " ms"); // export results //QueryResultsExporter2CSV exporter = new QueryResultsExporter2CSV(); //File out = getOutputFile(querySource,graphSource); //exporter.export(results, out); //log("Query results exported to ",out.getAbsolutePath()); String time = DurationFormatUtils.formatDuration(after - before, "H:m:s.S", true); printSummary(querySource, graphSource, results, time, graph); results.reset(); // graphSource.delete(); }
From source file:org.kuali.rice.core.impl.datetime.DateTimeServiceImpl.java
public int dateDiff(Date startDate, Date endDate, boolean inclusive) { Calendar startDateCalendar = Calendar.getInstance(); startDateCalendar.setTime(startDate); Calendar endDateCalendar = Calendar.getInstance(); endDateCalendar.setTime(endDate);/*from ww w. j av a2 s . c o m*/ int startDateOffset = -(startDateCalendar.get(Calendar.ZONE_OFFSET) + startDateCalendar.get(Calendar.DST_OFFSET)) / (60 * 1000); int endDateOffset = -(endDateCalendar.get(Calendar.ZONE_OFFSET) + endDateCalendar.get(Calendar.DST_OFFSET)) / (60 * 1000); if (startDateOffset > endDateOffset) { startDateCalendar.add(Calendar.MINUTE, endDateOffset - startDateOffset); } if (inclusive) { startDateCalendar.add(Calendar.DATE, -1); } int dateDiff = Integer.parseInt(DurationFormatUtils.formatDuration( endDateCalendar.getTimeInMillis() - startDateCalendar.getTimeInMillis(), "d", true)); return dateDiff; }