From ebd6f2ffc8b0c7cd7a6c8959ca73ba02017504d2 Mon Sep 17 00:00:00 2001 From: ddcat1115 Date: Thu, 1 Mar 2018 19:01:50 +0800 Subject: [PATCH] fix Countdown error format and invalid initial time, close #1009 --- src/components/CountDown/index.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/components/CountDown/index.js b/src/components/CountDown/index.js index 5b512c83..f7aa6e08 100644 --- a/src/components/CountDown/index.js +++ b/src/components/CountDown/index.js @@ -51,9 +51,8 @@ class CountDown extends Component { } lastTime = targetTime - new Date().getTime(); - return { - lastTime, + lastTime: lastTime < 0 ? 0 : lastTime, }; } // defaultFormat = time => ( @@ -63,11 +62,11 @@ class CountDown extends Component { const hours = 60 * 60 * 1000; const minutes = 60 * 1000; - const h = fixedZero(Math.floor(time / hours)); - const m = fixedZero(Math.floor((time - (h * hours)) / minutes)); - const s = fixedZero(Math.floor((time - (h * hours) - (m * minutes)) / 1000)); + const h = Math.floor(time / hours); + const m = Math.floor((time - (h * hours)) / minutes); + const s = Math.floor((time - (h * hours) - (m * minutes)) / 1000); return ( - {h}:{m}:{s} + {fixedZero(h)}:{fixedZero(m)}:{fixedZero(s)} ); } tick = () => { @@ -98,7 +97,6 @@ class CountDown extends Component { render() { const { format = this.defaultFormat, onEnd, ...rest } = this.props; const { lastTime } = this.state; - const result = format(lastTime); return ({result}); -- GitLab