Skip to content

Commit

Permalink
🐛 Fix incorrect time calculation
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Fihlon <[email protected]>
  • Loading branch information
McPringle committed Jul 18, 2024
1 parent 6c6cd5d commit 32db3cc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
6 changes: 5 additions & 1 deletion src/main/java/swiss/fihlon/apus/ui/view/EventView.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ private static RoomView createRoomView(@NotNull final Map.Entry<Room, List<Sessi
final LocalDateTime timeLimitNextSession = LocalDateTime.now().plus(TIME_LIMIT_NEXT_SESSION);
final Room room = roomWithSession.getKey();
final List<Session> sessions = roomWithSession.getValue();
final Session session = sessions.isEmpty() ? null : sessions.getFirst();
final LocalDateTime now = LocalDateTime.now().withSecond(59).withNano(999);
final Session session = sessions.isEmpty() ? null : sessions.stream()
.filter(s -> s.endDate().isAfter(now))
.findFirst()
.orElse(null);
final RoomView roomView;
if (session != null
&& session.startDate().toLocalDate().isEqual(today)
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/swiss/fihlon/apus/ui/view/RoomView.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,28 +137,28 @@ private Component createRoomComponent() {
@NotNull
private Component createTimeComponent() {
final var timeComponent = new Div();
final var now = LocalTime.now();
final var now = LocalTime.now().withSecond(59).withNano(999);
if (startTime == null || endTime == null) { // empty session
timeComponent.add(nbsp());
roomStyle = RoomStyle.EMPTY;
} else if (startTime.isBefore(now) && endTime.isAfter(now)) { // running session
} else if (startTime.isAfter(now)) { // next session
timeComponent.add(
new Icon(VaadinIcon.ALARM),
new Text(String.format("%s - %s", startTime, endTime))
);
roomStyle = RoomStyle.NEXT;
} else { // running session
final Duration duration = Duration.between(now, endTime);
final long timeLeft = Math.round(duration.getSeconds() / 60f);
final int minutesLeft = Math.round(duration.getSeconds() / 60f);
timeComponent.add(new Icon(VaadinIcon.HOURGLASS));
if (timeLeft == 0) {
if (minutesLeft <= 0) {
timeComponent.add(new Text(getTranslation("event.session.countdown.now")));
} else if (timeLeft == 1) {
timeComponent.add(new Text(getTranslation("event.session.countdown.singular", timeLeft)));
} else if (minutesLeft == 1) {
timeComponent.add(new Text(getTranslation("event.session.countdown.one-minute")));
} else {
timeComponent.add(new Text(getTranslation("event.session.countdown.plural", timeLeft)));
timeComponent.add(new Text(getTranslation("event.session.countdown.minutes", minutesLeft)));
}
roomStyle = RoomStyle.RUNNING;
} else { // next session
timeComponent.add(
new Icon(VaadinIcon.ALARM),
new Text(String.format("%s - %s", startTime, endTime))
);
roomStyle = RoomStyle.NEXT;
}
return timeComponent;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/vaadin-i18n/translations.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ event.legend.next-session=next session
event.legend.running-session=running session
event.room.empty=closed
event.session.countdown.now=ends now
event.session.countdown.plural=ends in {0} minutes
event.session.countdown.singular=ends in {0} minute
event.session.countdown.minutes=ends in {0} minutes
event.session.countdown.one-minute=ends in one minute
social.admin.login.button=Login
social.admin.login.cancel=Cancel
social.admin.login.menu=Login as Administrator
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/vaadin-i18n/translations_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ event.legend.next-session=n
event.legend.running-session=laufender Vortrag
event.room.empty=geschlossen
event.session.countdown.now=endet jetzt
event.session.countdown.plural=endet in {0} Minuten
event.session.countdown.singular=endet in {0} Minute
event.session.countdown.minutes=endet in {0} Minuten
event.session.countdown.one-minute=endet in einer Minute
social.admin.login.button=Anmelden
social.admin.login.cancel=Abbrechen
social.admin.login.menu=Als Administrator anmelden
Expand Down

0 comments on commit 32db3cc

Please sign in to comment.