/** * calculates the duration between two dates and returns a string in the format hhh:mm:ss * * @param fromDate - start date * @param toDate - end date * @return a string in the format hhh:mm:ss */ public static String getDuration(Date fromDate, Date toDate) { if (fromDate == null || toDate == null || fromDate.getTime() > toDate.getTime()) { return ""; } return getDuration((toDate.getTime() - fromDate.getTime()) / 1000); } /**
@Override public GameInfo createGameInfo(Game game) { StringBuilder playersInfo = new StringBuilder(); int counter = 0; for (MatchPlayer matchPlayer : getPlayers()) { if (counter > 0) { playersInfo.append(" - "); } playersInfo.append(matchPlayer.getName()); counter++; } String state; String result; String duelingTime = ""; if (game.hasEnded()) { if (game.getEndTime() != null) { duelingTime = " (" + DateFormat.getDuration((game.getEndTime().getTime() - game.getStartTime().getTime()) / 1000) + ')'; } state = "Finished" + duelingTime; result = game.getWinner(); } else { if (game.getStartTime() != null) { duelingTime = " (" + DateFormat.getDuration((new Date().getTime() - game.getStartTime().getTime()) / 1000) + ')'; } state = "Dueling" + duelingTime; result = ""; } return new GameInfo(0, this.getId(), game.getId(), state, result, playersInfo.toString(), tableId); }
TournamentGameView(int roundNum, TournamentPairing pair, Game game) { this.roundNum = roundNum; this.matchId = pair.getMatch().getId(); this.gameId = game.getId(); this.players = pair.getPlayer1().getPlayer().getName() + " - " + pair.getPlayer2().getPlayer().getName(); String duelingTime = ""; if (game.hasEnded()) { if (game.getEndTime() != null && game.getStartTime() != null) { duelingTime = " (" + DateFormat.getDuration((game.getEndTime().getTime() - game.getStartTime().getTime())/1000) + ')'; } this.state = "Finished" + duelingTime; this.result = game.getWinner(); } else { if (game.getStartTime() != null) { duelingTime = " (" + DateFormat.getDuration((new Date().getTime() - game.getStartTime().getTime())/1000) + ')'; } this.state = "Dueling" + duelingTime; this.result = ""; } this.tableId = pair.getTableId(); }