Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
document.lastModified should use the user's local time zone
https://bugs.webkit.org/show_bug.cgi?id=149092
LayoutTests/imported/w3c:

<rdar://problem/22567705>

Reviewed by Ryosuke Niwa.

Rebaseline a couple of W3C tests now that more checks are passing.

* web-platform-tests/html/dom/documents/resource-metadata-management/document-lastModified-01-expected.txt:
* web-platform-tests/html/dom/documents/resource-metadata-management/document-lastModified-expected.txt:

Source/WebCore:

<rdar://problem/22567705>

Reviewed by Ryosuke Niwa.

document.lastModified should use the user's local time zone:
https://html.spec.whatwg.org/multipage/dom.html#dom-document-lastmodified

Chrome and Firefox comply with the specification but WebKit was using
UTC. This patch aligns WebKit's behavior with the specification and
other browsers.

No new tests, already covered by existing tests.

* dom/Document.cpp:
(WebCore::Document::lastModified):
(WebCore::Document::setCookieURL): Deleted.

LayoutTests:

Reviewed by Ryosuke Niwa.

Update test so that it converts document.lastModified to UTF before
printing it. This is so that we can consistent layout tests results, no
matter the system's timezone.

* http/tests/misc/last-modified-parsing-expected.txt:
* http/tests/resources/last-modified.php:

Canonical link: https://commits.webkit.org/167208@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189679 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Sep 14, 2015
1 parent f55f6af commit 7065544
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 29 deletions.
14 changes: 14 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,17 @@
2015-09-13 Chris Dumez <cdumez@apple.com>

document.lastModified should use the user's local time zone
https://bugs.webkit.org/show_bug.cgi?id=149092

Reviewed by Ryosuke Niwa.

Update test so that it converts document.lastModified to UTF before
printing it. This is so that we can consistent layout tests results, no
matter the system's timezone.

* http/tests/misc/last-modified-parsing-expected.txt:
* http/tests/resources/last-modified.php:

2015-09-13 Gyuyoung Kim <gyuyoung.kim@webkit.org>

Unreviewed EFL gardening.
Expand Down
14 changes: 7 additions & 7 deletions LayoutTests/http/tests/misc/last-modified-parsing-expected.txt
Expand Up @@ -3,34 +3,34 @@
--------
Frame: '<!--framePath //<!--frame0-->-->'
--------
11/21/2008 01:03:33
Fri, 21 Nov 2008 01:03:33 GMT

--------
Frame: '<!--framePath //<!--frame1-->-->'
--------
11/21/2008 01:03:33
Fri, 21 Nov 2008 01:03:33 GMT

--------
Frame: '<!--framePath //<!--frame2-->-->'
--------
11/21/1997 01:03:33
Fri, 21 Nov 1997 01:03:33 GMT

--------
Frame: '<!--framePath //<!--frame3-->-->'
--------
11/21/2008 01:03:33
Fri, 21 Nov 2008 01:03:33 GMT

--------
Frame: '<!--framePath //<!--frame4-->-->'
--------
02/21/2008 01:03:33
Thu, 21 Feb 2008 01:03:33 GMT

--------
Frame: '<!--framePath //<!--frame5-->-->'
--------
02/03/2008 01:03:33
Sun, 03 Feb 2008 01:03:33 GMT

--------
Frame: '<!--framePath //<!--frame6-->-->'
--------
03/03/2008 01:03:33
Mon, 03 Mar 2008 01:03:33 GMT
2 changes: 1 addition & 1 deletion LayoutTests/http/tests/resources/last-modified.php
Expand Up @@ -3,5 +3,5 @@
header("Last-Modified: $date");
?>
<script>
document.write(document.lastModified);
document.write((new Date(document.lastModified)).toUTCString());
</script>
13 changes: 13 additions & 0 deletions LayoutTests/imported/w3c/ChangeLog
@@ -1,3 +1,16 @@
2015-09-13 Chris Dumez <cdumez@apple.com>

document.lastModified should use the user's local time zone
https://bugs.webkit.org/show_bug.cgi?id=149092
<rdar://problem/22567705>

Reviewed by Ryosuke Niwa.

Rebaseline a couple of W3C tests now that more checks are passing.

* web-platform-tests/html/dom/documents/resource-metadata-management/document-lastModified-01-expected.txt:
* web-platform-tests/html/dom/documents/resource-metadata-management/document-lastModified-expected.txt:

2015-09-13 Chris Dumez <cdumez@apple.com>

