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

List of unsupported date strings #2625

Open
1 task
aplefull opened this issue Nov 28, 2024 · 3 comments · May be fixed by #3619
Open
1 task

List of unsupported date strings #2625

aplefull opened this issue Nov 28, 2024 · 3 comments · May be fixed by #3619

Comments

@aplefull
Copy link
Contributor

aplefull commented Nov 28, 2024

Summary

All of the following date strings are parsed by Chrome and Firefox and produce the same time value in both browsers (even though sometimes the value can be unexpected). All of them are currently unsupported by Ladybird. I'm not sure how many of them we want to support for compatibility, but I figured it's better to have a list just in case

Saturday, October 12, 2024
12 October 2024 3:30 PM
12.10.2024
12.10.24
12 octobre 2024
12-OCT-2024
2024.10.12
10/12/24 3:30:00 PM
2024-10-12 3:30:00 PM
2024-10-12 15:30:00.000 +0000
Fri, 11 Oct 2024 22:18:51 GMT+00:00
Fri, 11 Oct 2024 22:18:51 GMT+23:59
Sat Oct 12 2024 22:18:51 GMT+00:00
Fri/11/Oct/2024 22:18:51 UTC
11.Oct.2024.22:18:51 UTC
Sat, 12-Oct-2024 15:30:00 PST
22:18:51 2024
Saturday (Oct 12) 2024
0000000
100000

Operating system

Linux

Steps to reproduce

N/A

Expected behavior

N/A

Actual behavior

N/A

URL for a reduced test case

N/A

HTML/SVG/etc. source for a reduced test case

<body>
  <script>
    // Note that following values are expected in GMT+1
    const dates = [
      ["12 October 2024 3:30 PM", 1728739800000],
      ["12.10.2024", 1733785200000],
      ["12-10-2024", 1733785200000],
      ["12.10.24", 1733785200000],
      ["12 octobre 2024", 1728684000000],
      ["12-OCT-2024", 1728684000000],
      ["2024/10/12", 1728684000000],
      ["2024.10.12", 1728684000000],
      ["10-12-24", 1728684000000],
      ["10/12/24 3:30:00 PM", 1728739800000],
      ["10/12/2024, 12:20:39 AM", 1728685239000],
      ["2024-10-12 3:30:00 PM", 1728739800000],
      ["2024-10-12 15:30:00.000 +0000", 1728747000000],
      ["Fri, 11 Oct 2024 22:18:51 GMT+00:00", 1728685131000],
      ["Fri, 11 Oct 2024 22:18:51 GMT+23:59", 1728598791000],
      ["Sat Oct 12 2024 22:18:51 GMT+00:00", 1728771531000],
      ["Fri/11/Oct/2024 22:18:51 UTC", 1728685131000],
      ["11.Oct.2024.22:18:51 UTC", 1728685131000],
      ["Sat, 12-Oct-2024 15:30:00 PST", 1728775800000],

      // How are these even valid
      ["22:18:51 2024", 1704143931000],
      ["0000000", 946681200000],
      ["100000", 3093527977200000],
      ["Saturday, October 12, 2024", 1728684000000],
      ["Saturday (Oct 12) 2024", 1704063600000],
    ];

    const log = (str) => document.body.appendChild(document.createElement("pre")).textContent = str;

    dates.forEach(([dateString, time]) => {
      const d = new Date(dateString);
      const t = d?.getTime();

      if (t !== time) {
        if (Number.isNaN(t)) {
            log(`Unsupported: ${dateString}`);
        } else {
            log(`String was parsed, but time is incorrect: ${dateString} -> ${t} (expected: ${time})`);
        }
      }
    });
  </script>
</body>

Log output and (if possible) backtrace

N/A

Screenshots or screen recordings

No response

Build flags or config settings

No response

Contribute a patch?

  • I’ll contribute a patch for this myself.
@StringEpsilon
Copy link

StringEpsilon commented Dec 7, 2024

The formats 10/12/24 15:30 and 2024-10-12 15:30:00 also work in both browsers. I found the latter in the wild on my own project.

I decided to take a look at the firefox bugtracker for Date.parse related issue and found a couple more formats that ladybird may want to support.

  • Dec. 7, 2024 (firefox, chrome)
  • Dec-2024 (chrome, firefox has an open bugticket)
  • 1995-Sep-26 00:00:00.001 (firefox, chrome)
  • Sep 26 1995 00:00:00.001 (firefox, chrome)

