-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
524 additions
and
180 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/main/java/de/focusshift/zeiterfassung/overtime/OvertimeDuration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package de.focusshift.zeiterfassung.overtime; | ||
|
||
import de.focusshift.zeiterfassung.timeentry.TimeEntryDuration; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.RoundingMode; | ||
import java.time.Duration; | ||
import java.util.Objects; | ||
|
||
public final class OvertimeDuration implements TimeEntryDuration { | ||
|
||
public static OvertimeDuration ZERO = new OvertimeDuration(Duration.ZERO); | ||
|
||
private final Duration value; | ||
|
||
public OvertimeDuration(Duration value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Duration value() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public Duration minutes() { | ||
final long seconds = value.toSeconds(); | ||
|
||
return seconds % 60 == 0 | ||
? value | ||
: Duration.ofMinutes(value.toMinutes() + 1); | ||
} | ||
|
||
@Override | ||
public double hoursDoubleValue() { | ||
final long minutes = minutes().toMinutes(); | ||
return minutesToHours(minutes); | ||
} | ||
|
||
public OvertimeDuration plus(Duration duration) { | ||
return new OvertimeDuration(value.plus(duration)); | ||
} | ||
|
||
public OvertimeDuration plus(OvertimeDuration overtimeDuration) { | ||
return new OvertimeDuration(value.plus(overtimeDuration.value)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
OvertimeDuration that = (OvertimeDuration) o; | ||
return Objects.equals(value, that.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(value); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "OvertimeDuration{" + | ||
"value=" + value + | ||
'}'; | ||
} | ||
|
||
private static double minutesToHours(long minutes) { | ||
return BigDecimal.valueOf(minutes).divide(BigDecimal.valueOf(60), 2, RoundingMode.CEILING).doubleValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/de/focusshift/zeiterfassung/report/ReportOvertimeDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package de.focusshift.zeiterfassung.report; | ||
|
||
import java.util.List; | ||
|
||
record ReportOvertimeDto(String personName, List<Double> overtimes) { | ||
|
||
public Double overtimeSum() { | ||
return overtimes.stream().reduce(0d, Double::sum); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/de/focusshift/zeiterfassung/report/ReportOvertimesDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.focusshift.zeiterfassung.report; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
record ReportOvertimesDto(List<LocalDate> dayOfWeeks, List<ReportOvertimeDto> overtimes) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.