@Test(expected = IllegalArgumentException.class) public void testFormatNegativeDurationWords() throws Exception { DurationFormatUtils.formatDurationWords(-5000, true, true); }
text = DurationFormatUtils.formatDurationWords(oneSecond, false, false); assertEquals("0 days 0 hours 0 minutes 1 second", text); text = DurationFormatUtils.formatDurationWords(oneSecond * 2, false, false); assertEquals("0 days 0 hours 0 minutes 2 seconds", text); text = DurationFormatUtils.formatDurationWords(oneSecond * 11, false, false); assertEquals("0 days 0 hours 0 minutes 11 seconds", text); text = DurationFormatUtils.formatDurationWords(oneMinute, false, false); assertEquals("0 days 0 hours 1 minute 0 seconds", text); text = DurationFormatUtils.formatDurationWords(oneMinute * 2, false, false); assertEquals("0 days 0 hours 2 minutes 0 seconds", text); text = DurationFormatUtils.formatDurationWords(oneMinute * 11, false, false); assertEquals("0 days 0 hours 11 minutes 0 seconds", text); text = DurationFormatUtils.formatDurationWords(oneMinute + oneSecond, false, false); assertEquals("0 days 0 hours 1 minute 1 second", text); text = DurationFormatUtils.formatDurationWords(oneHour, false, false); assertEquals("0 days 1 hour 0 minutes 0 seconds", text); text = DurationFormatUtils.formatDurationWords(oneHour * 2, false, false); assertEquals("0 days 2 hours 0 minutes 0 seconds", text); text = DurationFormatUtils.formatDurationWords(oneHour * 11, false, false); assertEquals("0 days 11 hours 0 minutes 0 seconds", text); text = DurationFormatUtils.formatDurationWords(oneHour + oneMinute + oneSecond, false, false); assertEquals("0 days 1 hour 1 minute 1 second", text); text = DurationFormatUtils.formatDurationWords(oneDay, false, false); assertEquals("1 day 0 hours 0 minutes 0 seconds", text); text = DurationFormatUtils.formatDurationWords(oneDay * 2, false, false); assertEquals("2 days 0 hours 0 minutes 0 seconds", text);
text = DurationFormatUtils.formatDurationWords(50 * 1000, true, false); assertEquals("50 seconds", text); text = DurationFormatUtils.formatDurationWords(65 * 1000, true, false); assertEquals("1 minute 5 seconds", text); text = DurationFormatUtils.formatDurationWords(120 * 1000, true, false); assertEquals("2 minutes 0 seconds", text); text = DurationFormatUtils.formatDurationWords(121 * 1000, true, false); assertEquals("2 minutes 1 second", text); text = DurationFormatUtils.formatDurationWords(72 * 60 * 1000, true, false); assertEquals("1 hour 12 minutes 0 seconds", text); text = DurationFormatUtils.formatDurationWords(24 * 60 * 60 * 1000, true, false); assertEquals("1 day 0 hours 0 minutes 0 seconds", text); text = DurationFormatUtils.formatDurationWords(50 * 1000, true, true); assertEquals("50 seconds", text); text = DurationFormatUtils.formatDurationWords(65 * 1000, true, true); assertEquals("1 minute 5 seconds", text); text = DurationFormatUtils.formatDurationWords(120 * 1000, true, true); assertEquals("2 minutes", text); text = DurationFormatUtils.formatDurationWords(121 * 1000, true, true); assertEquals("2 minutes 1 second", text); text = DurationFormatUtils.formatDurationWords(72 * 60 * 1000, true, true); assertEquals("1 hour 12 minutes", text); text = DurationFormatUtils.formatDurationWords(24 * 60 * 60 * 1000, true, true); assertEquals("1 day", text); text = DurationFormatUtils.formatDurationWords(50 * 1000, false, true); assertEquals("0 days 0 hours 0 minutes 50 seconds", text); text = DurationFormatUtils.formatDurationWords(65 * 1000, false, true);
public static String formatDuration(long timeInMiliseconds) { return DurationFormatUtils.formatDurationWords(timeInMiliseconds, true, true); }
public static String formatDuration(long timeInMiliseconds) { return DurationFormatUtils.formatDurationWords(timeInMiliseconds, true, true); }
@Override public void describeTo(Description description) { description.appendText(formatDurationWords(timeout, true, true)); } }
private String calculateUptime() { long different = System.currentTimeMillis() - startTimestamp; return DurationFormatUtils.formatDurationWords(different, false, false); }
public String getPerdiodFromStart(Long datetime) { if (datetime == null) { return ""; } return DurationFormatUtils.formatDurationWords( this.profile.getStart() - datetime, true, true); } }
@Override public void start(Stage primaryStage) { this.primaryStage = primaryStage; injector = initInjector(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionLogger()); initSejda(); cleanIfRequired(); primaryStage.setScene(initScene()); primaryStage.getIcons().addAll(injector.instancesOfType(Image.class)); primaryStage.setTitle(injector.instance(Pdfsam.class).name()); primaryStage.setOnCloseRequest(e -> Platform.exit()); requestPremiumModulesDescriptionIfRequired(); initWindowsStatusController(primaryStage); initDialogsOwner(primaryStage); initActiveModule(); loadWorkspaceIfRequired(); initOpenButtons(); primaryStage.show(); requestCheckForUpdateIfRequired(); requestLatestNewsIfRequired(); eventStudio().addAnnotatedListeners(this); closeSplash(); STOPWATCH.stop(); LOG.info(DefaultI18nContext.getInstance().i18n("Started in {0}", DurationFormatUtils.formatDurationWords(STOPWATCH.getTime(), true, true))); new InputPdfArgumentsController().accept(rawParameters); }
static void appendDeadlineInformation(StringBuilder sb, AbstractWorkItemType workItem, TextFormatter textFormatter) { XMLGregorianCalendar deadline = workItem.getDeadline(); long before = XmlTypeConverter.toMillis(deadline) - System.currentTimeMillis(); long beforeRounded = Math.round((double) before / 60000.0) * 60000L; String beforeWords = DurationFormatUtils.formatDurationWords(Math.abs(beforeRounded), true, true); String beforePhrase; if (beforeRounded > 0) { beforePhrase = " (in " + beforeWords + ")"; } else if (beforeRounded < 0) { beforePhrase = " (" + beforeWords + " ago)"; } else { beforePhrase = ""; } sb.append("Deadline: ").append(textFormatter.formatDateTime(deadline)).append(beforePhrase).append("\n"); sb.append("\n"); }
public void taskEnded() { stopWatch.stop(); LOG.info("Task ({}) executed in {}", task, DurationFormatUtils.formatDurationWords(stopWatch.getTime(), true, true)); }
public void taskEnded() { stopWatch.stop(); LOG.info("Task ({}) executed in {}", task, DurationFormatUtils.formatDurationWords(stopWatch.getTime(), true, true)); }
/** * Update progress bar and estimated time. * * @param progress * current progress. */ public void setProgress(SyncManager.Progress progress) { syncProgressBar.setValue( (int) Math.round((double) progress.getCurrentHeight() / (double) progress.getTargetHeight() * 10000d)); Duration estimation = progress.getSyncEstimation(); if (estimation != null && estimation.getSeconds() > 0L) { syncProgressBar.setString(String.format( "%s (%s)", SyncProgressFormatter.format(progress), // TODO: localize estimation estimation.toDays() >= 30 ? ">= 1 month" : DurationFormatUtils.formatDurationWords( estimation.toMillis(), true, true))); } else { syncProgressBar.setString(SyncProgressFormatter.format(progress)); } }
private void repairComplete() { String duration = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - startTime, true, true); String message = String.format("Repair command #%d finished in %s", cmd, duration); fireProgressEvent(tag, new ProgressEvent(ProgressEventType.COMPLETE, progress.get(), totalProgress, message)); logger.info(message); if (options.isTraced() && traceState != null) { for (ProgressListener listener : listeners) traceState.removeProgressListener(listener); // Because DebuggableThreadPoolExecutor#afterExecute and this callback // run in a nondeterministic order (within the same thread), the // TraceState may have been nulled out at this point. The TraceState // should be traceState, so just set it without bothering to check if it // actually was nulled out. Tracing.instance.set(traceState); Tracing.traceRepair(message); Tracing.instance.stopSession(); } executor.shutdownNow(); } });
private void repairComplete() { String duration = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - startTime, true, true); String message = String.format("Repair command #%d finished in %s", cmd, duration); fireProgressEvent(tag, new ProgressEvent(ProgressEventType.COMPLETE, progress.get(), totalProgress, message)); logger.info(message); if (options.isTraced() && traceState != null) { for (ProgressListener listener : listeners) traceState.removeProgressListener(listener); // Because DebuggableThreadPoolExecutor#afterExecute and this callback // run in a nondeterministic order (within the same thread), the // TraceState may have been nulled out at this point. The TraceState // should be traceState, so just set it without bothering to check if it // actually was nulled out. Tracing.instance.set(traceState); Tracing.traceRepair(message); Tracing.instance.stopSession(); } executor.shutdownNow(); } });
private void repairComplete() { String duration = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - startTime, true, true); String message = String.format("Repair command #%d finished in %s", cmd, duration); fireProgressEvent(tag, new ProgressEvent(ProgressEventType.COMPLETE, progress.get(), totalProgress, message)); logger.info(message); if (options.isTraced() && traceState != null) { for (ProgressListener listener : listeners) traceState.removeProgressListener(listener); // Because DebuggableThreadPoolExecutor#afterExecute and this callback // run in a nondeterministic order (within the same thread), the // TraceState may have been nulled out at this point. The TraceState // should be traceState, so just set it without bothering to check if it // actually was nulled out. Tracing.instance.set(traceState); Tracing.traceRepair(message); Tracing.instance.stopSession(); } executor.shutdownNow(); } });
private void scheduleTask(TaskRuntimeInformation runtimeInformation, boolean runNow) { HydraTask task = runtimeInformation.getMethod().getAnnotation(HydraTask.class); if (!taskSchedules.containsKey(task.name())) { //On startup logger.info("Scheduling task \"{}\" to be run every {}", task.name(), DurationFormatUtils.formatDurationWords(getIntervalForTask(task), true, true)); } Runnable runnable = new ScheduledMethodRunnable(runtimeInformation.getBean(), runtimeInformation.getMethod()); if (runNow) { scheduler.execute(runnable); } ScheduledFuture scheduledTask = scheduler.schedule(runnable, new Trigger() { @Override public Date nextExecutionTime(TriggerContext triggerContext) { Calendar nextExecutionTime = new GregorianCalendar(); Date lastCompletionTime = runNow ? new Date() : triggerContext.lastCompletionTime(); nextExecutionTime.setTime(lastCompletionTime != null ? lastCompletionTime : new Date()); nextExecutionTime.add(Calendar.MILLISECOND, (int) getIntervalForTask(task)); taskInformations.put(task, new TaskInformation(task.name(), lastCompletionTime != null ? lastCompletionTime.toInstant() : null, nextExecutionTime.toInstant())); return nextExecutionTime.getTime(); } }); taskSchedules.put(task.name(), scheduledTask); }
@Listener public void onServerStarting(GameStartingServerEvent event) { EXTENT_BUFFER_FACTORY = Sponge.getRegistry().getExtentBufferFactory(); Sponge.getCommandManager().register(this.instance, new Commands(), "testsuite"); this.logger.info("Running test suite..."); final Result result = runTests(); this.logger.info("Ran {} test(s), ignored {} test(s), took {}", result.getRunCount(), result.getIgnoreCount(), DurationFormatUtils.formatDurationWords(result.getRunTime(), true, true)); if (result.getFailureCount() > 0) { this.logger.warn("Failed {} test(s)", result.getFailureCount()); for (Failure failure : result.getFailures()) { this.logger.warn(failure.toString()); this.logger.warn(failure.getTrace()); } } if (result.wasSuccessful()) { this.logger.info("Success"); } else { this.logger.warn("Failure"); } }
rv += " in " + DurationFormatUtils.formatDurationWords( event.getTimeBefore().getTimeInMillis(new Date()), true, true);
@Override public CommandResult process(CommandSource source, String arguments) { source.sendMessage(Text.of("Running test suite...")); final Result result = runTests(); source.sendMessage(Text.of("Ran ", result.getRunCount(), " test(s), ignored ", result.getIgnoreCount(), " test(s), took ", DurationFormatUtils.formatDurationWords(result.getRunTime(), true, true))); if (result.getFailureCount() > 0) { source.sendMessage(Text.of(TextColors.DARK_RED, "Failed ", result.getFailureCount(), " test(s)")); source.sendMessage(Text.of(TextColors.DARK_RED, "See console for stack traces")); for (Failure failure : result.getFailures()) { source.sendMessage(Text.of(TextColors.DARK_RED, failure.toString())); TestSuite.this.logger.warn(failure.getTrace()); } } if (result.wasSuccessful()) { source.sendMessage(Text.of("Success")); } else { source.sendMessage(Text.of(TextColors.DARK_RED, "Failure")); } return CommandResult.success(); }