noodle icon indicating copy to clipboard operation
noodle copied to clipboard

Wrong timezone used

Open xhayper opened this issue 1 year ago • 2 comments

Describe the bug The timezone used in the app is wrong

To Reproduce Steps to reproduce the behavior:

  • Set your timezone to anything but UK
  • Create a module
  • Go to module page

Expected behavior Should show that i was created a moment ago.

Screenshots Screenshot 2023-11-03 at 14 20 36

Information (please complete the following information):

  • Node version 18.18.2
  • Bun version 1.0.8

Additional context Add any other context about the problem here.

xhayper avatar Nov 03 '23 07:11 xhayper

I am currently working to resolve the bug thank you.

Yashwanth-Chandrakumar avatar Dec 30 '23 09:12 Yashwanth-Chandrakumar

export function getRelativeTime(date: Date): string { const now = new Date(); const nowUTC = new Date(now.getTime() + now.getTimezoneOffset() * 60000); // Convert now to UTC const dateUTC = new Date(date.getTime() + date.getTimezoneOffset() * 60000); // Convert input date to UTC

const timeDifference = nowUTC.getTime() - dateUTC.getTime();

const minute = 60 * 1000;
const hour = 60 * minute;
const day = 24 * hour;
const week = 7 * day;
const month = 30 * day;
const year = 365 * day;

if (timeDifference < minute) {
  return 'just now';
} else if (timeDifference < hour) {
  const minutesAgo = Math.floor(timeDifference / minute);
  return `${minutesAgo} minute${minutesAgo > 1 ? 's' : ''} ago`;
} else if (timeDifference < day) {
  const hoursAgo = Math.floor(timeDifference / hour);
  return `${hoursAgo} hour${hoursAgo > 1 ? 's' : ''} ago`;
} else if (timeDifference < week) {
  const daysAgo = Math.floor(timeDifference / day);
  return `${daysAgo} day${daysAgo > 1 ? 's' : ''} ago`;
} else if (timeDifference < month) {
  const weeksAgo = Math.floor(timeDifference / week);
  return `${weeksAgo} week${weeksAgo > 1 ? 's' : ''} ago`;
} else if (timeDifference < year) {
  const monthsAgo = Math.floor(timeDifference / month);
  return `${monthsAgo} month${monthsAgo > 1 ? 's' : ''} ago`;
} else {
  const yearsAgo = Math.floor(timeDifference / year);

  return `${yearsAgo} year${yearsAgo > 1 ? 's' : ''} ago`;
}

}

vijeeshin avatar Feb 15 '24 09:02 vijeeshin