moment / luxon

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

DateTime.fromISO behaviour inconsistent with docs #1531

Open onlyskin opened 9 months ago

onlyskin commented 9 months ago

Describe the bug Constructing a DateTime instance from a zoned ISO string creates a DateTime instance with the local timezone not with the timezone from the string.

To Reproduce DateTime.fromISO('2016-05-25T09:00:00.000+06:00').zone.name will log your local timezone name, not the +06:00 DateTime.fromISO('2016-05-25T09:00:00.000+06:00', {zone: 'UTC+6'}).zone.name will log the correct timezone offset

same thing happens if you set the ISO string timezone to UTC or a geographical zone

Actual vs Expected behavior The docs for the DateTime.fromISO method state for opts.zone: "use this zone if no offset is specified in the input string itself. Will also convert the time to this zone". This implied to me that if I did not specify the opts.zone it would return a DateTime instance zoned to match the ISO string and caused some confusion. Would be better to say something like "Specify a zone for the DateTime instance. If the input string does not specify a timezone, parse it as a local time in the opts.zone offset."

I think it would be sufficient to update the documentation to make it clear this is the behaviour.

Desktop (please complete the following information):