moment / luxon

⏱ A library for working with dates and times in JS
https://moment.github.io/luxon
MIT License
15.05k stars 730 forks source link

startOf() returning object with incorrect TimeZone offset #1612

Closed sluther closed 3 months ago

sluther commented 3 months ago

Describe the bug Calling startOf() on any date object returns an object with the incorrect TimeZone Offset

To Reproduce

const test = DateTime.now().setZone('US/Eastern');

const testStart = test.startOf('month');
const testEnd = test.endOf('month');

console.log(`testStart: ${testStart.toISO()}`);
console.log(`testEnd: ${testEnd.toISO()}`);

Actual vs Expected behavior Actual behavior:

testStart: 2024-03-01T00:00:00.000-05:00 <------ Note the incorrect offset here
testEnd: 2024-03-31T23:59:59.999-04:00   <-----  Note the correct offset here

Expect to see the following in the console:

testStart: 2024-03-01T00:00:00.000-04:00
testEnd: 2024-03-31T23:59:59.999-04:00

Desktop (please complete the following information):

diesieben07 commented 3 months ago

The "Eastern Time Zone" observes daylight saving time (Eastern Standard Time at UTC-5 and Eastern Daylight Time at UTC-4). Because the switch happens in March, the offset from UTC is different on 2024-03-01 than on 2024-03-31.