SF patch #706707, time.tzset standards compliance update by Stuart Bishop
Update configure and test to use proper timezone specifications
This commit is contained in:
parent
bae5c965e8
commit
7f2588c073
|
@ -62,73 +62,55 @@ class TimeTestCase(unittest.TestCase):
|
||||||
# hemisphere.
|
# hemisphere.
|
||||||
xmas2002 = 1040774400.0
|
xmas2002 = 1040774400.0
|
||||||
|
|
||||||
|
# These formats are correct for 2002, and possibly future years
|
||||||
|
# This format is the 'standard' as documented at:
|
||||||
|
# http://www.opengroup.org/onlinepubs/007904975/basedefs/xbd_chap08.html
|
||||||
|
# They are also documented in the tzset(3) man page on most Unix
|
||||||
|
# systems.
|
||||||
|
eastern = 'EST+05EDT,M4.1.0,M10.5.0'
|
||||||
|
victoria = 'AEST-10AEDT-11,M10.5.0,M3.5.0'
|
||||||
|
utc='UTC+0'
|
||||||
|
|
||||||
org_TZ = environ.get('TZ',None)
|
org_TZ = environ.get('TZ',None)
|
||||||
try:
|
try:
|
||||||
|
|
||||||
# Make sure we can switch to UTC time and results are correct
|
# Make sure we can switch to UTC time and results are correct
|
||||||
# Note that unknown timezones default to UTC.
|
# Note that unknown timezones default to UTC.
|
||||||
for tz in ('UTC','GMT','Luna/Tycho'):
|
# Note that altzone is undefined in UTC, as there is no DST
|
||||||
environ['TZ'] = 'US/Eastern'
|
environ['TZ'] = eastern
|
||||||
time.tzset()
|
time.tzset()
|
||||||
environ['TZ'] = tz
|
environ['TZ'] = utc
|
||||||
time.tzset()
|
time.tzset()
|
||||||
self.failUnlessEqual(
|
self.failUnlessEqual(
|
||||||
time.gmtime(xmas2002),time.localtime(xmas2002)
|
time.gmtime(xmas2002), time.localtime(xmas2002)
|
||||||
)
|
)
|
||||||
self.failUnlessEqual(time.timezone,time.altzone)
|
self.failUnlessEqual(time.daylight, 0)
|
||||||
self.failUnlessEqual(time.daylight,0)
|
self.failUnlessEqual(time.timezone, 0)
|
||||||
self.failUnlessEqual(time.timezone,0)
|
self.failUnlessEqual(time.localtime(xmas2002).tm_isdst, 0)
|
||||||
self.failUnlessEqual(time.altzone,0)
|
|
||||||
self.failUnlessEqual(time.localtime(xmas2002).tm_isdst,0)
|
|
||||||
|
|
||||||
# Make sure we can switch to US/Eastern
|
# Make sure we can switch to US/Eastern
|
||||||
environ['TZ'] = 'US/Eastern'
|
environ['TZ'] = eastern
|
||||||
time.tzset()
|
time.tzset()
|
||||||
self.failIfEqual(time.gmtime(xmas2002),time.localtime(xmas2002))
|
self.failIfEqual(time.gmtime(xmas2002), time.localtime(xmas2002))
|
||||||
self.failUnlessEqual(time.tzname,('EST','EDT'))
|
self.failUnlessEqual(time.tzname, ('EST', 'EDT'))
|
||||||
self.failUnlessEqual(len(time.tzname),2)
|
self.failUnlessEqual(len(time.tzname), 2)
|
||||||
self.failUnlessEqual(time.daylight,1)
|
self.failUnlessEqual(time.daylight, 1)
|
||||||
self.failUnlessEqual(time.timezone,18000)
|
self.failUnlessEqual(time.timezone, 18000)
|
||||||
self.failUnlessEqual(time.altzone,14400)
|
self.failUnlessEqual(time.altzone, 14400)
|
||||||
self.failUnlessEqual(time.localtime(xmas2002).tm_isdst,0)
|
self.failUnlessEqual(time.localtime(xmas2002).tm_isdst, 0)
|
||||||
self.failUnlessEqual(len(time.tzname),2)
|
self.failUnlessEqual(len(time.tzname), 2)
|
||||||
|
|
||||||
# Now go to the southern hemisphere. We want somewhere all OS's
|
# Now go to the southern hemisphere.
|
||||||
# know about that has DST.
|
environ['TZ'] = victoria
|
||||||
environ['TZ'] = 'Australia/Melbourne'
|
|
||||||
time.tzset()
|
time.tzset()
|
||||||
self.failIfEqual(time.gmtime(xmas2002),time.localtime(xmas2002))
|
self.failIfEqual(time.gmtime(xmas2002), time.localtime(xmas2002))
|
||||||
self.failUnless(time.tzname[0] in ('EST','AEST'))
|
self.failUnless(time.tzname[0] == 'AEST', str(time.tzname[0]))
|
||||||
self.failUnless(time.tzname[1] in ('EST','EDT','AEDT'))
|
self.failUnless(time.tzname[1] == 'AEDT', str(time.tzname[1]))
|
||||||
self.failUnlessEqual(len(time.tzname),2)
|
self.failUnlessEqual(len(time.tzname), 2)
|
||||||
self.failUnlessEqual(time.daylight,1)
|
self.failUnlessEqual(time.daylight, 1)
|
||||||
self.failUnlessEqual(time.timezone,-36000)
|
self.failUnlessEqual(time.timezone, -36000)
|
||||||
self.failUnlessEqual(time.altzone,-39600)
|
self.failUnlessEqual(time.altzone, -39600)
|
||||||
self.failUnlessEqual(time.localtime(xmas2002).tm_isdst,1)
|
self.failUnlessEqual(time.localtime(xmas2002).tm_isdst, 1)
|
||||||
|
|
||||||
# Get some times from a timezone that isn't wallclock timezone
|
|
||||||
del environ['TZ']
|
|
||||||
time.tzset()
|
|
||||||
if time.timezone == 0:
|
|
||||||
environ['TZ'] = 'US/Eastern'
|
|
||||||
else:
|
|
||||||
environ['TZ'] = 'UTC'
|
|
||||||
time.tzset()
|
|
||||||
nonlocal = time.localtime(xmas2002)
|
|
||||||
|
|
||||||
# Then the same time in wallclock timezone
|
|
||||||
del environ['TZ']
|
|
||||||
time.tzset()
|
|
||||||
local = time.localtime(xmas2002)
|
|
||||||
|
|
||||||
# And make sure they arn't the same
|
|
||||||
self.failIfEqual(local,nonlocal)
|
|
||||||
|
|
||||||
# Do some basic sanity checking after wallclock time set
|
|
||||||
self.failUnlessEqual(len(time.tzname),2)
|
|
||||||
time.daylight
|
|
||||||
time.timezone
|
|
||||||
time.altzone
|
|
||||||
finally:
|
finally:
|
||||||
# Repair TZ environment variable in case any other tests
|
# Repair TZ environment variable in case any other tests
|
||||||
# rely on it.
|
# rely on it.
|
||||||
|
@ -136,6 +118,7 @@ class TimeTestCase(unittest.TestCase):
|
||||||
environ['TZ'] = org_TZ
|
environ['TZ'] = org_TZ
|
||||||
elif environ.has_key('TZ'):
|
elif environ.has_key('TZ'):
|
||||||
del environ['TZ']
|
del environ['TZ']
|
||||||
|
time.tzset()
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# From configure.in Revision: 1.398 .
|
# From configure.in Revision: 1.400 .
|
||||||
# Guess values for system-dependent variables and create Makefiles.
|
# Guess values for system-dependent variables and create Makefiles.
|
||||||
# Generated by GNU Autoconf 2.53 for python 2.3.
|
# Generated by GNU Autoconf 2.53 for python 2.3.
|
||||||
#
|
#
|
||||||
|
@ -908,7 +908,7 @@ esac
|
||||||
# Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be
|
# Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be
|
||||||
# absolute.
|
# absolute.
|
||||||
ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd`
|
ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd`
|
||||||
ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd`
|
ac_abs_top_builddir=`cd "$ac_dir" && cd $ac_top_builddir && pwd`
|
||||||
ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd`
|
ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd`
|
||||||
ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd`
|
ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd`
|
||||||
|
|
||||||
|
@ -16741,10 +16741,10 @@ int main()
|
||||||
int eastern_hour;
|
int eastern_hour;
|
||||||
time_t now;
|
time_t now;
|
||||||
now = time((time_t*)NULL);
|
now = time((time_t*)NULL);
|
||||||
putenv("TZ=GMT");
|
putenv("TZ=UTC+0");
|
||||||
tzset();
|
tzset();
|
||||||
gmt_hour = localtime(&now)->tm_hour;
|
gmt_hour = localtime(&now)->tm_hour;
|
||||||
putenv("TZ=US/Eastern");
|
putenv("TZ=EST+5EDT,M4.1.0,M10.5.0");
|
||||||
tzset();
|
tzset();
|
||||||
eastern_hour = localtime(&now)->tm_hour;
|
eastern_hour = localtime(&now)->tm_hour;
|
||||||
if (eastern_hour == gmt_hour)
|
if (eastern_hour == gmt_hour)
|
||||||
|
@ -17828,7 +17828,7 @@ esac
|
||||||
# Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be
|
# Don't blindly perform a `cd "$ac_dir"/$ac_foo && pwd` since $ac_foo can be
|
||||||
# absolute.
|
# absolute.
|
||||||
ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd`
|
ac_abs_builddir=`cd "$ac_dir" && cd $ac_builddir && pwd`
|
||||||
ac_abs_top_builddir=`cd "$ac_dir" && cd ${ac_top_builddir}. && pwd`
|
ac_abs_top_builddir=`cd "$ac_dir" && cd $ac_top_builddir && pwd`
|
||||||
ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd`
|
ac_abs_srcdir=`cd "$ac_dir" && cd $ac_srcdir && pwd`
|
||||||
ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd`
|
ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd`
|
||||||
|
|
||||||
|
|
|
@ -2552,10 +2552,10 @@ int main()
|
||||||
int eastern_hour;
|
int eastern_hour;
|
||||||
time_t now;
|
time_t now;
|
||||||
now = time((time_t*)NULL);
|
now = time((time_t*)NULL);
|
||||||
putenv("TZ=GMT");
|
putenv("TZ=UTC+0");
|
||||||
tzset();
|
tzset();
|
||||||
gmt_hour = localtime(&now)->tm_hour;
|
gmt_hour = localtime(&now)->tm_hour;
|
||||||
putenv("TZ=US/Eastern");
|
putenv("TZ=EST+5EDT,M4.1.0,M10.5.0");
|
||||||
tzset();
|
tzset();
|
||||||
eastern_hour = localtime(&now)->tm_hour;
|
eastern_hour = localtime(&now)->tm_hour;
|
||||||
if (eastern_hour == gmt_hour)
|
if (eastern_hour == gmt_hour)
|
||||||
|
|
Loading…
Reference in New Issue