Skip to content

Commit

Permalink
Temporary fix for incorrect notification and logging time
Browse files Browse the repository at this point in the history
  • Loading branch information
Alf-Melmac committed Oct 20, 2021
1 parent 7ae496b commit 2dfefeb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

import static de.webalf.slotbot.util.DateUtils.getDateTimeNowZoned;

/**
* @author Alf
* @since 11.08.2021
Expand Down Expand Up @@ -40,7 +42,7 @@ public class NotificationSetting extends AbstractSuperIdEntity {
* @return delay until notification must be sent
*/
public int getNotificationDelay(LocalDateTime eventTime) {
return (int) ChronoUnit.MINUTES.between(LocalDateTime.now(), getNotificationTime(eventTime));
return (int) ChronoUnit.MINUTES.between(getDateTimeNowZoned(), getNotificationTime(eventTime));
}

private LocalDateTime getNotificationTime(@NonNull LocalDateTime eventTime) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/de/webalf/slotbot/service/ActionLogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

import javax.validation.constraints.NotEmpty;
import java.time.Duration;
import java.time.LocalDateTime;

import static de.webalf.slotbot.util.DateUtils.getDateTimeNowZoned;

/**
* @author Alf
Expand All @@ -26,11 +27,11 @@ public class ActionLogService {
private final ActionLogRepository logRepository;

void logEventAction(@NonNull LogAction action, @NonNull Event event, @NonNull User user) {
logAction(action, Duration.between(LocalDateTime.now(), event.getDateTime()), event.getId(), user);
logAction(action, Duration.between(getDateTimeNowZoned(), event.getDateTime()), event.getId(), user);
}

void logEventAction(@NonNull LogAction action, @NonNull Event event, @NonNull User user1, @NonNull User user2) {
Duration timeGap = Duration.between(LocalDateTime.now(), event.getDateTime());
Duration timeGap = Duration.between(getDateTimeNowZoned(), event.getDateTime());
logAction(action, timeGap, event.getId(), user1);
logAction(action, timeGap, event.getId(), user2);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/de/webalf/slotbot/util/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public static ZonedDateTime getDateTimeZoned(@NonNull LocalDateTime dateTime) {
return dateTime.atZone(ZONE_BERLIN);
}

public static ZonedDateTime getDateTimeNowZoned() {
return getDateTimeZoned(LocalDateTime.now());
}

public static ZonedDateTime getDateTimeZoned(@NonNull LocalDate date, @NonNull LocalTime time) {
return date.atTime(time).atZone(ZONE_BERLIN);
}
Expand Down

0 comments on commit 2dfefeb

Please sign in to comment.