Revision: 4610
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4610&view=rev
Author: jswhit
Date: 2007-12-05 05:00:41 -0800 (Wed, 05 Dec 2007)
Log Message:
-----------
include time-zone offset in num2date and date2num.
Modified Paths:
--------------
trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py
trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/netcdftime.py
Modified: trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py
===================================================================
--- trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py
2007-12-05 08:53:31 UTC (rev 4609)
+++ trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/basemap.py
2007-12-05 13:00:41 UTC (rev 4610)
@@ -2866,7 +2866,9 @@
"""
Return datetime objects given numeric time values. The units
of the numeric time values are described by the units argument
- and the calendar keyword. The time zone is assumed to be UTC.
+ and the calendar keyword. The datetime objects represent
+ UTC with no time-zone offset, even if the specified
+ units contain a time-zone offset.
Like the matplotlib num2date function, except that it allows
for different units and calendars. Behaves the same if
@@ -2907,7 +2909,10 @@
"""
Return numeric time values given datetime objects. The units
of the numeric time values are described by the units argument
- and the calendar keyword. The time zone is assumed to UTC.
+ and the calendar keyword. The datetime objects must
+ be in UTC with no time-zone offset. If there is a
+ time-zone offset in units, it will be applied to the
+ returned numeric values.
Like the matplotlib date2num function, except that it allows
for different units and calendars. Behaves the same if
Modified: trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/netcdftime.py
===================================================================
--- trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/netcdftime.py
2007-12-05 08:53:31 UTC (rev 4609)
+++ trunk/toolkits/basemap/lib/matplotlib/toolkits/basemap/netcdftime.py
2007-12-05 13:00:41 UTC (rev 4610)
@@ -446,9 +446,7 @@
# parse the date string.
n = timestr.find('since')+6
year,month,day,hour,minute,second,utc_offset = _parse_date(timestr[n:])
- if utc_offset:
- raise ValueError("time zone offset not allowed")
- return units, datetime(year, month, day, hour, minute, second)
+ return units, utc_offset, datetime(year, month, day, hour, minute, second)
class utime:
"""
@@ -589,7 +587,8 @@
self.calendar = calendar
else:
raise ValueError, "calendar must be one of %s, got '%s'" %
(str(_calendars),calendar)
- units, self.origin = _dateparse(unit_string)
+ units, tzoffset, self.origin = _dateparse(unit_string)
+ self.tzoffset = tzoffset # time zone offset in minutes
self.units = units
self.unit_string = unit_string
if self.calendar in ['noleap','365_day'] and self.origin.month == 2
and self.origin.day == 29:
@@ -610,6 +609,10 @@
Returns C{time_value} in units described by L{unit_string}, using
the specified L{calendar}, given a 'datetime-like' object.
+The datetime object must represent UTC with no time-zone offset.
+If there is a time-zone offset implied by L{unit_string}, it will
+be applied to the returned numeric values.
+
Resolution is 1 second.
If C{calendar = 'standard'} or C{'gregorian'} (indicating
@@ -654,12 +657,15 @@
jdelta = [_360DayFromDate(d)-self._jd0 for d in date.flat]
if not isscalar:
jdelta = numpy.array(jdelta)
+ # convert to desired units, add time zone offset.
if self.units in ['second','seconds']:
- jdelta = jdelta*86400.
+ jdelta = jdelta*86400. + self.tzoffset*60.
elif self.units in ['minute','minutes']:
- jdelta = jdelta*1440.
- elif self.units in ['hours','hours']:
- jdelta = jdelta*24.
+ jdelta = jdelta*1440. + self.tzoffset
+ elif self.units in ['hour','hours']:
+ jdelta = jdelta*24. + self.tzoffset/60.
+ elif self.units in ['day','days']:
+ jdelta = jdelta + self.tzoffset/1440.
if isscalar:
return jdelta
else:
@@ -670,6 +676,9 @@
Return a 'datetime-like' object given a C{time_value} in units
described by L{unit_string}, using L{calendar}.
+dates are in UTC with no offset, even if L{unit_string} contains
+a time zone offset from UTC.
+
Resolution is 1 second.
Works for scalars, sequences and numpy arrays.
@@ -692,14 +701,15 @@
if not isscalar:
time_value = numpy.array(time_value)
shape = time_value.shape
+ # convert to desired units, remove time zone offset.
if self.units in ['second','seconds']:
- jdelta = time_value/86400.
+ jdelta = time_value/86400. - self.tzoffset*60
elif self.units in ['minute','minutes']:
- jdelta = time_value/1440.
+ jdelta = time_value/1440. - self.tzoffset
elif self.units in ['hours','hours']:
- jdelta = time_value/24.
+ jdelta = time_value/24. - self.tzoffset/60.
elif self.units in ['day','days']:
- jdelta = time_value
+ jdelta = time_value - self.tzoffset/1440.
jd = self._jd0 + jdelta
if self.calendar in
['julian','standard','gregorian','proleptic_gregorian']:
if not isscalar:
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins