Closed Bug 127246 Opened 18 years ago Closed Last month

Date() gives wrong timezone after time zone change

Categories

(Core :: JavaScript Engine, defect, minor)

defect
Not set
minor

Tracking

()

RESOLVED DUPLICATE of bug 1348916

People

(Reporter: andreas.hoefler, Unassigned)

References

(Blocks 1 open bug, )

Details

(Keywords: helpwanted, js1.5)

Attachments

(2 files, 1 obsolete file)

When getting the time via the javascript-object Date on Win2000 gives me a time
as if my timezone would be set to somewhere in america.
But my timezone is set to GMT+0100 (central europe) and all functions, which
fetch the time from the Date-object give a time which is about 10h below the
time it should give.

sample code for time-output:

<html><head></head>
<body>
<script type="text/javascript">
<!--
 var now = new Date();
 document.write(now.toLocaleString());
//-->
</script>
</body></html>

*** This bug has been marked as a duplicate of 65671 ***
Status: UNCONFIRMED → RESOLVED
Closed: 18 years ago
Resolution: --- → DUPLICATE
Reopening bug.

This doesn't sound like bug 65671, which is about a 24-hour discrepancy
for Unix/Linux users in the GMT+0 timezone only -
Status: RESOLVED → UNCONFIRMED
Resolution: DUPLICATE → ---
Attached file testcase #1
On my WinNT box, I changed my timezone to this:

    (GMT +01:00)Brussels, Berlin, Bern, Rome, Stockholm, Vienna


Then I changed my system clock to 11:59:50 PM. By trial-and-error
I got testcase #1 to finish exactly at midnight. Save the source of
testcase #1 locally to make this easier to do. Here are my results.
(Note only the second half of the test is affected by the system clock) 


**************************** new Date(2002, 0, 1) *****************************
toString()
Tue Jan 01 2002 00:00:00 GMT+0100
toGMTString()
Mon, 31 Dec 2001 23:00:00 GMT
toUTCString()
Mon, 31 Dec 2001 23:00:00 GMT
toLocaleString()
Tuesday, January 01, 2002 00:00:00


**************************** new Date() ***************************************
toString()
Sat Mar 16 2002 00:00:00 GMT+0100
toGMTString()
Fri, 15 Mar 2002 23:00:00 GMT
toUTCString()
Fri, 15 Mar 2002 23:00:00 GMT
toLocaleString()
Saturday, March 16, 2002 00:00:00
Andreas, are you in the Vienna timezone? Could you try testcase #1
and copy your results the way I have done above? Thanks -
Again, if you want to try to time the result to finish exactly at midnight,
the way I did, it will be easier if you save the source of testcase #1
locally and run it that way, rather than off the Bugzilla server -
I don't know why my "new Date()" results say "Mar 16" !!!
I must have accidentally changed the day when I changed the time; sorry.
Anyway, it's the hour and timezone measurements that really count here.
Well, yes: my Win2k pc has the settings from "German(Austria)".

But I don't need to adjust my system clock to show, what's wrong:

**************************** new Date(2002, 0, 1) ****************************
toString() 
Tue Jan 01 2002 00:00:00 GMT-0800 (PST)
toGMTString()
Tue, 01 Jan 2002 08:00:00 GMT
toUTCString()
Tue, 01 Jan 2002 08:00:00 GMT
toLocaleString()
Tuesday, January 01, 2002 00:00:00


**************************** new Date() ****************************
toString()
Thu Mar 07 2002 23:16:42 GMT-0800 (PST)
toGMTString()
Fri, 08 Mar 2002 07:16:42 GMT
toUTCString()
Fri, 08 Mar 2002 07:16:42 GMT
toLocaleString()
Thursday, March 07, 2002 23:16:42

According to toString, I'm living in GMT-0800... But the timezone-tab in my
systray-clock tells me, that I'm in the timezone "(GMT+01:00) Amsterdam, Berlin,
Bern, ... , Vienna"
Confirming bug. We ran testcase #1 on rogerl's Win2K machine, and
no matter what timezone we set it to, we got Pacific Standard Time.
We were careful to relaunch Mozilla each time we changed the timezone -

Raising severity to major; cc'ing Patrick, Steve, Brendan, and jband
for his Windows expertise. We should fix this ASAP. The bug never shows
up for me on my WinNT machine, but there is something different about
Win2K somehow - HELP!
Assignee: rogerl → khanson
Severity: normal → major
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: Date() gives time of wrong timezone → Date() gives wrong timezone on Win2K
Keywords: js1.5
cc'ing Mike -
I am seeing the same behavior on Roger's Windows2000 system (comment #9). 
However, when I turned the machine off and restarted it, the testcase above
exhibited the changed time, i.e., the changed time I left in the machine at
shutdown.

Andreas, could you turn your machine off and restart it.  I would expect the new
local time to be observed.  
I meant changed timezone.
I also observed that the screen clock refllected the correct timezone changed by
the Date and Time control panel.  However, the printed Netscape windows in the
above tests had the incorrect time in the page footer.  I am not sure where the
footer time is found?
err... the attachment doesn't contain any javascript, that outputs dates?
Where has the testcase gone?
This is not the code anymore, as it was when I viewed the testcase a while ago,
AFAICR...

