Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
yarn.lock
/dist
.idea
# perhaps reconsider tracking the lock file with git as it's the recommended practice
package-lock.json
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-progress-timer",
"version": "1.0.2",
"version": "1.0.3",
"description": "This react component will automatically calculate the time to complete a progress bar by percentage changing speed.",
"main": "dist/index.js",
"private": false,
Expand Down Expand Up @@ -37,14 +37,14 @@
},
"homepage": "http://whizsid.github.io/react-progress-timer",
"devDependencies": {
"@babel/cli": "^7.6.2",
"@babel/core": "^7.6.4",
"@babel/cli": "^7.11.5",
"@babel/core": "^7.11.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-object-rest-spread": "^7.6.2",
"@babel/preset-env": "^7.6.3",
"@babel/preset-env": "^7.11.5",
"@babel/preset-react": "^7.6.3",
"@babel/preset-typescript": "^7.6.0",
"@types/react": "^16.9.3",
"@types/react": "^16.9.49",
"@types/react-dom": "^16.9.1",
"babel-loader": "^8.0.6",
"babel-plugin-inline-react-svg": "^1.1.0",
Expand All @@ -63,7 +63,6 @@
"webpack-cli": "^3.3.9",
"webpack-dev-server": "^3.8.2"
},
"dependencies": {},
"peerDependencies": {
"react": "^16.9.0",
"react-dom": "^16.9.0"
Expand Down
31 changes: 18 additions & 13 deletions src/defaultFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
export default (time: number, percentage: number, format: string): string => {
let modTime = Math.ceil(time / 1000);
export default (
milliseconds: number,
percentage: number,
format: string
): string => {
const seconds = Math.ceil(milliseconds / 1000);
let unit = "second(s)";
let timeValue = seconds;

if (modTime > 12 * 30 * 24 * 60 * 60) {
modTime = Math.ceil((modTime / 12) * 30 * 24 * 60 * 60);
if (seconds > 12 * 30 * 24 * 60 * 60) {
timeValue = timeValue / (12 * 30 * 24 * 60 * 60);
unit = "year(s)";
} else if (modTime > 30 * 24 * 60 * 60) {
modTime = Math.ceil((modTime / 30) * 24 * 60 * 60);
} else if (seconds > 30 * 24 * 60 * 60) {
timeValue = timeValue / (30 * 24 * 60 * 60);
unit = "month(s)";
} else if (modTime > 24 * 60 * 60) {
modTime = Math.ceil((modTime / 24) * 60 * 60);
} else if (seconds > 24 * 60 * 60) {
timeValue = timeValue / (24 * 60 * 60);
unit = "day(s)";
} else if (modTime > 60 * 60) {
modTime = Math.ceil((modTime / 60) * 60);
} else if (seconds > 60 * 60) {
timeValue = timeValue / (60 * 60);
unit = "hour(s)";
} else if (modTime > 60) {
modTime = Math.ceil(modTime / 60);
} else if (seconds > 60) {
timeValue = timeValue / 60;
unit = "minute(s)";
}

return format
.replace("{value}", modTime.toString())
.replace("{value}", Math.ceil(timeValue).toString())
.replace("{unit}", unit)
.replace("{percentage}", Math.round(percentage).toString());
};