summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerhard Weis <gerhard.weis@gmx.com>2012-01-26 18:13:50 +1000
committerGerhard Weis <gerhard.weis@gmx.com>2012-01-26 18:13:50 +1000
commitca5daae1f2a1bd320dfbcaf30e08284b71ea15f9 (patch)
tree0336f9822f6c019cad5375f838015b01fc65bf1c
parentff92360e320355651bbbc72dc79d3b0c306cd0f9 (diff)
downloadisodate-ca5daae1f2a1bd320dfbcaf30e08284b71ea15f9.tar.gz
tz_isoformat needs datetime object to determine daylight saving
never pass None into tzinfo.utcoffset (doesn't make sense; it's not deterministic)
-rw-r--r--src/isodate/isostrf.py6
-rw-r--r--src/isodate/isotzinfo.py9
2 files changed, 8 insertions, 7 deletions
diff --git a/src/isodate/isostrf.py b/src/isodate/isostrf.py
index e492a39..34785d4 100644
--- a/src/isodate/isostrf.py
+++ b/src/isodate/isostrf.py
@@ -97,9 +97,9 @@ STRF_DT_MAP = {'%d': lambda tdt, yds: '%02d' % tdt.day,
(('%%0%dd' % yds) % tdt.year),
'%C': lambda tdt, yds: (((yds != 4) and '+') or '') +\
(('%%0%dd' % (yds - 2)) % (tdt.year / 100)),
- '%h': lambda tdt, yds: tz_isoformat(tdt.tzinfo, '%h'),
- '%Z': lambda tdt, yds: tz_isoformat(tdt.tzinfo, '%Z'),
- '%z': lambda tdt, yds: tz_isoformat(tdt.tzinfo, '%z'),
+ '%h': lambda tdt, yds: tz_isoformat(tdt, '%h'),
+ '%Z': lambda tdt, yds: tz_isoformat(tdt, '%Z'),
+ '%z': lambda tdt, yds: tz_isoformat(tdt, '%z'),
'%%': lambda tdt, yds: '%'}
STRF_D_MAP = {'%d': lambda tdt, yds: '%02d' % tdt.days,
diff --git a/src/isodate/isotzinfo.py b/src/isodate/isotzinfo.py
index 79797fa..df01384 100644
--- a/src/isodate/isotzinfo.py
+++ b/src/isodate/isotzinfo.py
@@ -74,7 +74,7 @@ def parse_tzinfo(tzstring):
int(groups['tzmin'] or 0))
raise ISO8601Error('%s not a valid time zone info' % tzstring)
-def tz_isoformat(tzinfo, format='%Z'):
+def tz_isoformat(dt, format='%Z'):
'''
return time zone offset ISO 8601 formatted.
The various ISO formats can be chosen with the format parameter.
@@ -87,11 +87,12 @@ def tz_isoformat(tzinfo, format='%Z'):
%z ... +-HHMM
%Z ... +-HH:MM
'''
- if (tzinfo is None) or (tzinfo.utcoffset(None) is None):
+ tzinfo = dt.tzinfo
+ if (tzinfo is None) or (tzinfo.utcoffset(dt) is None):
return ''
- if tzinfo.utcoffset(None) == ZERO and tzinfo.dst(None) == ZERO:
+ if tzinfo.utcoffset(dt) == ZERO and tzinfo.dst(dt) == ZERO:
return 'Z'
- tdelta = tzinfo.utcoffset(None)
+ tdelta = tzinfo.utcoffset(dt)
seconds = tdelta.days * 24 * 60 * 60 + tdelta.seconds
sign = ((seconds < 0) and '-') or '+'
seconds = abs(seconds)