aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/git.js23
1 files changed, 2 insertions, 21 deletions
diff --git a/api/git.js b/api/git.js
index 8574dfa..47b47bc 100644
--- a/api/git.js
+++ b/api/git.js
@@ -1,5 +1,5 @@
const { spawn } = require("child_process");
-const { differenceInMilliseconds } = require('date-fns');
+const { formatDistance } = require('date-fns');
const fs = require('fs');
function execGit(path, action, args = [""], error)
@@ -56,22 +56,6 @@ function getLog(base_dir, path)
})
}
-function getOptimalDateDifference(difference)
-{
- const time_values = { "second": 1000, "minute": 60000, "hour": 3600000, "day": 86400000, "week": 604800000, "month": 2629800000, "year": 31557600000 };
-
- let last;
- for(const [key, value] of Object.entries(time_values)) {
- if(difference > value) {
- last = key;
- continue;
- }
- break;
- }
-
- return `${Math.round(difference / time_values[last])} ${last}s`;
-}
-
function getTimeSinceLatestCommit(path)
{
return new Promise((resolve) =>
@@ -84,10 +68,7 @@ function getTimeSinceLatestCommit(path)
git.on("close", (code) =>
{
- const commit_timestamp = new Date(Number(Buffer.concat(commit).toString()) * 1000);
- const now_date = new Date();
-
- resolve(getOptimalDateDifference(differenceInMilliseconds(now_date, commit_timestamp)));
+ resolve(formatDistance(new Date(), new Date(Number(Buffer.concat(commit).toString()) * 1000)));
});
});
}