From 91f7cc6d2b5230fc82742c9661ca740e7715b48e Mon Sep 17 00:00:00 2001 From: uykek Date: Thu, 28 May 2020 00:25:12 +0200 Subject: [PATCH] Add method which calculates the amount of seconds that were needed to solve a DailySudoku object based on its "timeNeeded" attribute --- .../controller/database/model/DailySudoku.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/database/model/DailySudoku.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/database/model/DailySudoku.java index f8546c3..a78c660 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/database/model/DailySudoku.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/database/model/DailySudoku.java @@ -25,6 +25,20 @@ public class DailySudoku extends Level { return timeNeeded; } + public int getTimeNeededInSeconds() { + if (timeNeeded.matches("/d/d:/d/d:/d/d")) { + String[] timeInstances = timeNeeded.split(":"); + int hourIndex = 0; + int minuteIndex = 1; + int secondIndex = 2; + + int minutes = Integer.parseInt(timeInstances[hourIndex]) * 60 + Integer.parseInt(timeInstances[minuteIndex]); + return minutes * 60 + Integer.parseInt(timeInstances[secondIndex]); + } + + return 0; + } + public void setTimeNeeded(String timeNeeded) { this.timeNeeded = timeNeeded; }