|
@@ -51,9 +51,8 @@ class CountDown extends Component {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
lastTime = targetTime - new Date().getTime();
|
|
lastTime = targetTime - new Date().getTime();
|
|
|
-
|
|
|
|
|
return {
|
|
return {
|
|
|
- lastTime,
|
|
|
|
|
|
|
+ lastTime: lastTime < 0 ? 0 : lastTime,
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
// defaultFormat = time => (
|
|
// defaultFormat = time => (
|
|
@@ -63,11 +62,11 @@ class CountDown extends Component {
|
|
|
const hours = 60 * 60 * 1000;
|
|
const hours = 60 * 60 * 1000;
|
|
|
const minutes = 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 (
|
|
return (
|
|
|
- <span>{h}:{m}:{s}</span>
|
|
|
|
|
|
|
+ <span>{fixedZero(h)}:{fixedZero(m)}:{fixedZero(s)}</span>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
tick = () => {
|
|
tick = () => {
|
|
@@ -98,7 +97,6 @@ class CountDown extends Component {
|
|
|
render() {
|
|
render() {
|
|
|
const { format = this.defaultFormat, onEnd, ...rest } = this.props;
|
|
const { format = this.defaultFormat, onEnd, ...rest } = this.props;
|
|
|
const { lastTime } = this.state;
|
|
const { lastTime } = this.state;
|
|
|
-
|
|
|
|
|
const result = format(lastTime);
|
|
const result = format(lastTime);
|
|
|
|
|
|
|
|
return (<span {...rest}>{result}</span>);
|
|
return (<span {...rest}>{result}</span>);
|