days_between.days_diff()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
import datetime
2
3
4
def days_diff(date1, date2):
5
    days = (datetime.datetime(*date2) - datetime.datetime(*date1)).days
6
    if days < 0:
7
        return -days
8
    return days
9
10
11
if __name__ == '__main__':
12
    # These "asserts" using only for self-checking and not necessary for
13
    # auto-testing
14
    assert days_diff((1982, 4, 19), (1982, 4, 22)) == 3
15
    assert days_diff((2014, 1, 1), (2014, 8, 27)) == 238
16
    assert days_diff((2014, 8, 27), (2014, 1, 1)) == 238
17