Bug 3477 - some US-centric date formats not parsed by JavaScript (clock at news8austin.com)
Summary: some US-centric date formats not parsed by JavaScript (clock at news8austin.com)
Status: VERIFIED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 412
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Carsten Guenther
URL: http://www.news8austin.com/
Keywords:
Depends on:
Blocks: 3296
  Show dependency treegraph
 
Reported: 2005-06-12 13:25 PDT by Stuart Morgan
Modified: 2005-08-19 09:36 PDT (History)
2 users (show)

See Also:


Attachments
Simple testcase (379 bytes, text/html)
2005-06-14 11:29 PDT, Carsten Guenther
no flags Details
Proposed fix (6.58 KB, patch)
2005-06-14 11:30 PDT, Carsten Guenther
no flags Details | Formatted Diff | Diff
Merged patch from KDE (23.30 KB, patch)
2005-06-17 10:34 PDT, Carsten Guenther
darin: review-
Details | Formatted Diff | Diff
Improved patch (67.57 KB, patch)
2005-06-21 09:37 PDT, Carsten Guenther
darin: review-
Details | Formatted Diff | Diff
Changes without indentation cleanup (23.57 KB, patch)
2005-06-22 15:10 PDT, Carsten Guenther
carsten: review-
Details | Formatted Diff | Diff
Next interation of proposed fix (27.09 KB, patch)
2005-06-24 19:44 PDT, Carsten Guenther
darin: review-
Details | Formatted Diff | Diff
Updated expected.html (120.71 KB, text/html)
2005-06-24 19:47 PDT, Carsten Guenther
no flags Details
Final patch (27.10 KB, patch)
2005-06-25 00:31 PDT, Carsten Guenther
ggaren: review-
Details | Formatted Diff | Diff
New patch including updated layout tests (132.99 KB, patch)
2005-06-30 21:55 PDT, Carsten Guenther
darin: review+
Details | Formatted Diff | Diff
Copyright years update (508 bytes, patch)
2005-07-01 00:14 PDT, Harri Porten
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stuart Morgan 2005-06-12 13:25:58 PDT
The clock in the upper-left corner of news8austin.com always gives 12:45 PST as
the time in Safari, but works in IE and the Mozilla family.

Apple Bug: rdar://3444900
Comment 1 Stuart Morgan 2005-06-12 13:27:56 PDT
10/7/03 9:31 AM Darin Adler:
The problem is that the site provides the date as a string, but it's a string
our version of Date can't parse.

    var now = new Date("10/7/2003 11:30:29 AM")

We'll have to add code to parse dates in this format to fix this.
Comment 2 Carsten Guenther 2005-06-14 10:33:53 PDT
I will have a fix for that soon. Just needs some more testing.
Comment 3 Carsten Guenther 2005-06-14 11:29:33 PDT
Created attachment 2337 [details]
Simple testcase
Comment 4 Carsten Guenther 2005-06-14 11:30:28 PDT
Created attachment 2338 [details]
Proposed fix
Comment 5 Darin Adler 2005-06-15 18:32:38 PDT
Instead of just taking this patch, we might want to take the KDE date_object.cpp, which I believe has 
improvements in handling of this and other similar date formats.
Comment 6 Carsten Guenther 2005-06-15 18:49:21 PDT
I took a look at KHTML's date_object.cpp. They also support the YYYY/MM/DD format, other than that it 
looks not much different.

Let me know what you prefer, I can prepare a patch based on the KHTML source if you want.
Comment 7 Nate Cook 2005-06-16 00:20:41 PDT
I think it would be best to use the KDE version, esp. since they've switched KJS::KRFCDate_parseDate to 
return double, and solved the maximum year 2038 problem as outlined in Bug 3296 and Bug 3417.
Comment 8 Carsten Guenther 2005-06-17 10:34:27 PDT
Created attachment 2444 [details]
Merged patch from KDE

Attached new patch from the KDE code. This fixes this bug and 3296.
Comment 9 Darin Adler 2005-06-18 16:45:51 PDT
Comment on attachment 2444 [details]
Merged patch from KDE

I think it's great to land this improved date code from KDE, presuming that all
the existing date tests we have continue to work.

For future improvements, it's probably worth checking out the FAQ at
<http://www.tondering.dk/claus/calendar.html>, which can answer questions like
the one in the yearFromTime function. In fact, I think
<http://www.tondering.dk/claus/cal/node3.html#SECTION003161000000000000000>
answers that question.

There seems to be a missing "static" in front of timeFromYear, yearFromTime,
and weekDay, which we should add.

I don't understand the need for extrac checks in the part of code that says "if
(utc)". As far as I can tell, ToGMTString and ToUTCString will always set utc
to true, and ToString will always set utc to false, so there's no need for the
additional checks.

The code calls localtime_r inside the __APPLE__ ifdef. If it's no longer
calling localtime() then we should get rid of the macro at the top of the file
changing localtime() calls to localtimeUsingCF() calls. The original reason we
called localtimeUsingCF() instead of localtime() is that localtime() hit the
disk every time; we'll need to test to see that is no longer the case. The
simplest thing to do may be to extend the macro so there's one for localtime_r
too.

