time calculations corrected
This commit is contained in:
@ -124,10 +124,14 @@ public class DoneBean implements Serializable, Comparable<DoneBean> {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String getTimeDiff() {
|
||||
public Duration getTimeDiffDuration() {
|
||||
LocalDateTime earlier = timeFrom != null ? timeFrom : LocalDateTime.now();
|
||||
LocalDateTime later = timeUntil != null ? timeUntil : LocalDateTime.now();
|
||||
Duration diff = Duration.between(earlier, later);
|
||||
return Duration.between(earlier, later);
|
||||
}
|
||||
|
||||
public String getTimeDiff() {
|
||||
Duration diff = getTimeDiffDuration();
|
||||
return String.format("%02d:%02d", diff.toHours(), diff.toMinutes() % 60);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.jottyfan.timetrack.spring.done;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
@ -39,10 +40,11 @@ public class DoneController {
|
||||
@RequestMapping(value = "/done/list")
|
||||
public String getList(@ModelAttribute DoneModel doneModel, Model model) {
|
||||
String username = doneService.getCurrentUser(request);
|
||||
Duration maxWorkTime = Duration.ofHours(8); // TODO: to the configuration file
|
||||
List<DoneBean> list = doneService.getList(doneModel.getDay(), username);
|
||||
model.addAttribute("doneList", list);
|
||||
model.addAttribute("doneModel", doneModel);
|
||||
model.addAttribute("sum", new SummaryBean(list));
|
||||
model.addAttribute("sum", new SummaryBean(list, doneModel.getDay(), maxWorkTime));
|
||||
model.addAttribute("projectList", doneService.getProjects());
|
||||
model.addAttribute("moduleList", doneService.getModules());
|
||||
model.addAttribute("jobList", doneService.getJobs());
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.jottyfan.timetrack.spring.done;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@ -13,37 +14,82 @@ import java.util.List;
|
||||
public class SummaryBean implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Duration maxDayWorktime;
|
||||
private final LocalDate day;
|
||||
private final List<DoneBean> list;
|
||||
|
||||
public SummaryBean(List<DoneBean> list) {
|
||||
public SummaryBean(List<DoneBean> list, LocalDate day, Duration maxDayWorktime) {
|
||||
this.list = list;
|
||||
this.day = day;
|
||||
this.maxDayWorktime = maxDayWorktime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the start
|
||||
*/
|
||||
public String getStart() {
|
||||
LocalDateTime found = LocalDate.now().atTime(23, 59);
|
||||
private LocalDateTime getStartTime() {
|
||||
LocalDateTime found = day.atTime(23, 59);
|
||||
for (DoneBean bean : list) {
|
||||
LocalDateTime ldt = bean.getTimeFrom();
|
||||
if (ldt != null && ldt.isBefore(found)) {
|
||||
found = ldt;
|
||||
}
|
||||
}
|
||||
return String.format("%02d:%02d", found.getHour(), found.getMinute() % 60);
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the end
|
||||
*/
|
||||
public String getEnd() {
|
||||
LocalDateTime found = LocalDate.now().atTime(0, 0);
|
||||
private LocalDateTime getEndTime() {
|
||||
LocalDateTime found = day.atTime(0, 0);
|
||||
for (DoneBean bean : list) {
|
||||
LocalDateTime ldt = bean.getTimeUntil();
|
||||
if (ldt != null && found.isBefore(ldt)) {
|
||||
if (ldt != null && ldt.isAfter(found)) {
|
||||
found = ldt;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* get sum of break times
|
||||
*
|
||||
* @return the sum of the break times; 0 at least
|
||||
*/
|
||||
private Duration getBreakTime() {
|
||||
LocalDateTime startTime = getStartTime();
|
||||
LocalDateTime endTime = getEndTime();
|
||||
Duration totalTime = getTotalTime();
|
||||
Duration dayTime = Duration.between(startTime, endTime);
|
||||
return dayTime.minus(totalTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return total time of the day as the summary of all work times of the day
|
||||
*/
|
||||
private Duration getTotalTime() {
|
||||
Duration duration = Duration.ZERO;
|
||||
for (DoneBean bean : list) {
|
||||
Duration current = bean.getTimeDiffDuration();
|
||||
duration = duration.plus(current);
|
||||
}
|
||||
return duration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the start time as formatted string
|
||||
*/
|
||||
public String getStart() {
|
||||
LocalDateTime found = getStartTime();
|
||||
return String.format("%02d:%02d", found.getHour(), found.getMinute() % 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the end time as formatted string
|
||||
*/
|
||||
public String getEnd() {
|
||||
LocalDateTime found = getEndTime();
|
||||
return String.format("%02d:%02d", found.getHour(), found.getMinute() % 60);
|
||||
}
|
||||
|
||||
@ -51,20 +97,27 @@ public class SummaryBean implements Serializable {
|
||||
* @return the total
|
||||
*/
|
||||
public String getTotal() {
|
||||
return "TODO";
|
||||
Duration total = getTotalTime();
|
||||
return String.format("%02d:%02d", total.toHours(), total.toMinutesPart());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the pause
|
||||
*/
|
||||
public String getPause() {
|
||||
return "TODO";
|
||||
Duration breakTime = getBreakTime();
|
||||
Long hours = breakTime.toHours();
|
||||
Integer minutes = breakTime.toMinutesPart();
|
||||
hours = hours < 0 ? 0 : hours;
|
||||
minutes = minutes < 0 ? 0 : minutes;
|
||||
return String.format("%02d:%02d", hours, minutes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the overdue
|
||||
*/
|
||||
public String getOverdue() {
|
||||
return "TODO";
|
||||
Duration overdue = getTotalTime().minus(maxDayWorktime);
|
||||
return String.format("%02d:%02d", overdue.toHours(), overdue.toMinutesPart());
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,8 @@
|
||||
<main layout:fragment="content">
|
||||
<div style="margin: 10vh">
|
||||
<div class="alert alert-danger" role="alert" style="vertical-align: middle; align: center">
|
||||
<p>Es ist ein Fehler aufgetreten.</p>
|
||||
<p>Es ist ein Fehler aufgetreten:</p>
|
||||
<p th:text="${message}" />
|
||||
<a th:href="@{/}" class="alert-link">Ach, Mist...</a>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user