fixing issues of integration with wordpress plugin
This commit is contained in:
@@ -25,6 +25,33 @@ export function formatRelativeDate(dateString: string | Date): string {
|
||||
const diffTime = today.getTime() - dateOnly.getTime();
|
||||
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
|
||||
|
||||
// Handle future dates (negative diffDays)
|
||||
if (diffDays < 0) {
|
||||
const futureDays = Math.abs(diffDays);
|
||||
if (futureDays === 1) {
|
||||
return 'Tomorrow';
|
||||
} else if (futureDays < 30) {
|
||||
return `in ${futureDays} days`;
|
||||
} else if (futureDays < 365) {
|
||||
const months = Math.floor(futureDays / 30);
|
||||
const remainingDays = futureDays % 30;
|
||||
if (remainingDays === 0) {
|
||||
return `in ${months} month${months > 1 ? 's' : ''}`;
|
||||
} else {
|
||||
return `in ${months} month${months > 1 ? 's' : ''} ${remainingDays} day${remainingDays > 1 ? 's' : ''}`;
|
||||
}
|
||||
} else {
|
||||
const years = Math.floor(futureDays / 365);
|
||||
const remainingMonths = Math.floor((futureDays % 365) / 30);
|
||||
if (remainingMonths === 0) {
|
||||
return `in ${years} year${years > 1 ? 's' : ''}`;
|
||||
} else {
|
||||
return `in ${years} year${years > 1 ? 's' : ''} ${remainingMonths} month${remainingMonths > 1 ? 's' : ''}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle past dates (positive diffDays)
|
||||
if (diffDays === 0) {
|
||||
return 'Today';
|
||||
} else if (diffDays === 1) {
|
||||
|
||||
Reference in New Issue
Block a user