And others I found on my own:

  • 15:30 12/07/2024 (firefox, chrome)
  • 15:30:00 12/07/2024 (firefox, chrome)
  • 15:30:00.001 12/07/2024 (firefox, chrome)
  • 15:30 2024-12-07, 15:30:00 2024-12-07 and 15:30:00.001 2024-12-07 are rejected by firefox but parsed by chrome.

@manuel-za
Copy link
Contributor

manuel-za commented Dec 7, 2024

The screenshot below (from here) says it all. A worthy, non-trivial challenge! 😎

Background (follow this Discord thread):

Suggestions:

  • An updated test case below (should work on any time zone). Maybe update above?
  • Rename the issue to something like "LibJS: Support for non-standard date strings"?
  • Feel free to use any of this stuff ?
Updated test case (click to open)
<body>
  <script>

// Examples:
    const datesWithTimeZone = [
      ["2024-10-12 15:30:00.000 +0000", 1728747000000],
      ["Fri, 11 Oct 2024 22:18:51 GMT+00:00", 1728685131000],
      ["Fri, 11 Oct 2024 22:18:51 GMT+23:59", 1728598791000],
      ["Sat Oct 12 2024 22:18:51 GMT+00:00", 1728771531000],
      ["Fri/11/Oct/2024 22:18:51 UTC", 1728685131000],
      ["11.Oct.2024.22:18:51 UTC", 1728685131000],
      ["Sat, 12-Oct-2024 15:30:00 PST", 1728775800000],
    ];

    const timeOffsetInExamples = +1 * 3_600_000;
    const datesInGivenTimeZone = [  // Note that following values are expected in GMT+1
      ["12 October 2024 3:30 PM", 1728739800000],
      ["12.10.2024", 1733785200000],
      ["12-10-2024", 1733785200000],
      ["12.10.24", 1733785200000],
      ["12 octobre 2024", 1728684000000],
      ["12-OCT-2024", 1728684000000],
      ["2024/10/12", 1728684000000],
      ["2024.10.12", 1728684000000],
      ["10-12-24", 1728684000000],
      ["10/12/24 3:30:00 PM", 1728739800000],
      ["10/12/2024, 12:20:39 AM", 1728685239000],
      ["2024-10-12 3:30:00 PM", 1728739800000],

      // How are these even valid
      ["22:18:51 2024", 1704143931000],
      ["0000000", 946681200000],
      ["100000", 3093527977200000],
      ["Saturday, October 12, 2024", 1728684000000],
      ["Saturday (Oct 12) 2024", 1704063600000],
    ];

// Plumbing:
    const log = (str) => document.body.appendChild(document.createElement("pre")).textContent = str;
    const assertDateParse = ( dateString, time, deltaTimeOffset = 0 ) => {
      // Alternative formulation.
      // const d = new Date(dateString);
      // const t = d?.getTime() + deltaTimeOffset;

        const t = Date.parse(dateString) + deltaTimeOffset;

        if (Number.isNaN(t)) {
            log(`Unsupported: ${dateString}`);
            return;
        }

        if (t !== time) {
            log(`String was parsed, but time is incorrect: ${dateString} -> ${t} (expected: ${time})`);
            return;
        }

        log(`ok`);
    }

    const myTimeOffset = (() => {  // local time - UTC in milliseconds
      const now = new Date();  // like: Sat Oct 12 2024 01:23:45.678 GMT-0700 (Pacific Daylight Time)
      const date_elem = now.toString().split( ' ' ).slice( 0, 5 );
      date_elem.push( 'UTC' );
      const sameTimeUTC = new Date( date_elem.join( ' ' )); // like: Sat Oct 12 2024 01:23:45 UTC
      const offset = sameTimeUTC.getTime() - now.getTime() + now.getMilliseconds();
      return offset;
    })();

    const deltaTimeOffset = myTimeOffset - timeOffsetInExamples;

// The actual tests:
    datesWithTimeZone   .forEach(([dateString, time]) => assertDateParse( dateString, time )); // date strings with time zone don't need time offset adjustment
    datesInGivenTimeZone.forEach(([dateString, time]) => assertDateParse( dateString, time, deltaTimeOffset ));
  </script>
</body>

:]m @trflynn89

image

@manuel-za
Copy link
Contributor

I'm working on this. Should 🤞 have a PR in a couple of days.

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

Successfully merging a pull request may close this issue.

4 participants