diff options
author | Alec Nikolas Reiter <alecreiter@gmail.com> | 2017-07-29 15:33:32 -0400 |
---|---|---|
committer | Alec Nikolas Reiter <alecreiter@gmail.com> | 2017-08-05 08:52:56 -0400 |
commit | 00ff58c1f9d1d53c5b52fdbfffe9c901a5ecedde (patch) | |
tree | e1a05b0f86e375733d9b0d6b745f9535e5a9353f /dateutil/utils.py | |
parent | 94f1639b513280ca73144bc494d826616be22768 (diff) | |
download | dateutil-00ff58c1f9d1d53c5b52fdbfffe9c901a5ecedde.tar.gz |
Implement utils.within_delta
Closes #432
Diffstat (limited to 'dateutil/utils.py')
-rw-r--r-- | dateutil/utils.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/dateutil/utils.py b/dateutil/utils.py new file mode 100644 index 0000000..92d100c --- /dev/null +++ b/dateutil/utils.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + + +def within_delta(dt1, dt2, delta): + """ + Useful for comparing two datetimes that may a negilible difference + to be considered equal. + """ + delta = abs(delta) + difference = dt1 - dt2 + return -delta <= difference <= delta |