From 97a3f34d2f27a172aff1bdfe05f02005158be7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C5=A0t=C4=9Btina?= Date: Tue, 1 Sep 2020 10:40:48 +0200 Subject: [PATCH 1/2] Fix the defaultFormatter to properly calculate remaining time from hours up. --- .gitignore | 2 ++ package.json | 9 ++++----- src/defaultFormatter.ts | 31 ++++++++++++++++++------------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 35a6fc7..b7144b5 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/package.json b/package.json index 4749bca..c11c200 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" diff --git a/src/defaultFormatter.ts b/src/defaultFormatter.ts index 18dc76f..321d3a7 100644 --- a/src/defaultFormatter.ts +++ b/src/defaultFormatter.ts @@ -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()); }; From 4ad11f4c990cd2392c051900c5a3bf8fcf871fae Mon Sep 17 00:00:00 2001 From: WhizSid Date: Fri, 4 Sep 2020 22:36:02 +0530 Subject: [PATCH 2/2] Bump version 1.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c11c200..f500ff3 100644 --- a/package.json +++ b/package.json @@ -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,