Is there an error with bugzilla lurking around?
Andreas, can you confirm what Kenton says in Comment #11? That is, if you 
shut down your box and restart it, do you see the correct timezone then?
Ok folks, I got the testcase again from Phil and tried it once again. The
results are quite nice :) :
It seems, that meanwhile Mozilla (my current build is 2002042808) recognizes the
change of the timezone correctly. Same with calculation of local time.

I'm re-uploading the attachment once again, because the current attachment seems
to be broken.

before reboot (with timezone: GMT+0100) (dst is active)
DATE TESTS:

new Date(2002, 0, 1)toString()
Tue Jan 01 2002 00:00:00 GMT+0100
toGMTString()
Mon, 31 Dec 2001 23:00:00 GMT
toUTCString()
Mon, 31 Dec 2001 23:00:00 GMT
toLocaleString()
Tuesday, January 01, 2002 00:00:00

new Date()toString()
Tue Apr 30 2002 07:09:10 GMT+0200
toGMTString()
Tue, 30 Apr 2002 05:09:10 GMT
toUTCString()
Tue, 30 Apr 2002 05:09:10 GMT
toLocaleString()
Tuesday, April 30, 2002 07:09:10

*************************************************************
before reboot (changed timezone to GMT-0300) (after full restart of mozilla)
DATE TESTS:

new Date(2002, 0, 1)toString()
Tue Jan 01 2002 00:00:00 GMT-0200
toGMTString()
Tue, 01 Jan 2002 02:00:00 GMT
toUTCString()
Tue, 01 Jan 2002 02:00:00 GMT
toLocaleString()
Tuesday, January 01, 2002 00:00:00

new Date()toString()
Tue Apr 30 2002 02:12:00 GMT-0300
toGMTString()
Tue, 30 Apr 2002 05:12:00 GMT
toUTCString()
Tue, 30 Apr 2002 05:12:00 GMT
toLocaleString()
Tuesday, April 30, 2002 02:12:00

*************************************************************
before reboot (changed timezone back to GMT+0100) (after full restart of mozilla)
DATE TESTS:

new Date(2002, 0, 1)toString()
Tue Jan 01 2002 00:00:00 GMT+0100
toGMTString()
Mon, 31 Dec 2001 23:00:00 GMT
toUTCString()
Mon, 31 Dec 2001 23:00:00 GMT
toLocaleString()
Tuesday, January 01, 2002 00:00:00

new Date()toString()
Tue Apr 30 2002 07:15:07 GMT+0200
toGMTString()
Tue, 30 Apr 2002 05:15:07 GMT
toUTCString()
Tue, 30 Apr 2002 05:15:07 GMT
toLocaleString()
Tuesday, April 30, 2002 07:15:07
This testcase reads out the different times available of the Date()-Object and
writes them to the screen. (Replacement for previous but somehow broken
attachment)
Err... can someone tell me what's up with the attachments?!?
Att. 2 is identical to att. 1 but neither one contains the code for the
testcase. What the heck is going on within BZ?
This may be related to bug #44070
Blocks: 149801
Any news on this one?

/be
see comments #11 - #16.  The only problem that occurs is on a win2k machine when
the timezone is changed.  It doesn't ripple up to JavaScript.  I suspect some
variable is read at boot time and is used by JavaScript.  Rebooting a win2k
machine fixes the problem.  Unless your flying across time zones I don't see it
as a serious problem.  I vote for Wontfix.
i'm opposed to wontfix

http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/sysinfo/time_7ory.asp

Remarks

To inform Explorer that the time zone has changed, send the WM_SETTINGCHANGE 
message.

this looks like a job for spy++
Severity: major → minor
Keywords: helpwanted
Summary: Date() gives wrong timezone on Win2K → Date() gives wrong timezone on Win2K after time zone change
Depends on: 155771
*** Bug 115942 has been marked as a duplicate of this bug. ***
Just confirmed that Mac OS 9 and Mac OS X also now behave this way; please
change platform/OS to All and remove Win2k from the summary.  To reproduce:

1) type javascipt:new Date();
2) change the time zone
3) click in the address bar and press enter to get the date again

Expected results:  you should see the local time in the new time zone, and the
new offset from GMT.

Actual results:  you get the local time in the old time zone, with the old
offset from GMT.  So, nothing breaks internally, but the local time is now off
if you're displaying it for the user.  I haven't confirmed whether Daylight
Savings Time behaves the same way as a timezone change for this purpose, but I'd
expect so, and that happens automatically for many users.
Changing description as requested -
OS: Windows 2000 → All
Hardware: PC → All
Summary: Date() gives wrong timezone on Win2K after time zone change → Date() gives wrong timezone after time zone change
I have a duplicate of this bug as originally reported, for Win2000, which I have
reported under bug 83914. But my problem sounds like Andreas' original one when
he made no mention of recently changing time zones. My time zone has been fixed
at +0100 for two months, before I downloaded Mozilla/5.0 (Windows; U; Windows NT
5.0; en-US; rv:1.4b) Gecko/20030507. Maybe I can work round it by changing the
time zone, rebooting etc as Andreas did. But it is still a bug.
peter.r.kirk@ntlworld.com:

