fix: correctly cap worked hours calculation to current time

This commit is contained in:
Gabriel Menezes 2026-10-08 10:26:15 -04:00
parent ec9cf347ec
commit 5b0d1c6dea
3 changed files with 6 additions and 3 deletions

View file

@ -130,7 +130,8 @@ public class DashboardUseCase {
private long calculateMinutesInRange(TaskHistoryItem item, LocalDateTime start, LocalDateTime end) { private long calculateMinutesInRange(TaskHistoryItem item, LocalDateTime start, LocalDateTime end) {
LocalDateTime effectiveStart = item.getStartAt().isBefore(start) ? start : item.getStartAt(); LocalDateTime effectiveStart = item.getStartAt().isBefore(start) ? start : item.getStartAt();
LocalDateTime effectiveEnd = Objects.isNull(item.getEndAt()) || item.getEndAt().isAfter(end) ? end : item.getEndAt(); LocalDateTime itemEnd = Objects.nonNull(item.getEndAt()) ? item.getEndAt() : LocalDateTime.now();
LocalDateTime effectiveEnd = itemEnd.isAfter(end) ? end : itemEnd;
if (effectiveStart.isAfter(effectiveEnd)) return 0; if (effectiveStart.isAfter(effectiveEnd)) return 0;

View file

@ -140,7 +140,8 @@ public class OrgDashboardUseCase {
private long calculateMinutesInRange(TaskHistoryItem item, LocalDateTime start, LocalDateTime end) { private long calculateMinutesInRange(TaskHistoryItem item, LocalDateTime start, LocalDateTime end) {
LocalDateTime effectiveStart = item.getStartAt().isBefore(start) ? start : item.getStartAt(); LocalDateTime effectiveStart = item.getStartAt().isBefore(start) ? start : item.getStartAt();
LocalDateTime effectiveEnd = Objects.isNull(item.getEndAt()) || item.getEndAt().isAfter(end) ? end : item.getEndAt(); LocalDateTime itemEnd = Objects.nonNull(item.getEndAt()) ? item.getEndAt() : LocalDateTime.now();
LocalDateTime effectiveEnd = itemEnd.isAfter(end) ? end : itemEnd;
if (effectiveStart.isAfter(effectiveEnd)) return 0; if (effectiveStart.isAfter(effectiveEnd)) return 0;
return Duration.between(effectiveStart, effectiveEnd).toMinutes(); return Duration.between(effectiveStart, effectiveEnd).toMinutes();
} }

View file

@ -66,7 +66,8 @@ public class MemberDetailUseCase {
for (TaskHistoryItem h : task.getHistory()) { for (TaskHistoryItem h : task.getHistory()) {
if (!isWithinPeriod(h, start, end)) continue; if (!isWithinPeriod(h, start, end)) continue;
LocalDateTime effectiveStart = h.getStartAt().isBefore(start) ? start : h.getStartAt(); LocalDateTime effectiveStart = h.getStartAt().isBefore(start) ? start : h.getStartAt();
LocalDateTime effectiveEnd = (Objects.isNull(h.getEndAt()) || h.getEndAt().isAfter(end)) ? end : h.getEndAt(); LocalDateTime itemEnd = Objects.nonNull(h.getEndAt()) ? h.getEndAt() : LocalDateTime.now();
LocalDateTime effectiveEnd = itemEnd.isAfter(end) ? end : itemEnd;
if (effectiveStart.isAfter(effectiveEnd)) continue; if (effectiveStart.isAfter(effectiveEnd)) continue;
long minutes = Duration.between(effectiveStart, effectiveEnd).toMinutes(); long minutes = Duration.between(effectiveStart, effectiveEnd).toMinutes();