Bug 335556 - Date() constructor treats time as UTC instead of localtime
Summary: Date() constructor treats time as UTC instead of localtime
Status: RESOLVED FIXED
Alias: None
Product: konqueror
Classification: Applications
Component: kjs (show other bugs)
Version: 4.13.1
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-29 20:32 UTC by Wolfgang Bauer
Modified: 2014-06-26 13:15 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In: 4.13.3
Sentry Crash Report:


Attachments
html file demonstrating the issue (441 bytes, text/html)
2014-05-29 20:33 UTC, Wolfgang Bauer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Bauer 2014-05-29 20:32:06 UTC
When creating a new Date() object with a specific date/time, that passed time is treated as UTC, although it should be localtime.

Reproducible: Always

Steps to Reproduce:
1. Open attached html file in Konqueror

Actual Results:  
Wrong time is displayed (according to your time zone)

Expected Results:  
The time that is passed to the constructor should be shown.

Other browsers, like Firefox or even Konqueror with the WebKit engine, treat the time as local time. 

The specification does not clearly state whether that time should be treated as UTC or localtime AFAICS, but there's an explicit note in the documentation of the Date.UTC() function:
NOTE    The UTC function differs from the Date constructor in two ways: it returns a time value as a Number, rather than creating a Date object, and it interprets the arguments in UTC rather than as local time.
(http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.4.3)
Comment 1 Wolfgang Bauer 2014-05-29 20:33:08 UTC
Created attachment 86908 [details]
html file demonstrating the issue
Comment 2 Wolfgang Bauer 2014-06-26 10:41:56 UTC
This actually worked fine until 4.9.1 and broke in 4.9.2.

I was able to track it down to this commit:
https://projects.kde.org/projects/kde/kdelibs/repository/revisions/48dd1fc50277b861b49613c5f46b6f8b10cc932d

See https://git.reviewboard.kde.org/r/118947/ for a proposed fix.
Comment 3 Wolfgang Bauer 2014-06-26 12:03:00 UTC
Git commit 0137c691cfe02e6fc0c99e2ced15aea149e56b4b by Wolfgang Bauer.
Committed on 26/06/2014 at 11:55.
Pushed by wbauer into branch 'KDE/4.13'.

KJS: treat time correctly as localtime in the Date() constructor

Commit 48dd1fc50277b861b49613c5f46b6f8b10cc932d introduced a bug:
It factors out the code to convert a time specification to an actual
time value into the function makeTimeFromList().
But in that function makeTime(&t, ms, true) is called, whereas the
original code called makeTime(&t, ms, false) for the constructor.

This patch fixes it by passing the "utc" parameter to makeTime() instead
of "true".
FIXED-IN: 3.13.3
REVIEW: 118947

M  +1    -1    kjs/date_object.cpp

http://commits.kde.org/kdelibs/0137c691cfe02e6fc0c99e2ced15aea149e56b4b
Comment 4 Wolfgang Bauer 2014-06-26 12:18:15 UTC
Git commit 786e0a7821f195c5a227e72a41d29033851dc2af by Wolfgang Bauer.
Committed on 26/06/2014 at 11:55.
Pushed by wbauer into branch 'master'.

KJS: treat time correctly as localtime in the Date() constructor

Commit 48dd1fc50277b861b49613c5f46b6f8b10cc932d introduced a bug:
It factors out the code to convert a time specification to an actual
time value into the function makeTimeFromList().
But in that function makeTime(&t, ms, true) is called, whereas the
original code called makeTime(&t, ms, false) for the constructor.

This patch fixes it by passing the "utc" parameter to makeTime() instead
of "true".
FIXED-IN: 3.13.3
REVIEW: 118947
(cherry picked from commit 0137c691cfe02e6fc0c99e2ced15aea149e56b4b)

M  +1    -1    kjs/date_object.cpp

http://commits.kde.org/kdelibs/786e0a7821f195c5a227e72a41d29033851dc2af
Comment 5 Wolfgang Bauer 2014-06-26 12:25:15 UTC
Git commit 198c1819e382aed93a574c6f9d51c7303985a672 by Wolfgang Bauer.
Committed on 26/06/2014 at 12:21.
Pushed by wbauer into branch 'master'.

treat specified time correctly as localtime in the Date() constructor

Commit 48dd1fc50277b861b49613c5f46b6f8b10cc932d (in KDE4's kdelibs)
introduced a bug:
It factors out the code to convert a time specification to an actual
time value into the function makeTimeFromList().
But in that function makeTime(&t, ms, true) is called, whereas the
original code called makeTime(&t, ms, false) for the constructor.

This patch fixes it by passing the "utc" parameter to makeTime() instead
of "true".
FIXED-IN: 3.13.3
REVIEW: 118947

M  +1    -1    src/kjs/date_object.cpp

http://commits.kde.org/kjs/198c1819e382aed93a574c6f9d51c7303985a672