spencermountain / spacetime

A lightweight javascript timezone library
http://spacetime.how/
Other
3.98k stars 184 forks source link

Epoch values not updating for different timezones #399

Closed prenx4x closed 1 year ago

prenx4x commented 1 year ago

I am trying to get epoch value for particular timezone.

const spacetimeNow = spacetime();
console.log(spacetimeNow);
console.log(spacetimeNow.goto("asia/dubai"));
console.log(spacetime.now("asia/dubai"));

Output:

SpaceTime {
  epoch: 1693330667371,
  tz: 'america/toronto',
  silent: true,
  british: undefined,
  _weekStart: 1,
  _today: {}
} 
SpaceTime {
  epoch: 1693330667371,
  tz: 'asia/dubai',
  silent: true,
  british: undefined,
  _weekStart: 1,
  _today: {}
}
SpaceTime {
  epoch: 1693330667371,
  tz: 'asia/dubai',
  silent: true,
  british: undefined,
  _weekStart: 1,
  _today: {}
}

As you can see the epoch is still the same. Isn't it supposed to be different for different timezone. Is this a bug or I am doing something wrong?

Thanks.

spencermountain commented 1 year ago

hey Mufaddal - yep! epoch is like the universal heartbeat - same everywhere. If you want to compare dates, you'll have to compare date-strings, like an ISO or something. ✌️ fellow torontonian cheers

spencermountain commented 1 year ago

ps - hey hissab is cool!

prenx4x commented 1 year ago

@spencermountain Thanks for getting back so quickly. So the actual issue is that I am trying to find difference in timezones using .diff function (or epoch).

I checked https://github.com/spencermountain/spacetime/issues/309 and will try to follow the code snippet you provided.

Are you planning to add timezone difference support in your .diff function anytime soon?

prenx4x commented 1 year ago

ps - hey hissab is cool!

Thanks! I am using spacetime library for all date time calculations in my app (after trying some other popular libraries).

PS - feel free to connect with me on linkedin using the link in the footer of hissab's website. Its great to connect to fellow torontonian dev.