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

Feature request: Add 'T' character if needed to ISO-8601 strings #1325

Closed
jamesexplo opened this issue Nov 14, 2022 · 5 comments
Closed

Feature request: Add 'T' character if needed to ISO-8601 strings #1325

jamesexplo opened this issue Nov 14, 2022 · 5 comments

Comments

@jamesexplo
Copy link

When trying to use DateTime.fromISO for an ISO-8601 string that contains a space instead of a T character (aka, instead of 2022-11-14T19:56:20, a string like 2022-11-14 19:56:20, Luxon should handle this alternative format or should provide an option to allow the T to be added.

@dasa
Copy link
Contributor

dasa commented Nov 15, 2022

Related to #990

@jamesexplo
Copy link
Author

@dasa what was the solution for this? I don't see any relevant commits around the time 990 was closed and no option such as allowSpaceSeparator but maybe I am missing something.

@dasa
Copy link
Contributor

dasa commented Nov 15, 2022

I closed #990 since it seemed to be rejected, but here's my own workaround:

  // ISO 8601 time extension starts with T and then two digits.
  // Moment and RFC 3339 also allow the use of a space char instead.
  // https://github.com/moment/luxon/issues/990
  const re = / (\d\d)/;
  let dateTime = DateTime.fromISO(v);
  if (dateTime.isValid) {
    return dateTime;
  } else if (re.test(v)) {
    // replace space with a T and try again
    v = v.replace(re, "T$1");
    dateTime = DateTime.fromISO(v);
    if (dateTime.isValid) {
      return dateTime;
    }
  }

@icambron
Copy link
Member

As far as I understand it, the string with a space in it isn't an ISO 8601 string. I don't want to support it because a lot of people rely on Luxon's validations to (mostly) filter out bad ISO strings that other parsers downstream may choke on.

Note that fromSQL accepts a space there

@diesieben07
Copy link
Collaborator

Like @icambron said, only T is allowed as a separator in ISO 8601. You can use fromSQL or a custom format using fromFormat to parse formats that are not ISO 8601.
As such I am going to close this.

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

4 participants