Skip to content

Commit

Permalink
Turning seconds into minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
serranoarevalo committed Oct 28, 2017
1 parent 3aa0fa6 commit 9e02e56
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions components/Timer/presenter.js
Expand Up @@ -2,6 +2,19 @@ import React, { Component } from "react";
import { View, StyleSheet, Text, StatusBar } from "react-native";
import Button from "../Button";

function formatTime(time) {
var minutes = Math.floor(time / 60);
time -= minutes * 60;

var seconds = parseInt(time % 60, 10);

return `${minutes < 10 ? `0${minutes}` : minutes}:${seconds < 10
? `0${seconds}`
: seconds}`;

return;
}

class Timer extends Component {
componentWillReceiveProps(nextProps) {
const currentProps = this.props;
Expand All @@ -24,12 +37,13 @@ class Timer extends Component {
startTimer,
restartTimer
} = this.props;
console.log(elapsedTime);
return (
<View style={styles.container}>
<StatusBar barStyle="light-content" />
<View style={styles.upper}>
<Text style={styles.time}>25:00</Text>
<Text style={styles.time}>
{formatTime(timerDuration - elapsedTime)}
</Text>
</View>
<View style={styles.lower}>
{!isPlaying && <Button iconName={"ios-play"} onPress={startTimer} />}
Expand Down

0 comments on commit 9e02e56

Please sign in to comment.