JuditKaramazov / TakeYouThere

🚀🌿 karamaSystem v3 - An interactive map enabling us to pin and share pictures of places we've visited together.
https://takeyouthere.vercel.app
MIT License
16 stars 5 forks source link

Bug: Date Not Correctly Posted #17

Open luigar opened 2 weeks ago

luigar commented 2 weeks ago

Describe the bug

Adding PINS with a date are showing 1 day before the actual date , example 2024-06-12 is posting as 2024-06-11 same with other dates.

Steps to reproduce

  1. Add location in places.ts
  2. Refresh server
  3. View Map Pin

Do you have any screenshots?

image (8) image (7)

Code of Conduct

Contributing Docs

JuditKaramazov commented 1 week ago

Welcome, luigar!

First of all, excuse me for my belated response; it's been a complicated time! After having a look at the code (as well as my pictures and dates), I must admit I never encountered the problem you're experiencing. That's why, after thinking of it, I concluded that it might be related to different time zones, as I kept in mind Europe/Madrid (Barcelona, to be more specific), but I didn't consider other options.

In all honesty, the getRelativeTimeString function might be potentially problematic due to the way it handles dates and times - especially when it comes to different time zones. Could you please give the following alternative a try and tell me if it solves your problem?

export const getRelativeTimeString = (date: string) => {
  const parsedDate = DateTime.fromISO(date, { zone: 'utc' }); // You'll have to explicitly set the zone here.
  const relativeTime = parsedDate.toRelative();

  // Formatting the date in a specific time zone might help, too. Let's say 'Europe/London' here, for instance.
  const formattedDate = parsedDate.setZone('Europe/London').toLocaleString(DateTime.DATETIME_MED);

  return `${relativeTime} (${formattedDate})`;
}

Perhaps we should explicitly handle time zones when parsing and formatting dates for more consistent behavior. Let me know if it works for you; if that's not the case, we'll look for another solution! Best wishes,

Judit