Skip to content

Commit

Permalink
fix: inception unable to handle months and years
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwbabylonlab committed Dec 12, 2024
1 parent 0d44f63 commit 80891c5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-staking",
"version": "0.3.20",
"version": "0.3.21",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
25 changes: 19 additions & 6 deletions src/utils/formatTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,30 @@ interface Duration {
seconds?: number;
}

export const durationTillNow = (time: string, currentTime: number) => {
if (!time || time.startsWith("000")) return "Ongoing";
export const durationTillNow = (
startTimestamp: string,
currentTime: number,
) => {
if (!startTimestamp || startTimestamp.startsWith("000")) return "Ongoing";

const duration = intervalToDuration({
end: currentTime,
start: new Date(time),
start: new Date(startTimestamp),
});
let format: (keyof Duration)[] = ["days", "hours", "minutes"];

if (!duration.days && !duration.hours && !duration.minutes) {
format.push("seconds");
let format: (keyof Duration)[] = [];

// If there are months or years, only show months and days
if (duration.months || duration.years) {
format = ["years", "months", "days"];
}
// If only days or less, show more detailed time
else {
format = ["days", "hours", "minutes"];
// Add seconds only if less than a minute
if (!duration.days && !duration.hours && !duration.minutes) {
format.push("seconds");
}
}

const formattedTime = formatDuration(duration, {
Expand Down

0 comments on commit 80891c5

Please sign in to comment.