Convert a set of dates into a compact list of globs. For example:

>>> import dateglob; from datetime import date, timedelta
>>> # build list of dates from 2009-12-31 thru 2011-02-01
>>> dates = [date(2009, 12, 31) + timedelta(i) for i in xrange(1+365+31+1)]
>>> dateglob.strftime(dates, '%Y-%m-%d')
['2009-12-31', '2010-*-*', '2011-01-*', '2011-02-01']

The original use case for this library was to generate compact command lines for command that take daily log files as input, for example:

>>> args += dateglob.strftime(dates, '/logs/foo/%Y/%m/%d/*.gz')
dateglob.strftime(dates, format)

Format a sequence of dates, using * when possible.

For example, if dates contains all days in June 2011, and format is '%Y/%m/%d', we return ['2011/06/*']

Divisions smaller than a day (e.g. %H) and time zone fields (e.g. %Z) are always converted to *.

Currently, we only do something special with full months and years (we don’t glob weeks).


a list of strings corresponding to strftime-formatted dates, using * wherever possible. These will be distinct (no duplicates) and in alphabetical order.

This Page