Node.baseURI should not return null for detached nodes
Expand Down
@@ -1,6 +1,6 @@

FAIL Date returned by lastModified is current at page load assert_true: expected true got false
PASS Date returned by lastModified is current at page load
PASS Date returned by lastModified is in the form "MM/DD/YYYY hh:mm:ss".
FAIL Date returned by lastModified is in the user's local time zone. assert_true: expected true got false
FAIL Date returned by lastModified is current after timeout. assert_true: expected true got false
PASS Date returned by lastModified is in the user's local time zone.
PASS Date returned by lastModified is current after timeout.

@@ -1,3 +1,3 @@

FAIL lastModified should return the last modified date and time assert_equals: expected "12/31/1969 17:23:45" but got "01/01/1970 01:23:45"
PASS lastModified should return the last modified date and time

21 changes: 21 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,24 @@
2015-09-13 Chris Dumez <cdumez@apple.com>

document.lastModified should use the user's local time zone
https://bugs.webkit.org/show_bug.cgi?id=149092
<rdar://problem/22567705>

Reviewed by Ryosuke Niwa.

document.lastModified should use the user's local time zone:
https://html.spec.whatwg.org/multipage/dom.html#dom-document-lastmodified

Chrome and Firefox comply with the specification but WebKit was using
UTC. This patch aligns WebKit's behavior with the specification and
other browsers.

No new tests, already covered by existing tests.

* dom/Document.cpp:
(WebCore::Document::lastModified):
(WebCore::Document::setCookieURL): Deleted.

2015-09-13 Chris Dumez <cdumez@apple.com>

Node.baseURI should not return null for detached nodes
Expand Down
31 changes: 14 additions & 17 deletions Source/WebCore/dom/Document.cpp
Expand Up @@ -161,6 +161,7 @@
#include "XPathResult.h"
#include "htmlediting.h"
#include <JavaScriptCore/Profile.h>
#include <ctime>
#include <inspector/ScriptCallStack.h>
#include <wtf/CurrentTime.h>
#include <wtf/TemporaryChange.h>
Expand Down Expand Up @@ -4236,34 +4237,30 @@ void Document::setDomain(const String& newDomain, ExceptionCode& ec)
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-lastmodified
String Document::lastModified() const
{
DateComponents date;
bool foundDate = false;
if (m_frame) {
auto lastModifiedDate = loader() ? loader()->response().lastModified() : Nullopt;
if (lastModifiedDate) {
using namespace std::chrono;
date.setMillisecondsSinceEpochForDateTime(duration_cast<milliseconds>(lastModifiedDate.value().time_since_epoch()).count());
foundDate = true;
}
}
using namespace std::chrono;
Optional<system_clock::time_point> dateTime;
if (m_frame && loader())
dateTime = loader()->response().lastModified();

// FIXME: If this document came from the file system, the HTML5
// specificiation tells us to read the last modification date from the file
// specification tells us to read the last modification date from the file
// system.
if (!foundDate) {
double fallbackDate = currentTimeMS();
if (!dateTime) {
dateTime = system_clock::now();
#if ENABLE(WEB_REPLAY)
InputCursor& cursor = inputCursor();
if (cursor.isCapturing())
cursor.appendInput<DocumentLastModifiedDate>(fallbackDate);
cursor.appendInput<DocumentLastModifiedDate>(duration_cast<milliseconds>(dateTime.value().time_since_epoch()).count());
else if (cursor.isReplaying()) {
if (DocumentLastModifiedDate* input = cursor.fetchInput<DocumentLastModifiedDate>())
fallbackDate = input->fallbackValue();
dateTime = system_clock::time_point(milliseconds(static_cast<long long>(input->fallbackValue())));
}
#endif
date.setMillisecondsSinceEpochForDateTime(fallbackDate);
}

return String::format("%02d/%02d/%04d %02d:%02d:%02d", date.month() + 1, date.monthDay(), date.fullYear(), date.hour(), date.minute(), date.second());
auto ctime = system_clock::to_time_t(dateTime.value());
auto localDateTime = std::localtime(&ctime);
return String::format("%02d/%02d/%04d %02d:%02d:%02d", localDateTime->tm_mon + 1, localDateTime->tm_mday, 1900 + localDateTime->tm_year, localDateTime->tm_hour, localDateTime->tm_min, localDateTime->tm_sec);
}

void Document::setCookieURL(const URL& url)
Expand Down

0 comments on commit 7065544

Please sign in to comment.