Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Work saveCurrentWork(final LocalDateTime workEnd) {
currentWork.setEndTime(workEnd);

final String time = DateFormatter
.secondsToHHMMSS(Duration.between(currentWork.getStartTime(), currentWork.getEndTime()).getSeconds());
.secondsToHHMMSS(DateFormatter.getSecondsBewtween(currentWork.getStartTime(), currentWork.getEndTime()));

LOG.info("Saving Work from '{}' to '{}' ({}) on project '{}' with notes '{}'", currentWork.getStartTime(),
currentWork.getEndTime(), time, currentWork.getProject().getName(), currentWork.getNotes());
Expand Down Expand Up @@ -350,7 +350,7 @@ public long calcSeconds(final List<Work> workItems) {
long seconds = 0;

for (final Work w : workItems) {
seconds += Duration.between(w.getStartTime(), w.getEndTime()).getSeconds();
seconds += DateFormatter.getSecondsBewtween(w.getStartTime(), w.getEndTime());
}

return seconds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.time.Duration;
import java.util.List;

import de.doubleslash.keeptime.common.DateFormatter;
import de.doubleslash.keeptime.model.Work;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
Expand All @@ -40,7 +41,7 @@ public void update(final List<Work> workItems, final long seconds) {
gc.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
double currentX = 0;
for (final Work w : workItems) {
final long workedSeconds = Duration.between(w.getStartTime(), w.getEndTime()).getSeconds();
final long workedSeconds = DateFormatter.getSecondsBewtween(w.getStartTime(), w.getEndTime());
final double width = (double) workedSeconds / seconds * canvas.getWidth();
final Color fill = w.getProject().getColor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void tick() {
final Label label = entry.getValue();

final long seconds = model.getPastWorkItems().stream().filter(work -> work.getProject().getId() == p.getId())
.mapToLong(work -> Duration.between(work.getStartTime(), work.getEndTime()).getSeconds()).sum();
.mapToLong(work -> DateFormatter.getSecondsBewtween(work.getStartTime(), work.getEndTime())).sum();
label.setText(DateFormatter.secondsToHHMMSS(seconds));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,7 @@ private void initialize() {
final LocalDateTime now = LocalDateTime.now();
model.activeWorkItem.get().setEndTime(now); // FIXME not good to change model

final long currentWorkSeconds = Duration
.between(model.activeWorkItem.get().getStartTime(), model.activeWorkItem.get().getEndTime())
.getSeconds();
final long currentWorkSeconds = DateFormatter.getSecondsBewtween(model.activeWorkItem.get().getStartTime(), model.activeWorkItem.get().getEndTime());
activeWorkSecondsProperty.set(currentWorkSeconds);
final long todayWorkingSeconds = controller.calcTodaysWorkSeconds();
final long todaySeconds = controller.calcTodaysSeconds();
Expand Down
25 changes: 15 additions & 10 deletions src/test/java/de/doubleslash/keeptime/common/DateFormatterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,31 @@

package de.doubleslash.keeptime.common;

import static org.junit.Assert.assertThat;

import java.time.LocalDateTime;

import static org.hamcrest.MatcherAssert.assertThat;
import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Test;

@Ignore

public class DateFormatterTest {

@Test
public void zeroSecondsBetweenTest() {
public void durationShouldBePositiveWhenStartBeforeEndDate() {
final LocalDateTime startDate = LocalDateTime.now();
final LocalDateTime endDate = startDate.plusNanos(10000);
final LocalDateTime endDate = startDate.plusSeconds(10);

final long secondsBewtween = DateFormatter.getSecondsBewtween(startDate, endDate);
assertThat(secondsBewtween, Matchers.is(0l));

final long secondsBewtweenSwitched = DateFormatter.getSecondsBewtween(endDate, startDate);
assertThat(secondsBewtweenSwitched, Matchers.is(0l)); // why??
assertThat(secondsBewtween, Matchers.is(10l));
}

@Test
public void durationShouldBePositiveWhenEndBeforeStartDate() {
final LocalDateTime startDate = LocalDateTime.now();
final LocalDateTime endDate = startDate.plusSeconds(10);


final long secondsBewtweenSwitched = DateFormatter.getSecondsBewtween(endDate, startDate);
assertThat(secondsBewtweenSwitched, Matchers.is(10l));
}
}