@@ -55,7 +55,7 @@ public Controller(final Model model, final DateProvider dateProvider) {
5555 this .dateProvider = dateProvider ;
5656
5757 // initiate quicksaving
58- new Interval (QUICK_SAVE_INTERVAL ).registerCallBack (() -> saveCurrentWork (0 ));
58+ new Interval (QUICK_SAVE_INTERVAL ).registerCallBack (() -> saveCurrentWork (dateProvider . dateTimeNow () ));
5959 }
6060
6161 public void changeProject (final Project newProject ) {
@@ -65,26 +65,23 @@ public void changeProject(final Project newProject) {
6565 public void changeProject (final Project newProject , final long minusSeconds ) {
6666
6767 final LocalDateTime now = dateProvider .dateTimeNow ().minusSeconds (minusSeconds );
68- final LocalDate dateNow = now .toLocalDate ();
6968
70- saveCurrentWork (minusSeconds );
69+ saveCurrentWork (now );
7170
7271 // Start new work
73- final Work work = new Work (dateNow , now , now .plusSeconds (minusSeconds ), newProject , "" );
72+ final Work work = new Work (now . toLocalDate () , now , now .plusSeconds (minusSeconds ), newProject , "" );
7473
7574 model .getPastWorkItems ().add (work );
7675
7776 model .activeWorkItem .set (work );
7877 }
7978
80- public void saveCurrentWork (final long minusSeconds ) {
79+ public void saveCurrentWork (final LocalDateTime now ) {
8180 final Work currentWork = model .activeWorkItem .get ();
8281
8382 if (currentWork == null ) {
8483 return ;
8584 }
86- final LocalDateTime now = dateProvider .dateTimeNow ().minusSeconds (minusSeconds );
87- final LocalDate dateNow = now .toLocalDate ();
8885
8986 currentWork .setEndTime (now );
9087 if (currentWork .getNotes ().isEmpty ()) {
@@ -100,10 +97,10 @@ public void saveCurrentWork(final long minusSeconds) {
10097 // Save in db
10198 model .getWorkRepository ().save (currentWork );
10299
103- if (currentWork != null && !dateNow .isEqual (currentWork .getCreationDate ())) {
104- LOG .info ("Removing projects with other creation date than today '{}' from list." , dateNow );
100+ if (currentWork != null && !now . toLocalDate () .isEqual (currentWork .getCreationDate ())) {
101+ LOG .info ("Removing projects with other creation date than today '{}' from list." , now . toLocalDate () );
105102 final int sizeBefore = model .getPastWorkItems ().size ();
106- model .getPastWorkItems ().removeIf (w -> !dateNow .isEqual (w .getCreationDate ()));
103+ model .getPastWorkItems ().removeIf (w -> !now . toLocalDate () .isEqual (w .getCreationDate ()));
107104 LOG .debug ("Removed '{}' work items from past work items." , sizeBefore - model .getPastWorkItems ().size ());
108105 }
109106 }
@@ -153,7 +150,7 @@ public void updateSettings(final Color hoverBackgroundColor, final Color hoverFo
153150 @ PreDestroy
154151 public void shutdown () {
155152 LOG .info ("Controller shutdown" );
156- saveCurrentWork (0 );
153+ saveCurrentWork (dateProvider . dateTimeNow () );
157154 }
158155
159156 public void deleteProject (final Project p ) {
0 commit comments