I see some tabs in this patch. Please fix that and use only spaces for
indenting.

All the loops that say:

+	   while(*dateString && isspace(*dateString))

could leave out the 0 check. isspace will return false for the 0 character.

The calls to strtol should check the error; I don't think the patch should
remove our errno checking and any call to strtol should check errno after the
fact.

I'm not sure that calling isspace is right -- do we really want characters like
'\n' or '\t' to be allowed in dates, but not Unicode whitespace? I think our
isSpaceOrTab might have been better. We'd need test cases to be sure.

Seems close, but not quite ready to land.
Comment 10 Carsten Guenther 2005-06-21 09:36:48 PDT
Here comes the improved version of the patch.

> There seems to be a missing "static" in front of timeFromYear, yearFromTime,
> and weekDay, which we should add.

Added the missing statics.

> I don't understand the need for extrac checks in the part of code that says "if
> (utc)". As far as I can tell, ToGMTString and ToUTCString will always set utc
> to true, and ToString will always set utc to false, so there's no need for the
> additional checks.

Not excactly sure what tests you mean. Can you give me the line numbers?

> The code calls localtime_r inside the __APPLE__ ifdef. If it's no longer
> calling localtime() then we should get rid of the macro at the top of the file
> changing localtime() calls to localtimeUsingCF() calls. The original reason we
> called localtimeUsingCF() instead of localtime() is that localtime() hit the
> disk every time; we'll need to test to see that is no longer the case. The
> simplest thing to do may be to extend the macro so there's one for localtime_r
> too.

I ran some tests with fs_usage and could not find any disk access when calling localtime(). However, I 
vote for keeping the macros and the core foundation code for now since according to a comment in the 
code it provides us with larger date ranges and I am not sure of all the consequences of removing 
them. This could be addressed in a separate bug.

I also rewrote the one localtime_r to be localtime.

> I see some tabs in this patch. Please fix that and use only spaces for
> indenting.

Cleaned up indendation.

> All the loops that say:
> 
> +          while(*dateString && isspace(*dateString))
> 
> could leave out the 0 check. isspace will return false for the 0 character.

Removed the *dateString test from those loops.

> The calls to strtol should check the error; I don't think the patch should
> remove our errno checking and any call to strtol should check errno after the
> fact.

Put back in the errno checks after calls to strtol.

> I'm not sure that calling isspace is right -- do we really want characters like
> '\n' or '\t' to be allowed in dates, but not Unicode whitespace? I think our
> isSpaceOrTab might have been better. We'd need test cases to be sure.

isSpaceOrTab does not check for more than spaces and tabs either. In addition we should also allow '\r' 
what isspace() does. I ran a quick test with Firefox and it allows both tabs and newlines in dates. So I 
think using isspace() is the right thing until we decide to support all unicode whitespace characters. 
And I am not sure if we should.
Comment 11 Carsten Guenther 2005-06-21 09:37:31 PDT
Created attachment 2533 [details]
Improved patch
Comment 12 Darin Adler 2005-06-21 10:22:09 PDT
Comment on attachment 2533 [details]
Improved patch

Setting the review flag on Carsten's behalf.
Comment 13 Darin Adler 2005-06-22 09:39:44 PDT
Comment on attachment 2533 [details]
Improved patch

I'm not so happy with all the whitespace and indenting changes. There is lots
of code here that hasn't changed at all except that you seem to have run some
program's indenting on it (emacs, perhaps?).

Maybe we should do that in a separate pass, as it makes it harder to spot the
actual changes.

To me, some of the whitespace changes look wrong, too. Like the
strangely-indented body of DateProtoFuncImp::DateProtoFuncImp for example.

My (utc) comment above is about this code:

+    if ( (id == DateProtoFuncImp::ToGMTString) ||
+	  (id == DateProtoFuncImp::ToUTCString) )
+	 t = gmtime(&tv);
+    else if (id == DateProtoFuncImp::ToString)
+	 t = localtime(&tv);
+    else if (utc)
+	 t = gmtime(&tv);
+    else
+	 t = localtime(&tv);

I think the first two if statements are entirely unnecessary.

Because there were so many whitespace changes, I wasn't able to do a thorough
review of the new patch.
Comment 14 Carsten Guenther 2005-06-22 15:10:33 PDT
Created attachment 2552 [details]
Changes without indentation cleanup

Added another patch with the above changes but without the indentation cleanup.


I think you are right about the if(utc) check. I removed the first two if
statements since they are redundant, utc got already set depending on the id
value.
Comment 15 Darin Adler 2005-06-22 19:52:42 PDT
Comment on attachment 2552 [details]
Changes without indentation cleanup

Patch looks great now.

I think we need a better test case now, that covers a lot more cases that the
single test case attached to this bug.

Perhaps we can find one the KDE project is already using? Or maybe with these
changes we can enable the Mozilla date tests.

In any case, the only remaining issue here is that the test case is not good
enough. I will mark this review+, but we should get a much more thorough test
case that covers the new code paths before we land this patch.

