From b29973189f092c42c40a7a51caf908a1af3d79ce Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Mon, 16 Mar 2020 20:23:29 +0100 Subject: [PATCH] Use pretty date formatting --- screens/Tetris/TetrisScreen.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/screens/Tetris/TetrisScreen.js b/screens/Tetris/TetrisScreen.js index e348a60..532869b 100644 --- a/screens/Tetris/TetrisScreen.js +++ b/screens/Tetris/TetrisScreen.js @@ -85,6 +85,22 @@ class TetrisScreen extends React.Component { this.showPausePopup(); } + getFormattedTime(seconds: number) { + let date = new Date(); + date.setHours(0); + date.setMinutes(0); + date.setSeconds(seconds); + let format; + console.log(date); + if (date.getHours()) + format = date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds(); + else if (date.getMinutes()) + format = date.getMinutes() + ':' + date.getSeconds(); + else + format = date.getSeconds(); + return format; + } + onTick(score: number, level: number, newGrid: Array>) { this.setState({ gameScore: score, @@ -145,7 +161,7 @@ class TetrisScreen extends React.Component { showGameOverConfirm() { let message = 'SCORE: ' + this.state.gameScore + '\n'; message += 'LEVEL: ' + this.state.gameLevel + '\n'; - message += 'TIME: ' + this.state.gameTime + '\n'; + message += 'TIME: ' + this.getFormattedTime(this.state.gameTime) + '\n'; Alert.alert( 'GAME OVER', message, @@ -193,7 +209,7 @@ class TetrisScreen extends React.Component { {this.state.gameTime} + }}>{this.getFormattedTime(this.state.gameTime)}