export function formatRelativeDate(dateString) {
  const givenDate = new Date(dateString);
  const currentDate = new Date();

  // Calculate the time difference in milliseconds
  const timeDiff = currentDate - givenDate;
  
  // Calculate difference in minutes and hours
  const minutesDiff = Math.floor(timeDiff / (1000 * 60));
  const hoursDiff = Math.floor(timeDiff / (1000 * 60 * 60));
  
  // Determine "time ago" format, forcing it to use hours if it's over 24 hours
  let timeAgo;
  if (minutesDiff < 60) {
    timeAgo = `${minutesDiff} minutes ago`;
  } else {
    timeAgo = `${hoursDiff} hours ago`;
  }

  // Format the date as DD/MM/YYYY
  const formattedDate = new Intl.DateTimeFormat('en-GB').format(givenDate);

  // Return the final format
  return `${timeAgo}, ${formattedDate}`;
}


export const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
console.log(timeZone); // e.g., "America/New_York"



export function formatUTCToDDMMYYHHMMSS(utcDateString) {
  const date = new Date(utcDateString);

  // Extract individual date and time components
  const day = String(date.getUTCDate()).padStart(2, '0');
  const month = String(date.getUTCMonth() + 1).padStart(2, '0'); // Months are 0-based
  const year = String(date.getUTCFullYear()).slice(-2); // Get last two digits of the year
  const hours = String(date.getUTCHours()).padStart(2, '0');
  const minutes = String(date.getUTCMinutes()).padStart(2, '0');
  const seconds = String(date.getUTCSeconds()).padStart(2, '0');

  // Combine the formatted parts
  return `${day}-${month}-${year} ${hours}:${minutes}:${seconds}`;
}