luigi.date_interval
luigi.date_interval provides convenient classes for date algebra.
Everything uses ISO 8601 notation, i.e. YYYY-MM-DD for dates, etc.
There is a corresponding luigi.parameter.DateIntervalParameter that you can use to parse date intervals.
Example:
class MyTask(luigi.Task):
date_interval = luigi.DateIntervalParameter()
Now, you can launch this from the command line using
--date-interval 2014-05-10 or
--date-interval 2014-W26 (using week notation) or
--date-interval 2014 (for a year) and some other notations.
Classes
|
Custom date interval (does not implement prev and next methods) |
|
Most simple |
|
The |
|
|
|
ISO 8601 week. |
|
- class luigi.date_interval.DateInterval(date_a, date_b)[source]
The
DateIntervalis the base class with subclassesDate,Week,Month,Year, andCustom. Note that theDateIntervalis abstract and should not be used directly: useCustomfor arbitrary date intervals. The base class features a couple of convenience methods, such asnext()which returns the next consecutive date interval.Example:
x = luigi.date_interval.Week(2013, 52) print x.prev()
This will print
2014-W01.All instances of
DateIntervalhave attributesdate_aanddate_bset. This represents the half open range of the date interval. For instance, a May 2014 is represented asdate_a = 2014-05-01,date_b = 2014-06-01.
- class luigi.date_interval.Date(y, m, d)[source]
Most simple
DateIntervalwheredate_b == date_a + datetime.timedelta(1).
- class luigi.date_interval.Week(y, w)[source]
ISO 8601 week. Note that it has some counterintuitive behavior around new year. For instance Monday 29 December 2008 is week 2009-W01, and Sunday 3 January 2010 is week 2009-W53 This example was taken from from http://en.wikipedia.org/wiki/ISO_8601#Week_dates
Python datetime does not have a method to convert from ISO weeks, so the constructor uses some stupid brute force
- class luigi.date_interval.Month(y, m)[source]
- class luigi.date_interval.Year(y)[source]
- class luigi.date_interval.Custom(date_a, date_b)[source]
Custom date interval (does not implement prev and next methods)
Actually the ISO 8601 specifies <start>/<end> as the time interval format Not sure if this goes for date intervals as well. In any case slashes will most likely cause problems with paths etc.