-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Comments
The formats I decided to take a look at the firefox bugtracker for
And others I found on my own:
|
The screenshot below (from here) says it all. A worthy, non-trivial challenge! 😎 Background (follow this Discord thread):
Suggestions:
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 |
I'm working on this. Should 🤞 have a PR in a couple of days. |
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
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
Log output and (if possible) backtrace
Screenshots or screen recordings
No response
Build flags or config settings
No response
Contribute a patch?
The text was updated successfully, but these errors were encountered: