Skip to content

Commit

Permalink
移除 timespan 模块;修复 0 秒的 bug;
Browse files Browse the repository at this point in the history
  • Loading branch information
yb committed Mar 15, 2020
1 parent 139288d commit 820b74a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-scripts": "^3.4.0",
"react-tooltip": "^4.1.2",
"timespan": "^2.3.0"
"react-tooltip": "^4.1.2"
},
"scripts": {
"start": "react-app-rewired start",
Expand Down
20 changes: 14 additions & 6 deletions src/utils/helper.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import TimeSpan from 'timespan';

export const formatDuration = (seconds) => {
let time = TimeSpan.fromSeconds(seconds);
let text = `${time.seconds} 秒`;
if (time.minutes) text = `${time.minutes}${text}`;
if (time.hours) text = `${Math.floor(time.totalHours())} 小时 ${text}`;
let s = parseInt(seconds);
let m = 0;
let h = 0;
if (s >= 60) {
m = parseInt(s / 60);
s = parseInt(s % 60);
if (m >= 60) {
h = parseInt(m / 60);
m = parseInt(m % 60);
}
}
let text = `${s} 秒`;
if (m > 0) text = `${m}${text}`;
if (h > 0) text = `${h} 小时 ${text}`;
return text;
}

Expand Down

0 comments on commit 820b74a

Please sign in to comment.