type RelativeTimeFormatUnit = any;
export function getRelativeTime(dateString: string): string {
  const date = new Date(dateString);
  const now = new Date();
  const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000);

  const intervals: Record<RelativeTimeFormatUnit, number> = {
    year: 31536000,
    month: 2592000,
    week: 604800,
    day: 86400,
    hour: 3600,
    minute: 60,
    second: 1,
  };

  const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });

  for (const key in intervals) {
    const unit = key as RelativeTimeFormatUnit;
    const diff = Math.floor(diffInSeconds / intervals[unit]);
    if (diff >= 1) {
      return rtf.format(-diff, unit);
    }
  }
  return "just now";
}
