Fix duration calculation

Fix the duration calculation to clamp to the original range
of the query from the user, not the modified values with
the search_offset included.

Also includes some whitespace changes for the new 1.3.3 pep8.

Change-Id: If6b48f68709ace4d88d30ee1ecba6a5913b6175a
Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>