Skip to content

Commit

Permalink
fix: #80 - fix the date formats when in between groupings
Browse files Browse the repository at this point in the history
  • Loading branch information
maurycupitt committed Aug 23, 2023
1 parent 2b1a65b commit 2b83fdf
Showing 1 changed file with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,21 @@ function IqAllVersionDetails() {
return
}
const endDate = new Date()
const differenceInMilliseconds = endDate.getTime() - startDate.getTime();
const differenceInSeconds = differenceInMilliseconds / 1000;
const differenceInMinutes = differenceInSeconds / 60;
const differenceInHours = differenceInMinutes / 60;
const differenceInDays = differenceInHours / 24;
const differenceInMonths = (endDate.getMonth() - startDate.getMonth()) + (12 * (endDate.getFullYear() - startDate.getFullYear()));
const differenceInWeeks = differenceInDays / 7;
const differenceInMilliseconds = endDate.getTime() - startDate.getTime()
const differenceInSeconds = differenceInMilliseconds / 1000
const differenceInMinutes = differenceInSeconds / 60
const differenceInHours = Math.round(differenceInMinutes / 60)
const differenceInDays = Math.round(differenceInHours / 24)
const differenceInMonths = (endDate.getMonth() - startDate.getMonth()) + (12 * (endDate.getFullYear() - startDate.getFullYear()))
const differenceInWeeks = Math.round(differenceInDays / 7)

let yearsDiff = endDate.getFullYear() - startDate.getFullYear();
let yearsDiff = endDate.getFullYear() - startDate.getFullYear()

if (
endDate.getMonth() < startDate.getMonth() ||
(endDate.getMonth() === startDate.getMonth() && endDate.getDate() < startDate.getDate())
) {
yearsDiff -= 1;
yearsDiff -= 1
}

const difference = {
Expand All @@ -100,28 +100,28 @@ function IqAllVersionDetails() {
months: differenceInMonths,
weeks: differenceInWeeks,
years: yearsDiff,
};
}

if (difference.years !== undefined && difference.years > 0) {
const yearString = `${difference.years} yr${difference.years !== 1 ? 's' : ''}`;
const yearString = `${difference.years} yr${difference.years !== 1 ? 's' : ''}`
if (startDate.getMonth() !== 11) {
const remainingMonths = 12 - startDate.getMonth() - 1;
const monthString = `${remainingMonths} mo${remainingMonths !== 1 ? 's' : ''}`;
return `${yearString} ${monthString}`;
const remainingMonths = 12 - startDate.getMonth() - 1
const monthString = `${remainingMonths} mo${remainingMonths !== 1 ? 's' : ''}`
return `${yearString} ${monthString}`
}
return yearString;
return yearString
} else if (difference.months !== undefined && difference.months > 0) {
return `${difference.months} mo${difference.months !== 1 ? 's' : ''}`;
} else if (difference.weeks !== undefined && difference.weeks > 0) {
return `${difference.weeks} wk${difference.weeks !== 1 ? 's' : ''}`;
} else if (difference.days !== undefined && difference.days > 0) {
return `${difference.days} day${difference.days !== 1 ? 's' : ''}`;
return `${difference.months} mo${difference.months !== 1 ? 's' : ''}`
} else if (difference.weeks !== undefined && difference.weeks >= 1 ) {
return `${difference.weeks} wk${difference.weeks !== 1 ? 's' : ''}`
} else if (difference.days !== undefined && difference.days >= 2) {
return `${difference.days} day${difference.days !== 1 ? 's' : ''}`
} else if (difference.hours !== undefined && difference.hours > 0) {
return `${difference.hours} hr${difference.hours !== 1 ? 's' : ''}`;
return `${difference.hours} hr${difference.hours !== 1 ? 's' : ''}`
} else if (difference.minutes !== undefined && difference.minutes > 0) {
return `${difference.minutes} min${difference.minutes !== 1 ? 's' : ''}`;
return `${difference.minutes} min${difference.minutes !== 1 ? 's' : ''}`
} else {
return `${difference.seconds} sec${difference.seconds !== 1 ? 's' : ''}`;
return `${difference.seconds} sec${difference.seconds !== 1 ? 's' : ''}`
}
}

Expand Down

0 comments on commit 2b83fdf

Please sign in to comment.