Skip to content

Commit

Permalink
Merge pull request #2481 from mdboom/datestr2num-fix
Browse files Browse the repository at this point in the history
datestr2num of year and month fails on 29th, 30th, and 31st of month
  • Loading branch information
pelson committed Jan 9, 2014
2 parents 19b3598 + 66ec634 commit cac742e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,24 @@ def __call__(self, s):
return date2num(datetime.datetime(*time.strptime(s, self.fmt)[:6]))


def datestr2num(d):
def datestr2num(d, default=None):
"""
Convert a date string to a datenum using
:func:`dateutil.parser.parse`. *d* can be a single string or a
sequence of strings.
:func:`dateutil.parser.parse`.
Parameters
----------
d : string or sequence of strings
The dates to convert.
default : datetime instance
The default date to use when fields are missing in `d`.
"""
if cbook.is_string_like(d):
dt = dateutil.parser.parse(d)
dt = dateutil.parser.parse(d, default=default)
return date2num(dt)
else:
return date2num([dateutil.parser.parse(s) for s in d])
return date2num([dateutil.parser.parse(s, default=default) for s in d])


def date2num(d):
Expand Down

0 comments on commit cac742e

Please sign in to comment.