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

SourceForge.net noreply@sourceforge.net
Fri, 07 Mar 2003 06:25:06 -0800


Patches item #675422, was opened at 2003-01-27 08: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: None
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: Guido van Rossum (gvanrossum)
Date: 2003-03-07 09: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-21 16:49

Message:
Logged In: YES 
user_id=6380

Sorry, not a chance.

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

Comment By: Stuart Bishop (zenzen)
Date: 2003-02-21 16: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 07: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-20 23: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