Closed Bug 1328672 Opened 7 years ago Closed 3 years ago

Date.parse() or new Date() doesn't allow hours only for timezone offset on ISO 8601

Categories

(Core :: JavaScript: Standard Library, defect, P3)

50 Branch
defect

Tracking

()

RESOLVED FIXED
93 Branch
Webcompat Priority P1
Tracking Status
firefox93 --- fixed

People

(Reporter: kyrandita, Assigned: tephra)

References

(Blocks 1 open bug)

Details

(Keywords: parity-chrome, parity-edge, Whiteboard: )

Attachments

(2 files)

User Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0
Build ID: 20161213225203

Steps to reproduce:

run the following JS in the console. (date used was just the first encountered, it seems to be an issue for all ISO 8601 dates)
new Date("2016-12-29 08:30:14-07");
the T replaced with a space seems to be accepted in the latest versions and either way I get the same result.
changing the date string to a 4 digit offset seems to be accepted
2016-12-29 08:30:14-0700
2016-12-29 08:30:14-07:00
but the issue is that the shorthand version (default output of postgres) is not understood


Actual results:

The console reports Invalid Date.


Expected results:

Date should have parsed normally.
Both Chrome and Edge parse these strings, it is the default output for many programs to prefer the shorthand when possible.
Component: Untriaged → JavaScript Engine
Product: Firefox → Core
I see this behaviour too. And it is broke some other applications (in my case - home-assistant, when it draws temperature graph by data from OpenWeatherMap).

I am not familiar with mozilla codebase, but it's seems that to solve this problem, parsing code for timezone minutes in jsdate.cpp in function ParseISOStyleDate need to be changed from 

        NEED_NDIGITS(2, tzMin);

to 

        NEED_NDIGITS_OR_LESS(2, tzMin);

link to the line of code (changeset 348711):
https://hg.mozilla.org/mozilla-central/file/tip/js/src/jsdate.cpp#l899
Blocks: 1274354
Component: JavaScript Engine → JavaScript: Standard Library
Whiteboard: [parity-chrome][parity-edge]
Assignee: nobody → eric
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Priority: -- → P3
Apologies for not working on this. I had a kid and life has been a little crazy. I actually have a patch for this that has been lying around for a while. I'll dig it up and submit!
No need to apologize. No pressure; you're not paid to work on this :)
I'm having some issues with building the shell, getting the error:
 
/mozilla-central/js/src/shell/js.cpp:8893:9: error: unknown type name 'PRLibSpec'
        PRLibSpec libSpec;

And the same error for PR_LibSpec_Pathname, PR_LD_NOW, PR_LD_GLOBAL. Any ideas what the issue might be?
I'm on Mac OSX 10.12.6

I'll upload the diff for the patch since I'm unable to build and test it.
Attached patch v1.patchSplinter Review
(In reply to Eric Skoglund [:tephra] from comment #4)
> And the same error for PR_LibSpec_Pathname, PR_LD_NOW, PR_LD_GLOBAL. Any
> ideas what the issue might be?

See bug 1441454. You can pass --enable-nspr-build to configure to work around it for now.
Someone was asking about this on IRC.

The patch here is not compatible with Chrome, though. They *don't* accept hours-only if there's a "T" present, but they do if you replace the T with a space. I'll check what Edge does. (Also, we shouldn't accept a single digit.)

Safari is actually even more strict than we are.
Edge accepts the hours-only offset for both the 'T' and space versions. Edge and Chrome don't accept -01:0 (has to be 2 digits).

Eric, are you still interested in finishing this? :)
Flags: needinfo?(eric)
(In reply to Jan de Mooij [:jandem] from comment #8)
> Edge accepts the hours-only offset for both the 'T' and space versions. Edge
> and Chrome don't accept -01:0 (has to be 2 digits).
> Eric, are you still interested in finishing this? :)

Sorry for no response! Been busy with the baby :)

I should have time for this tonight so I would love to have another stab
at it and see if I can whip up a neater patch :)

// Eric
Flags: needinfo?(eric)
Mass bug change to replace various 'parity' whiteboard flags with the new canonical keywords. (See bug 1443764 comment 13.)
Whiteboard: [parity-chrome][parity-edge] →
Seems I'm still unable to build firefox, this is even on a different machine (linux this time). I'll take myself of this bug and will try to see if I can get a build working and try to take on some different bugs when I do.
Assignee: eric → nobody
Status: ASSIGNED → NEW
No problem :) What build failures do you get when building the shell?
(In reply to Jan de Mooij [:jandem] from comment #12)
> No problem :) What build failures do you get when building the shell?

This was trying to build firefox as a whole and it was some error while building a rust part.
Not that experienced with rust, so will look over all the requirements again and see if I'm missing
something.
Ah weird. |mach build| should make sure you have an up-to-date Rust compiler and I've never had problems with it. Maybe try updating to mozilla-central tip.

So I guess life really happened...But given that this bug still exists I'll just pick it up 3 years later!

Assignee: nobody → eric

Some programs seems to have this date format as the default output and
it is a format supported by chrome as well.

(In reply to Jan de Mooij [:jandem] from comment #14)

Ah weird. |mach build| should make sure you have an up-to-date Rust compiler
and I've never had problems with it. Maybe try updating to mozilla-central
tip.

Hey Jan, I tagged you as the reviewer in phabricator since I mainly didn't know who to tag and you had interacted with me earlier :)

Attachment #9235453 - Attachment description: WIP: Bug 1328672: Support date format with only two time zone digits. → Bug 1328672: Support date format with only two time zone digits.
Pushed by evilpies@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/042937e67e03
Support date format with only two time zone digits. r=anba
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 93 Branch
Webcompat Priority: --- → P1
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: