Skip to content

Commit 38fb814

Browse files
committed
dates.py: fix num2jul, jul2num; fixes bug 2963391; thanks to G. Lichtenberg
svn path=/trunk/matplotlib/; revision=8182
1 parent d8ef07b commit 38fb814

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/matplotlib/dates.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
Matplotlib provides sophisticated date plotting capabilities, standing
44
on the shoulders of python :mod:`datetime`, the add-on modules
55
:mod:`pytz` and :mod:`dateutils`. :class:`datetime` objects are
6-
converted to floating point numbers which represent the number of days
7-
since 0001-01-01 UTC. The helper functions :func:`date2num`,
6+
converted to floating point numbers which represent time in days
7+
since 0001-01-01 UTC, plus 1. For example, 0001-01-01, 06:00 is
8+
1.25, not 0.25. The helper functions :func:`date2num`,
89
:func:`num2date` and :func:`drange` are used to facilitate easy
910
conversion to and from :mod:`datetime` and numeric ranges.
1011
@@ -225,7 +226,7 @@ def date2num(d):
225226
*d* is either a :class:`datetime` instance or a sequence of datetimes.
226227
227228
Return value is a floating point number (or sequence of floats)
228-
which gives number of days (fraction part represents hours,
229+
which gives one plus the number of days (fraction part represents hours,
229230
minutes, seconds) since 0001-01-01 00:00:00 UTC.
230231
"""
231232
if not cbook.iterable(d): return _to_ordinalf(d)
@@ -235,17 +236,18 @@ def date2num(d):
235236
def julian2num(j):
236237
'Convert a Julian date (or sequence) to a matplotlib date (or sequence).'
237238
if cbook.iterable(j): j = np.asarray(j)
238-
return j + 1721425.5
239+
return j - 1721424.5
239240

240241
def num2julian(n):
241242
'Convert a matplotlib date (or sequence) to a Julian date (or sequence).'
242243
if cbook.iterable(n): n = np.asarray(n)
243-
return n - 1721425.5
244+
return n + 1721424.5
244245

245246
def num2date(x, tz=None):
246247
"""
247-
*x* is a float value which gives number of days (fraction part
248-
represents hours, minutes, seconds) since 0001-01-01 00:00:00 UTC.
248+
*x* is a float value which gives one plus the number of days
249+
(fraction part represents hours, minutes, seconds) since
250+
0001-01-01 00:00:00 UTC.
249251
250252
Return value is a :class:`datetime` instance in timezone *tz* (default to
251253
rcparams TZ value).

0 commit comments

Comments
 (0)