Skip to content

Commit

Permalink
fix:wrong eta
Browse files Browse the repository at this point in the history
  • Loading branch information
Achintya-Chatterjee committed Jul 11, 2024
1 parent e5efd32 commit e27495c
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions app/helpers/convertDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const timeDifference = (timestamp, timeNow) => {
const mins = calc(60, timeInSec);
const hours = calc(60, mins);
const days = calc(24, hours);
const weeks = Math.floor(days / 7);
const remainingDays = days % 7;
const months = calc(30, days);
const years = calc(12, months);
const months = Math.floor(days / 30);
const years = Math.floor(months / 12);

console.log({ timeInSec, mins, hours, days, months, years }); // Debug log

if (timeInSec < 1) {
return { result: '', cycle: 'just now' };
Expand All @@ -20,16 +20,6 @@ const timeDifference = (timestamp, timeNow) => {
return { result: years, cycle: 'year' };
} else if (months > 0) {
return { result: months, cycle: 'month' };
} else if (weeks > 0) {
if (remainingDays > 0) {
return {
result: weeks,
cycle: 'week',
extra: remainingDays,
extraCycle: 'day',
};
}
return { result: weeks, cycle: 'week' };
} else if (days > 0) {
return { result: days, cycle: 'day' };
} else if (hours > 0) {
Expand All @@ -49,12 +39,6 @@ function convertDate([timestamp], { end_date, timeNow = Date.now() }) {
time_value.result > 1 ? 's' : ''
}`;

if (time_value.extra) {
timeString += ` and ${time_value.extra} ${time_value.extraCycle}${
time_value.extra > 1 ? 's' : ''
}`;
}

if (end_date == 1 && timestamp * 1000 < timeNow) {
return `${timeString} ago`;
}
Expand Down

0 comments on commit e27495c

Please sign in to comment.