Author: Richard Plangger <[email protected]>
Branch: py3.5-time
Changeset: r89280:dc076a581a0e
Date: 2016-12-30 17:15 +0100
http://bitbucket.org/pypy/pypy/changeset/dc076a581a0e/
Log: make struct_time carry the fields tm_gmtoff/tm_zone, currently those
attributes are not available even though the system provides them
diff --git a/pypy/module/time/app_time.py b/pypy/module/time/app_time.py
--- a/pypy/module/time/app_time.py
+++ b/pypy/module/time/app_time.py
@@ -3,6 +3,7 @@
from _structseq import structseqtype, structseqfield
from types import SimpleNamespace
import time
+
class struct_time(metaclass=structseqtype):
__module__ = 'time'
name = 'time.struct_time'
@@ -16,6 +17,8 @@
tm_wday = structseqfield(6)
tm_yday = structseqfield(7)
tm_isdst = structseqfield(8)
+ tm_gmtoff = structseqfield(9)
+ tm_zone = structseqfield(10)
def strptime(string, format="%a %b %d %H:%M:%S %Y"):
"""strptime(string, format) -> struct_time
diff --git a/pypy/module/time/interp_time.py b/pypy/module/time/interp_time.py
--- a/pypy/module/time/interp_time.py
+++ b/pypy/module/time/interp_time.py
@@ -164,6 +164,8 @@
CLOCKS_PER_SEC = platform.ConstantInteger("CLOCKS_PER_SEC")
has_gettimeofday = platform.Has('gettimeofday')
+HAS_TM_ZONE = False
+
if _POSIX:
calling_conv = 'c'
CConfig.timeval = platform.Struct("struct timeval",
@@ -180,6 +182,9 @@
("tm_mon", rffi.INT), ("tm_year", rffi.INT), ("tm_wday", rffi.INT),
("tm_yday", rffi.INT), ("tm_isdst", rffi.INT), ("tm_gmtoff",
rffi.LONG),
("tm_zone", rffi.CCHARP)])
+
+ HAS_TM_ZONE = True
+
elif _WIN:
calling_conv = 'win'
CConfig.tm = platform.Struct("struct tm", [("tm_sec", rffi.INT),
@@ -539,7 +544,11 @@
w_struct_time = _get_module_object(space, 'struct_time')
w_time_tuple = space.newtuple(time_tuple)
- return space.call_function(w_struct_time, w_time_tuple)
+ w_obj = space.call_function(w_struct_time, w_time_tuple)
+ if HAS_TM_ZONE:
+ space.setattr(w_obj, space.wrap("tm_gmoff"),
space.wrap(rffi.getintfield(t, 'c_tm_gmtoff')))
+ space.setattr(w_obj, space.wrap("tm_zone"),
space.wrap(rffi.getintfield(t, 'c_tm_zone')))
+ return w_obj
def _gettmarg(space, w_tup, allowNone=True):
if space.is_none(w_tup):
diff --git a/pypy/module/time/test/test_time.py
b/pypy/module/time/test/test_time.py
--- a/pypy/module/time/test/test_time.py
+++ b/pypy/module/time/test/test_time.py
@@ -254,6 +254,22 @@
del os.environ['TZ']
time.tzset()
+ def test_localtime_timezone(self):
+ import os, time
+ org_TZ = os.environ.get('TZ', None)
+ try:
+ os.environ['TZ'] = 'Europe/Kiev'
+ time.tzset()
+ localtm = time.localtime(0)
+ assert localtm.tm_zone == "MSK"
+ assert localtm.tm_gmtoff == 10800
+ finally:
+ if org_TZ is not None:
+ os.environ['TZ'] = org_TZ
+ elif 'TZ' in os.environ:
+ del os.environ['TZ']
+ time.tzset()
+
def test_strftime(self):
import time
import os, sys
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit