question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

hasSame order matters / timezones are not working with hasSame

See original GitHub issue

I noticed that when I compared two DateTime objects with hasSame the ordering of the objects returned different results. It seems to only happen when at least one of the objects has a timezone defined.

I managed to reproduce it, let the code speak for itself:

// With zones
const first = DateTime.fromISO("2019-10-02T07:24:04.339+03:00", {
  zone: "Europe/Helsinki"
});
const second = DateTime.fromISO("2019-10-02T00:00:00.000-05:00", {
  zone: "America/Chicago"
});

console.log(first.hasSame(second, "day")); // true
console.log(second.hasSame(first, "day")); // false
console.log(first.toISO()); // 2019-10-02T07:24:04.339+03:00
console.log(second.toISO()); // 2019-10-02T00:00:00.000-05:00

// No zones
const third = DateTime.fromISO("2019-10-02T07:24:04.339+03:00");
const fourth = DateTime.fromISO("2019-10-02T00:00:00.000-05:00");

console.log(third.hasSame(fourth, "day")); // true
console.log(fourth.hasSame(third, "day")); // true
console.log(first.toISO()); // 2019-10-02T07:24:04.339+03:00
console.log(second.toISO()); // 2019-10-02T08:00:00.000+03:00

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
icambroncommented, Oct 26, 2019

It could be! I just need a PR.

0reactions
sebastianvosscommented, Oct 26, 2019

We recently got bitten by this in the context of daylight saving. We were filtering a list of items by item.date.hasSame(today, 'day'). We changed the filter condition to item.date.toISODate() === today.toISODate() to avoid the problem for now. But it would be great if this could be somehow improved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Handle Time Zones using DateTime and Luxon
Raise your hand if you've ever had issues dealing with time zones, or even if you've asked, "How do I convert a Date...
Read more >
Working With Timezones - Knowledgebase
In this article, we'll show you how to work with timezones using The Events ... We'll go over settings, Daylight Savings, and troubleshooting....
Read more >
7 pm jst
Currently has same time zone offset as JST (UTC +9) but different time zone ... fill out an INQUIRY so that their issues...
Read more >
1pm est to utc
Currently has same time zone offset as EDT (UTC -4) but different time zone ... Because, chronic uncertainty may cause anxiety, stress, or...
Read more >
ifollow iptv
11h ago led load resistor not working 11h ago red parrot menu with prices ... My brother in law has same box, same...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found