From ccbdc089713ea266e4e6c23069809c9100c46486 Mon Sep 17 00:00:00 2001 From: SponsoredByPuma <92574150+SponsoredByPuma@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:23:33 +0200 Subject: [PATCH] #295 Timer depends on local time (#304) * Timer is no longer based on the Date time (System time) * websocket on main state * Google Java Format * add a solution to the timer which is based on local time * Google Java Format * missing imports * replaced created with ok, improved Logger Message --------- Co-authored-by: github-actions <> --- .../main/java/io/diveni/backend/Utils.java | 8 +++++++ .../controller/WebsocketController.java | 16 +++++++++++++ frontend/src/components/EstimateTimer.vue | 24 +++++++++++++++++++ frontend/src/views/MemberVotePage.vue | 1 + 4 files changed, 49 insertions(+) diff --git a/backend/src/main/java/io/diveni/backend/Utils.java b/backend/src/main/java/io/diveni/backend/Utils.java index 273ce1cf0..2479376ae 100644 --- a/backend/src/main/java/io/diveni/backend/Utils.java +++ b/backend/src/main/java/io/diveni/backend/Utils.java @@ -7,6 +7,7 @@ import java.net.URI; import java.text.DateFormat; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Base64; import java.util.Date; @@ -67,4 +68,11 @@ private static final DateFormat getDateFormatISO() { public static String getTimestampISO8601(Date date) { return dateFormatISO8601.format(date); } + + public static Date getDateFromString(String dateString) throws ParseException { + TimeZone tz = TimeZone.getTimeZone("UTC"); + DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + df.setTimeZone(tz); + return df.parse(dateString); + } } diff --git a/backend/src/main/java/io/diveni/backend/controller/WebsocketController.java b/backend/src/main/java/io/diveni/backend/controller/WebsocketController.java index 6aeb8838b..52036db3a 100644 --- a/backend/src/main/java/io/diveni/backend/controller/WebsocketController.java +++ b/backend/src/main/java/io/diveni/backend/controller/WebsocketController.java @@ -22,9 +22,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.handler.annotation.Payload; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import java.text.ParseException; import io.diveni.backend.principals.AdminPrincipal; import io.diveni.backend.principals.MemberPrincipal; @@ -232,4 +236,16 @@ public synchronized void adminSelectedUserStory( webSocketService.sendSelectedUserStoryToMembers(session, index); LOGGER.debug("<-- adminSelectedUserStory()"); } + + @GetMapping("/get-timer-value") + public synchronized ResponseEntity getTimeValue(String memberID) throws ParseException { + LOGGER.debug("--> get-timer-value()"); + Session session = + ControllerUtils.getSessionByMemberIDOrThrowResponse(databaseService, memberID); + Date startDate = Utils.getDateFromString(session.getTimerTimestamp()); + Date currentDate = new Date(); + long timeDifference = currentDate.getTime() - startDate.getTime(); + LOGGER.debug("<-- get-timer-value() + " + timeDifference); + return new ResponseEntity<>(timeDifference, HttpStatus.OK); + } } diff --git a/frontend/src/components/EstimateTimer.vue b/frontend/src/components/EstimateTimer.vue index fa9233058..de76a3f5c 100644 --- a/frontend/src/components/EstimateTimer.vue +++ b/frontend/src/components/EstimateTimer.vue @@ -7,6 +7,7 @@ diff --git a/frontend/src/views/MemberVotePage.vue b/frontend/src/views/MemberVotePage.vue index 3925d89fe..e00a5edeb 100644 --- a/frontend/src/views/MemberVotePage.vue +++ b/frontend/src/views/MemberVotePage.vue @@ -23,6 +23,7 @@ :start-timestamp="timerTimestamp" :pause-timer="estimateFinished || pauseSession" :duration="timerCountdownNumber" + :member="memberID" :votingStarted="isStartVoting" />