Skip to content

Commit 90600d8

Browse files
committed
dates: improve documentation related to use of Gregorian calendar
svn path=/trunk/matplotlib/; revision=8396
1 parent 6466bad commit 90600d8

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

lib/matplotlib/dates.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@
99
:func:`num2date` and :func:`drange` are used to facilitate easy
1010
conversion to and from :mod:`datetime` and numeric ranges.
1111
12+
.. note::
13+
Like Python's datetime, mpl uses the Gregorian calendar for
14+
all conversions between dates and floating point numbers.
15+
This practice is not universal, and calendar differences can
16+
cause confusing differences between what Python and mpl
17+
give as the number of days since 0001-01-01 and what other
18+
software and databases yield. For example, the
19+
`US Naval Observatory <http://www.usno.navy.mil/USNO/astronomical-applications/data-services/jul-date>`_
20+
uses a calendar that switches from Julian to Gregorian in
21+
October, 1582. Hence, using their calculator, the number of
22+
days between 0001-01-01 and 2006-04-01 is 732403, whereas using
23+
the Gregorian calendar via the datetime module we find::
24+
25+
In [31]:date(2006,4,1).toordinal() - date(1,1,1).toordinal()
26+
Out[31]:732401
27+
28+
1229
A wide range of specific and general purpose date tick locators and
1330
formatters are provided in this module. See
1431
:mod:`matplotlib.ticker` for general information on tick locators
@@ -233,8 +250,11 @@ def date2num(d):
233250
*d* is either a :class:`datetime` instance or a sequence of datetimes.
234251
235252
Return value is a floating point number (or sequence of floats)
236-
which gives one plus the number of days (fraction part represents hours,
237-
minutes, seconds) since 0001-01-01 00:00:00 UTC.
253+
which gives the number of days (fraction part represents hours,
254+
minutes, seconds) since 0001-01-01 00:00:00 UTC, *plus* *one*.
255+
The addition of one here is a historical artifact. Also, note
256+
that the Gregorian calendar is assumed; this is not universal
257+
practice. For details, see the module docstring.
238258
"""
239259
if not cbook.iterable(d): return _to_ordinalf(d)
240260
else: return np.asarray([_to_ordinalf(val) for val in d])
@@ -252,9 +272,12 @@ def num2julian(n):
252272

253273
def num2date(x, tz=None):
254274
"""
255-
*x* is a float value which gives one plus the number of days
275+
*x* is a float value which gives the number of days
256276
(fraction part represents hours, minutes, seconds) since
257-
0001-01-01 00:00:00 UTC.
277+
0001-01-01 00:00:00 UTC *plus* *one*.
278+
The addition of one here is a historical artifact. Also, note
279+
that the Gregorian calendar is assumed; this is not universal
280+
practice. For details, see the module docstring.
258281
259282
Return value is a :class:`datetime` instance in timezone *tz* (default to
260283
rcparams TZ value).

0 commit comments

Comments
 (0)