1) What timezone are you in - London? "+0100" is indeterminate
   this time of year, when Daylight Savings Time is in effect. 

2) What happens if you enter this in the URL bar:  javascript:new Date();
   What date does Mozilla print out? How about IE?

3) If Mozilla does not display your timezone, what happens
   if you reboot the computer and try again right afterward?

4) What version of Win2K do you have ?(Windows Explorer > Help > About Windows) 

5) Have you set a "Regional Setting" in the Windows control panel?
   If so, which one? 


Thanks - I am currently having no trouble changing timezones on my
own Win2K box (version 5.0 Service Pack 2). I have to restart Mozilla
after I change the timezone, but I don't have to reboot the computer.
Entering |javascript:new Date();| gives me the new timezone.

I am using Mozilla trunk binary 2003050704 (rv:1.4b) -
1) I am in UK, near London, with daylight saving.
2) in Mozilla: Wed May 28 2003 15:35:58 GMT-0700 (PDT)
   in IE6:     Wed May 28 23:37:05 UTC+0100 2003
3) I'll try that a bit later
4) Version 5.0 (Build 2195: Service Pack 3)
5) Under Regional Options, my locale is English (United Kingdom). I have several
additional languages set up. Is that what you mean?
Rebooted, I now get Wed May 28 2003 15:49:48 GMT-0700 (PDT), no change except
for showing how long my system takes to reboot.
Peter: thanks, that is very helpful. I just can't figure out
why the bug still occurs after a complete machine reboot!

I know the JS Engine tries to pick up the timezone from the OS.
Perhaps if that fails, it defaults to the California timezone (?)

I'll ask the developers, and try some more Win2K machines on my end -
Phil, have you made any progress on this bug? After more than a month all my
message times are still eight hours wrong. Actually I spent two weeks of that
month with my laptop in GMT+0500 (including daylight saving), and there all my
messages times were twelve hours out which is a bit easier to work with. But the
two changes of time zone, and numerous reboots, did nothing to solve the
problem. So this is not something special with GMT+0100 as I suspected.
javascript:new Date(); still gives the time as GMT-0700. Now running Mozilla/5.0
(Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624.
Peter: sorry for the delay. Roger has been away on vacation; 
a brief look did not uncover why this might be happening.
I personally have not been able to reproduce the bug on Win2000.

Brendan, jband: do you know of any place where Mozilla date code
might default to California time if the normal timezone queries
to the OS fail? I can't think of any other explanation of why
Peter is stuck with California time no matter what he does.

Note, Peter is testing via |javascript:new Date();|
I still have this problem (see comment 26 and following) despite upgrading, now
to Mozilla 1.6. Daylight saving ended but the reported times remained eight
hours out.
Could the distinction here be between FAT and NTFS systems? See bug 136049
comments 49, 51 and 53. I had this problem on my Windows 2000 system with FAT,
but it went away on my new Windows XP system with NTFS. So maybe bug 136049 (not
really fixed) is dependent on this one.

Bug 244358 (also not really fixed, although no longer a problem for me) may also
be dependent on this one, see bug 244358 comment 5.
See bug 173242 comment 2 for an explanation of the GMT+0100 problem.
(In reply to comment #35)
> See bug 173242 comment 2 for an explanation of the GMT+0100 problem.

Thank you, Mike. This seems to confirm comment 34. So I guess the fix for at
least my part of this bug (on Windows NT/2000/XP only) is to change to NTFS -
with the disadvantage that you cannot easily read your files from DOS or Windows
9x. That is, from the Mozilla viewpoint it should be a WONTFIX.

I'm not sure if this applies to all aspects of this bug.
Blocks: 285663
*** Bug 241276 has been marked as a duplicate of this bug. ***
Assignee: khanson → general
QA Contact: pschwartau → general
Duplicate of this bug: 424867
Duplicate of this bug: 424867
The same happens for the JSON backup filename proposal of the Library. After a timezone change the old timezone is used until the browser has been restarted.
Flags: blocking1.9.2?
Duplicate of this bug: 492056
  Description  From  Marco Pesenti Gritti

When the system timezone is changed, Date keeps using the old one. It looks
like it's cached by the class initializer:

http://mxr.mozilla.org/mozilla-central/source/js/src/jsdate.cpp#2171
Flags: wanted1.9.2+
Flags: blocking1.9.2?
Flags: blocking1.9.2-
Duplicate of this bug: 424867
Assignee: general → nobody
Attachment #9012885 - Attachment is obsolete: true

bug 1348916 also tracks missing updates when the host time zone changes and has newer info, so let's dup this to that bug.

Status: NEW → RESOLVED
Closed: 18 years agoLast month
Resolution: --- → DUPLICATE
Duplicate of bug: 1348916
You need to log in before you can comment on or make changes to this bug.