In particular, my insistence that we check errno may have resulted in a
stricter function that behaves different than KDE's KJS on various date
strings, so we might end up deciding we need to change that.
Comment 16 Carsten Guenther 2005-06-22 21:39:24 PDT
There is still a problem with dates < 1970, the mozilla test results in 2 regressions. I will look into that.

Also reassigning to myself.
Comment 17 Carsten Guenther 2005-06-24 19:44:31 PDT
Created attachment 2635 [details]
Next interation of proposed fix

Here comes the (hopefully) final patch. It fixes all outstanding issues I could
find with dates that were not in the portable range.

This patch also fixes one of the date tests (ecma_3/Date/15.9.5.5.js), I will
also append the updated expected.html file.

In regards to testcases, I would like to enable all of the mozilla test cases
for dates (the ones in ecma/dates). I did a first run locally and it does not
look too bad. But to fully support those I need to add some code, for example
to create a date object from a bool value. I will open a separate bug for this.
Comment 18 Carsten Guenther 2005-06-24 19:47:24 PDT
Created attachment 2636 [details]
Updated expected.html
Comment 19 Darin Adler 2005-06-24 21:22:37 PDT
Comment on attachment 2635 [details]
Next interation of proposed fix

This line:

+  return seconds == -1 ? NaN : seconds * 1000.0;

should use the constant "invalidDate" rather than a hard-wired -1.

Otherwise, r=me, assuming that our testing is super-thorough. Ideally I'd want
a test date that exercises each branch within the date-parsing function.

Enabling the date tests in the Mozilla JavaScript test suite is a great idea.
I'm so happy this change will allow us to do that!

Harri Porten also showed me a pretty complete date test page the other day. I
suggest contacting him, because I'd like to land that as a layout test.
Comment 20 Carsten Guenther 2005-06-25 00:31:46 PDT
Created attachment 2637 [details]
Final patch

Replaced -1 with invalidDate.
Comment 21 Darin Adler 2005-06-25 00:37:52 PDT
Comment on attachment 2637 [details]
Final patch

r=me
Comment 22 Geoffrey Garen 2005-06-29 13:24:38 PDT
This patch breaks:
     fast/js/date-parse-test

Changing status to reopened and rolling out patch.
Comment 23 Harri Porten 2005-06-29 13:31:05 PDT
Here are the KDE tests:

http://websvn.kde.org/trunk/tests/khtmltests/regression/tests/js/Date.js?rev=424394&view=markup

Not as complete as the Mozilla tests but a) they test the features currently
supported by the implementation and b) test some special, non-standard cases
found on the Web.
Comment 24 Harri Porten 2005-06-29 13:49:25 PDT
As I commented on in another br I think the date-parse-test contains some
questionnable tests. (My) Firefox and Konqueror have 10 failures, IE 9
(partially different ones). Could be that both browsers have their own bugs but
I'd be careful with the interpretation of the results from this test.
Comment 25 Darin Adler 2005-06-29 15:06:52 PDT
The failures are probably due to items in the test that are incorrect. If so, we need to update expected 
results.
Comment 26 Carsten Guenther 2005-06-29 19:27:54 PDT
Sorry about that, I did not run the layout tests after my latest changes. I will look into that later this week.
Comment 27 Carsten Guenther 2005-06-30 21:55:24 PDT
Created attachment 2723 [details]
New patch including updated layout tests

Here comes a new patch that contains date_object.cpp|h, expected.html and a
modified fast/js/date-parse-test.

Let's go through the failed layout tests in detail since they fall into four
groups:

1. Five of the tests were failing because we are checking for errno after every
strtol operation. In one location this was wrong: when we have the year follow
by the timezone, without a time. I removed that check for errno and added a
comment.

2. Six of the tests contained invalid timezone identifiers. Those are invalid
dates and NaN should be returned so the testcases were wrong. In addition to
that our code was wrong too since it produces a number. I added that check for
an unknown timezone and also modified the testcases to have NaN as the expected
result. I also cross-checked with what Firefox does.

3. Two other testcases were wrong in that they assume that "Dec 25 1995 1:30AM"
and "Dec 25 1995 1:30PM" are valid dates. Both are invalid date descriptions,
note the missing space between the time and AM/PM. I modified the testcases to
expect NaN and also cross-checked with Firefox.

4. The remaining two testcases expected NaN althought they are valid: "Dec 25
1995 0:30 AM GMT" and "Dec 25 1995 0:30 PM GMT". Our code produced the right
numbers, again I cross-checked with the results from Firefox. I modified those
two testcases to expect the right results.
Comment 28 Darin Adler 2005-06-30 22:36:46 PDT
Comment on attachment 2723 [details]
New patch including updated layout tests

r=me
Comment 29 Harri Porten 2005-07-01 00:14:08 PDT
Created attachment 2724 [details]
Copyright years update

A one-liner that might make the patch work even better ;)
Comment 30 Harri Porten 2005-07-01 15:21:54 PDT
Comment on attachment 2724 [details]
Copyright years update

Patch accidentally reversed.
Comment 31 Joost de Valk (AlthA) 2005-07-03 07:56:56 PDT
reporter could you veriufy this one? thx.