[Patches] [ python-Patches-675422 ] Add tzset method to time module

SourceForge.net noreply@sourceforge.net
Wed, 19 Mar 2003 21:06:54 -0800


Patches item #675422, was opened at 2003-01-28 00:42
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=675422&group_id=5470

Category: Library (Lib)
Group: Python 2.3
Status: Open
Resolution: Accepted
Priority: 5
Submitted By: Stuart Bishop (zenzen)
Assigned to: Guido van Rossum (gvanrossum)
Summary: Add tzset method to time module

Initial Comment:
Adds access to the tzset method, allowing you to change your local timezone as required. In addition to invoking the tzset system
call, the code also updates the timezone attributes (time.timezone etc). This lets you do timezone conversions amongst other things.

Also includes changes to configure.in to only build new code if the tzset method correctly switches timezones on your platform. This 
should be for all modern Unixes, and possibly other platforms.

Also includes tests in test_time.py

Docs would be along the lines of:

tzset() -- 
Initialize, or reinitialize, the local timezone to the value stored in os.environ['TZ']. The TZ environment variable should be specified in
standard Uniz timezone format as documented in the tzset man page
(eg. 'US/Eastern', 'Europe/Amsterdam'). Unknown timezones will silently fall back to UTC. If the TZ environment variable is not set, the local timezone is set to the systems best guess of wallclock time.
Changing the TZ environment variable without calling tzset *may* change the local timezone used by methods such as localtime, but this behaviour should not be relied on.

eg::

>>> now = time.time()
>>> os.environ['TZ'] = 'Europe/Amsterdam'
>>> time.tzset()
>>> time.ctime(now)
'Mon Jan 27 14:35:17 2003'
>>> time.tzname  
('CET', 'CEST')
>>> os.environ['TZ'] = 'US/Eastern'
>>> time.tzset()
>>> time.ctime(now)
'Mon Jan 27 08:35:17 2003'
>>> time.tzname
('EST', 'EDT')

----------------------------------------------------------------------

>Comment By: Stuart Bishop (zenzen)
Date: 2003-03-20 16:06

Message:
Logged In: YES 
user_id=46639

An update to this patch is now available:
http://www.python.org/sf/706707

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2003-03-20 15:18

Message:
Logged In: YES 
user_id=33168

test_time is now failing on Solaris 8.  altzone is -3600,
but should be 0.  Also, is there a reason to compare
timezone to altzone, but then check that each is 0 (line
78)?  Can you provide any suggestions for where to look for
the problem?

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2003-03-15 09:03

Message:
Logged In: YES 
user_id=6380

OK, checked in with that line removed.

Thanks!

----------------------------------------------------------------------

Comment By: Stuart Bishop (zenzen)
Date: 2003-03-08 15:42

Message:
Logged In: YES 
user_id=46639

Leave it commented out or remove that line. It is testing
unimportant behaviour that looks more platform dependant
than I suspected (and now I look at it again, what tzname
should be set to if the timezone is unknow is unspecified by
the tzset(3) docs). The important behaviour is that:

a) the system silently falls back to UTC if the timezone is
unknown, and this is tested elsewhere 

b) calling tzset resets tzname, which is also tested elsewhere.



----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2003-03-08 01:25

Message:
Logged In: YES 
user_id=6380

zenzen: when I run the test suite on my Red Hat Linux 7.3
box, I get one failure: the test line
  self.failUnless(time.tzname[0] in ('UTC','GMT'))
fails when the timezone is set to 'Luna/Tycho', because
tzname is in fact set to  ('Luna/Tych', 'Luna/Tych').

If I comment out that one line the tzset test suite passes.

What should I do?

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2003-02-22 08:49

Message:
Logged In: YES 
user_id=6380

Sorry, not a chance.

----------------------------------------------------------------------

Comment By: Stuart Bishop (zenzen)
Date: 2003-02-22 08:45

Message:
Logged In: YES 
user_id=46639

It is a patch to 2.3, but I'd though I'd try and sneak this
new feature past people into 2.2.3 as I want to be able to
use it in Zope 2 :-)

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2003-02-21 23:56

Message:
Logged In: YES 
user_id=6380

Uh? This is a new feature, so doesn't apply to 2.2.3.

Maybe you meant 2.3?

----------------------------------------------------------------------

Comment By: Stuart Bishop (zenzen)
Date: 2003-02-21 15:29

Message:
Logged In: YES 
user_id=46639

Assigning to Guido for consideration of being added to
2.2.3, and since he through this patch was a good idea in
the first place :-)

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=675422&group_id=5470