add time from other days
This commit is contained in:
@ -4,7 +4,11 @@ import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TDoneRecord;
|
||||
@ -41,6 +45,27 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
|
||||
this.activity = jobMap.get(r.getFkJob());
|
||||
}
|
||||
|
||||
/**
|
||||
* set the day of timeFrom and timeUntil, keeping the times
|
||||
*
|
||||
* @param day
|
||||
* the day
|
||||
*/
|
||||
public void setDay(Date day) {
|
||||
if (timeFrom != null) {
|
||||
LocalDateTime ldt = timeFrom.toLocalDateTime();
|
||||
LocalDate date = day.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
ldt = ldt.withYear(date.getYear()).withMonth(date.getMonthValue()).withDayOfMonth(date.getDayOfMonth());
|
||||
timeFrom = Timestamp.from(ldt.toInstant(OffsetDateTime.now().getOffset()));
|
||||
}
|
||||
if (timeUntil != null) {
|
||||
LocalDateTime ldt = timeUntil.toLocalDateTime();
|
||||
LocalDate date = day.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
ldt = ldt.withYear(date.getYear()).withMonth(date.getMonthValue()).withDayOfMonth(date.getDayOfMonth());
|
||||
timeUntil = Timestamp.from(ldt.toInstant(OffsetDateTime.now().getOffset()));
|
||||
}
|
||||
}
|
||||
|
||||
public String getTimeSummary() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
if (timeFrom != null) {
|
||||
|
@ -137,6 +137,7 @@ public class DoneModel implements Model, Serializable {
|
||||
|
||||
public boolean insert(JooqFacesContext facesContext) {
|
||||
try {
|
||||
bean.setDay(day);
|
||||
new DoneGateway(facesContext).insert(bean);
|
||||
return true;
|
||||
} catch (DataAccessException | ClassNotFoundException | SQLException e) {
|
||||
|
Reference in New Issue
Block a user