hasSame order matters / timezones are not working with hasSame
See original GitHub issueI 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:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It could be! I just need a PR.
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 toitem.date.toISODate() === today.toISODate()
to avoid the problem for now. But it would be great if this could be somehow improved.