Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2009-10-29
09:38 • Ticket [2049971fff] clock command doesn't reflect Windows time zone changes<... artifact: 4656b6ab2e user: kennykb
2008-08-26
05:36 • Ticket [2049971fff]: 4 changes artifact: c4011a7c4f user: ingemarh
05:18 • Ticket [2049971fff]: 4 changes artifact: e62f9b2175 user: ferrieux
02:31 • Ticket [2049971fff]: 4 changes artifact: aa51584a87 user: kennykb
2008-08-20
00:14 • Ticket [2049971fff]: 4 changes artifact: c3e9a288f9 user: ferrieux
2008-08-19
14:29 • Open ticket [2049971fff]. artifact: 89061dc108 user: ingemarh
00:28 • Pending ticket [2049971fff]. artifact: 1e4a9b2f74 user: ferrieux
2008-08-15
06:33 • Ticket [2049971fff]: 4 changes artifact: 7873f6e88e user: ingemarh
2008-08-14
04:31 • Ticket [2049971fff]: 4 changes artifact: 4a074e289e user: ferrieux
01:18 • Ticket [2049971fff]: 2 changes artifact: b9162abba0 user: dgp
2008-08-13
17:42 • New ticket [2049971fff]. artifact: 1a139748dc user: ingemarh

clock command doesn't reflect Windows time zone changes

Open2049971fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 17 years ago
Descriptionplain2008-08-13 17:42:02
In a running tclsh the clock command does not recognize a time zone change. Threads created after the zone change will reflect the new time zone.

Ex:
% clock format [clock seconds]
Wed Aug 13 19:26:15 CEST 2008

Now change time zone and issue the above command again. The output is the same (except for a few added seconds). 

The command
% thread::create {puts [clock format [clock seconds]]}
will provide correct output time

Restart tclsh and run the command. The correct time is shown.
dgp Ticket [2049971fff]: 2 changes [History diff]2008-08-14 01:18:59
ferrieuxplain2008-08-14 04:31:15
Logged In: YES 
user_id=496139
Originator: NO

In unix, "changing the time zone" doesn't make sense globally. Instead, the timezone is a per-process thing associated with the value of the TZ environment variable. In addition to that, unix has no such thing as setting another process's environment from the outside. So it seems hard to define a portable interpretation of a system-wide change of "the" timezone.

Now are you saying that you're setting ::env(TZ) from the inside, and complaining about [clock]'s init code note being re-run on that occasion ?
ingemarhplain2008-08-15 06:33:07
Logged In: YES 
user_id=238112
Originator: YES

I'm awfully sorry, I hate incomplete error reports, and here I am filing such a beast myself ... :-(

I forgot to mention that this happens in Windows Vista. No TZ environment variables are set.
I also should mention that it works as expected in Tcl 8.4 (I guess this has to do with the major rewrite of the clock command in 8.5)
ferrieuxplain2008-08-19 00:28:36
Logged In: YES 
user_id=496139
Originator: NO

OK, in Windows you're right it is different in the absence of $::env(TZ).
Here another consideration comes to play: performance. See the comment in library/clock.tcl:

# GetSystemTimeZone --
#Stores the sustem time zone in the 'CachedSystemTimeZone'
#variable, since determining it may be an expensive process.

A simple workaround for you is then to unset ::tcl::clock::CachedSystemTimeZone before each of your calls to [clock format].
I think the trade-off is well chosen considering the rarity of timezone-tracking apps wrt simple apps who just want to display a time, and do it fast (because they are just logging timestamps for some quick event for example). For this reason I'm switching this to Pending. Feel free to kick it open again if you feel other argumentation is due.
ingemarhplain2008-08-19 14:29:29
Logged In: YES 
user_id=238112
Originator: YES

The suggested workaround is fine with me. I need it in app that checks that noone tampers with the system time.
Thanks a lot!
ferrieuxplain2008-08-20 00:14:37
Logged In: YES 
user_id=496139
Originator: NO

Kevin, do you agree to leave things the way they are, and close the entry, or would you like to re-evaluate the cost of calling GetTimeZoneInformation et al. ?

-Alex
kennykbplain2008-08-26 02:31:01
Logged In: YES 
user_id=99768
Originator: NO

Sorry about the delayed response, it's vacation time here...

One thing that would be possible, if the message pump is going, would be to intercept the WM_SETTINGCHANGE message, and use it to trigger clearing the cached time zone.  This should incur run-time cost only when the time zone changes (and at initialization).

This approach would require each interpreter that has 'clock.tcl' in place to have an async notification window to receive the message and process it.  This is a bit nasty, since we don't yet have anything in place that handles notifications at this sort of global level.  If you're interested in pursuing this approach, tclWinDde.c and tclWinSock.c both have code that creates a notification window (in the one case, to handle DDE messages, in the other, to trigger events on sockets).  

Since time zone change is such a rare event, I didn't think it was worth the effort to do this stuff at the time I implemented [clock].  If this becomes a recurring complaint, perhaps we should revisit the decision.
ferrieuxplain2008-08-26 05:18:08
Logged In: YES 
user_id=496139
Originator: NO

Yes, I had noticed the existence of that notification mechanism, but discarded it on the grounds that it needs an event loop or at least the Windows-only part GetMessage(), possibly in a separate, hidden thread... eeeek. (indeed [clock] should behave the same with or without [vwait] or Tk).

But maybe I'm missing something else, like a callback API which doesn't need its own thread, where we could call Tcl_AsyncMark.
Is it what you have in mind ?
ingemarhplain2008-08-26 05:36:06
Logged In: YES 
user_id=238112
Originator: YES

Indeed, time zone changes are usually very rare. But if someone (read: a teenager :-) ) has limited access to a computer based on some time rules, one way to get around the rules is to change time zone.
So for me it's enough with the workaround that Alex suggests.  Maybe it should be documented in the clock command that this caching exists.

/Ingemar
kennykb Ticket [2049971fff]: 1 change [History diff]2009-10-29 09:38:51
Log in (anonymous is fine) to add a comment.