keepLocalTime applies day light savings
See original GitHub issueDescribe the bug
I have recently begun using Luxon and I’m really enjoying it so far. Apologies if I have misunderstood the purpose of the keepLocalTime
option. As I understood it, it should return a local time with a different offset but the same date and time. But what I am seeing is day light savings being applied.
To Reproduce
const ny = DateTime.fromISO('2021-03-28T23:59:00.000Z')
.setZone('America/New_York', { keepLocalTime: true })
ny.toFormat('DDDD HH:mm')
// "Monday, 29 March 2021 00:59" (Actual - Unexpected)
// "Monday, 28 March 2021 23:59" (Expected)
const ny2 = luxon.DateTime.fromISO('2021-02-28T23:59:00.000Z')
.setZone('America/New_York', { keepLocalTime: true })
ny2.toFormat('DDDD HH:mm')
// "Sunday, 28 February 2021 23:59" (Expected)
Actual vs Expected behavior
I would have expected ny.toFormat('DDDD HH:mm')
to have given me "Sunday, 28 March 2021 23:59"
but instead it appears to apply DST and prints "Monday, 29 March 2021 00:59"
Desktop:
- OS: Linux Kubuntu
- Browser: Firefox 94.0
- Luxon version:
2.1.1
- Your timezone: Europe/London
Again apologies if I have misunderstood the purpose of the keepLocalTime
and this is actually intentional behaviour.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Python daylight savings time - Stack Overflow
Using time.localtime() , you can ask the same question for any arbitrary time to see whether DST would be (or was) in effect...
Read more >Time Zones and Resolving Ambiguity - Temporal documentation
When Daylight Saving Time (DST) starts or if a country moves to another time zone, then local clocks will instantly change. Exact time...
Read more >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 >Daylight Saving Time | State Legislation
This page reviews current state legislation for Daylight Saving Time. ... The daylight saving time (DST) period in the U.S. begins each year ......
Read more >When React Native Date Pickers and Daylight Savings Collide
This time, however, we do change the moment in time the timestamp represents, using the keepLocalTime: true option. The new DateTime will look...
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
That makes a lot of sense and will help me resolve my issue. Thank you for taking the time to explain it.
Oh, I see. No, this is not a bug. What’s happening is this:
In other words, the DST shift comes from your local zone before the
setZone()
has ever been called.What you meant was to keep the offset from the string. You can do that one of a few ways:
DateTime.fromISO(s, { zone: "UTC"})
DateTime.fromISO(s, { setZone: true })
DateTime.fromISO(s).setZone("utc").setZone("America/New_York", { keepLocalTime: true })