def date_range date1 date2 dates_list if date1 date2 year date1 month

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def date_range(date1, date2):
dates_list = []
if date1[0] != date2[0]:
year = date1[0]
month = date1[1]
if date2[0]-date1[0] == 1:
for day in range(date1[2], monthrange(year, month)[1]+1):
dates_list.append([year, month, day])
for month in range(date1[1]+1, 13):
for day in range(1, monthrange(year, month)[1]+1):
dates_list.append([year, month, day])
year = date2[0]
for month in range(1, date2[1]):
for day in range(1, monthrange(year, month)[1]+1):
dates_list.append([year, month, day])
month = date2[1]
for day in range(1, monthrange(year, month)[1]+1):
dates_list.append([year, month, day])
else:
for day in range(date1[2], monthrange(year, month)[1]+1):
dates_list.append([year, month, day])
for month in range(date1[1]+1, 13):
for day in range(1, monthrange(year, month)[1]+1):
dates_list.append([year, month, day])
for year in range(date1[0]+1, date2[0]):
for month in range(1, 13):
for day in range(1, monthrange(year, month)[1]+1):
dates_list.append([year, month, day])
year = date2[0]
for month in range(1, date2[1]):
for day in range(1, monthrange(year, month)[1]+1):
dates_list.append([year, month, day])
month = date2[1]
for day in range(1, date2[2]+1):
dates_list.append([year, month, day])
else:
year = date1[0]
if date1[1] != date2[1]:
month = date1[1]
for day in range(date1[2], monthrange(year, month)[1]+1):
dates_list.append([year, month, day])
if date2[1]-date1[1] == 1:
month = date2[1]
for day in range(1, date2[2]+1):
dates_list.append([year, month, day])
else:
for month in range(date1[1]+1, date2[1]):
for day in range(1, monthrange(year, month)[1]+1):
dates_list.append([year, month, day])
month = date2[1]
for day in range(1, date2[2]+1):
dates_list.append([year, month, day])
else:
month = date1[1]
for day in range(date1[2], date2[2]+1):
dates_list.append([year, month, day])
return dates_list