Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime.fromISO doesn't work with space, but javascript's Date.parse does #1609

Closed
toymachiner62 opened this issue Mar 26, 2024 · 4 comments

Comments

@toymachiner62
Copy link

Describe the bug
A clear and concise description of what the bug is.
When a date has a space between the date and time instead of a T, Luxon's DateTime.fromISO() does not parse correctly while the built in javascript Date.parse() does.

I think this is a bug in Luxon and it should properly parse with a space.

DateTime.fromISO('2020-01-01 00:00:00-0800'); // DateTime { Invalid, reason: unparsable }
DateTime.fromISO('2020-01-01T00:00:00-0800'); // DateTime { ts: 2020-01-01T02:00:00.000-06:00, zone: America/Chicago, locale: en-US }
Date.parse('2020-01-01 00:00:00-0800') // 1577865600000
Date.parse('2020-01-01T00:00:00-0800'); // 1577865600000

To Reproduce
Please share a minimal code example that triggers the problem:

Actual vs Expected behavior
A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • OS: Mac OS Ventura 13.6
  • Browser Chrome 123.0.6312.59
  • Luxon version 3.4.4
  • Your timezone America/Chicago

Additional context
Add any other context about the problem here.

@diesieben07
Copy link
Collaborator

diesieben07 commented Mar 26, 2024

DateTime#fromISO parses only ISO 8601, which requires a T, not a space.

Date.parse is only guaranteed to support a simplified version of ISO 8601, so it also requires a T.
Some runtimes might support other formats (like yours with the space), but this is not guaranteed and can change at any time.

See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse and more specifically https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format

See also:
#1325
#990

@toymachiner62
Copy link
Author

The thing that is confusing is that this spec literally says:

NOTE: ISO 8601 defines date and time separated by "T".
      Applications using this syntax may choose, for the sake of
      readability, to specify a full-date and full-time separated by
      (say) a space character.

@dasa
Copy link
Contributor

dasa commented Mar 26, 2024

I raised that as well, but this was Isaac's response: #990 (comment)

@diesieben07
Copy link
Collaborator

That literally says

ISO 8601 defines date and time separated by "T".

There are no ifs or buts about this, if you want valid ISO 8601, you need to use "T".
The given grammar above this paragraph also specifies a "T", nothing else (but the grammar also does not claim to be ISO 8601).
I don't know what the second sentence of the quote is supposed to refer to, however either way it is about RFC 3339, not ISO 8601.

But all this is really moot, because ISO 8601 is unfortunately not something you can just read for free, as far as I know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants