List of usage examples for java.time LocalDateTime minusNanos
public LocalDateTime minusNanos(long nanos)
From source file:net.resheim.eclipse.timekeeper.ui.Activator.java
/** * * @return/*from w w w.j av a 2s .c o m*/ */ public LocalDateTime getIdleSince() { ITask task = TasksUi.getTaskActivityManager().getActiveTask(); if (task != null && Activator.getValue(task, Activator.START) != null) { String tickString = Activator.getValue(task, Activator.TICK); LocalDateTime ticked = LocalDateTime.parse(tickString); ticked = ticked.minusNanos(IDLE_INTERVAL); return ticked; } return null; }
From source file:net.resheim.eclipse.timekeeper.ui.Activator.java
/** * Must be called by the UI-thread/*from ww w. ja v a 2 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()); } } } } }