Exploring Dateutil’s Relativedelta

The first thing that I want to use dateutil for is calculating seconds based on times. Dateutil doesn’t appear to be set up for this so I’m going to use a hack to see if it gets close enough.

relativedelta([dt1, dt2, years, months, ...]) The relativedelta type is based on the specification of the excelent work done by M.-A.

Minutes

The relativetimedelta is a time-delta object, so you can’t get seconds directly, but you can get it by adding and subtracting the same time.

time = datetime.datetime.now()
minutes = 5
expected = minutes * 60
delta = relativedelta(minutes=minutes)
actual = (time + delta - time).seconds
print expected == actual
True