-
Notifications
You must be signed in to change notification settings - Fork 4
/
check_date.py
137 lines (98 loc) · 2.89 KB
/
check_date.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from datetime import date as d
from datetime import timedelta
import doctest
# Comtains function to check if a date is in the past week or a future date
"""
{{{ TO CHANGE }}}
1. Remove imports
from datetime import timedelta
from datetime import date as d
2. Add import
from datetime import datetime
3. Change path to include parent directory and import module
import sys
sys.path.insert(1, '../.')
from check_date import check_date
4. Convert date as string to date, and adjust functions accordingly
* remove - from format (not needed)
* .date() converts datetime obj to date obj
# Obtain date as object
date_obj = datetime.strptime(date, "format").date()
5. Remove function
get_past_days()
6. Change d to datetime when creating csv
"""
def check_date(date):
"""
>>> date = d.today() # Today
>>> check_date(date)
True
>>> date = d.today() + timedelta(days=1) # Tomorrow
>>> check_date(date)
True
>>> date = d.today() + timedelta(days=365) # Next year
>>> check_date(date)
True
>>> date = d.today() - timedelta(days=1) # Yesterday
>>> check_date(date)
True
>>> date = d.today() - timedelta(days=3) # Last day of past week
>>> check_date(date)
True
>>> date = d.today() - timedelta(days=7) # Last week
>>> check_date(date)
False
>>> date = d.today() - timedelta(days=365) # Last year
>>> check_date(date)
False
"""
today = d.today()
past_week = []
temp_day = d.today()
for i in range(7):
past_week.append(temp_day)
temp_day = temp_day-timedelta(1)
return date in past_week or date > today
def check_date_14(date):
# did not set up unit tests yet
today = d.today()
past_week = []
temp_day = d.today()
for i in range(14):
past_week.append(temp_day)
temp_day = temp_day-timedelta(1)
return date in past_week or date > today
def check_date_30(date):
# did not set up unit tests yet
"""
>>> date = d.today() # Today
>>> check_date(date)
True
>>> date = d.today() + timedelta(days=1) # Tomorrow
>>> check_date(date)
True
>>> date = d.today() + timedelta(days=365) # Next year
>>> check_date(date)
True
>>> date = d.today() - timedelta(days=1) # Yesterday
>>> check_date(date)
True
>>> date = d.today() - timedelta(days=12)
>>> check_date(date)
True
>>> date = d.today() - timedelta(days=7) # Last week
>>> check_date(date)
False
>>> date = d.today() - timedelta(days=365) # Last year
>>> check_date(date)
False
"""
today = d.today()
past_week = []
temp_day = d.today()
for i in range(30):
past_week.append(temp_day)
temp_day = temp_day-timedelta(1)
return date in past_week or date > today
if __name__ == "__main__":
doctest.testmod()