From 32db3cccef4b031cd67c61feb7f0cf95bcd79f55 Mon Sep 17 00:00:00 2001 From: Marcus Fihlon Date: Thu, 18 Jul 2024 22:35:37 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20incorrect=20time=20calcula?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcus Fihlon --- .../swiss/fihlon/apus/ui/view/EventView.java | 6 ++++- .../swiss/fihlon/apus/ui/view/RoomView.java | 26 +++++++++---------- .../vaadin-i18n/translations.properties | 4 +-- .../vaadin-i18n/translations_de.properties | 4 +-- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/main/java/swiss/fihlon/apus/ui/view/EventView.java b/src/main/java/swiss/fihlon/apus/ui/view/EventView.java index 68b159c..02fa8ce 100644 --- a/src/main/java/swiss/fihlon/apus/ui/view/EventView.java +++ b/src/main/java/swiss/fihlon/apus/ui/view/EventView.java @@ -129,7 +129,11 @@ private static RoomView createRoomView(@NotNull final Map.Entry 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) diff --git a/src/main/java/swiss/fihlon/apus/ui/view/RoomView.java b/src/main/java/swiss/fihlon/apus/ui/view/RoomView.java index a1c4798..95ab4bc 100644 --- a/src/main/java/swiss/fihlon/apus/ui/view/RoomView.java +++ b/src/main/java/swiss/fihlon/apus/ui/view/RoomView.java @@ -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; } diff --git a/src/main/resources/vaadin-i18n/translations.properties b/src/main/resources/vaadin-i18n/translations.properties index 9a1a818..20e1955 100644 --- a/src/main/resources/vaadin-i18n/translations.properties +++ b/src/main/resources/vaadin-i18n/translations.properties @@ -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 diff --git a/src/main/resources/vaadin-i18n/translations_de.properties b/src/main/resources/vaadin-i18n/translations_de.properties index b254998..d5e75d9 100644 --- a/src/main/resources/vaadin-i18n/translations_de.properties +++ b/src/main/resources/vaadin-i18n/translations_de.properties @@ -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