feat(SRC): :rocket: If some input data of get_days_between_dates is a string, converts it to datetime
Browse files- queries.py +12 -1
queries.py
CHANGED
@@ -219,6 +219,10 @@ def date_to_string(date):
|
|
219 |
return string_date
|
220 |
|
221 |
def get_days_between_dates(date1, date2):
|
|
|
|
|
|
|
|
|
222 |
return (date1 - date2).days
|
223 |
|
224 |
def query_usuarios(data, query_list, limit_days=8, debug=False):
|
@@ -236,6 +240,9 @@ def query_usuarios(data, query_list, limit_days=8, debug=False):
|
|
236 |
# Create empty list to store the date_keys that match
|
237 |
date_keys_that_match = []
|
238 |
|
|
|
|
|
|
|
239 |
# Iterate for each query_list date
|
240 |
for query_date in query_list:
|
241 |
# Iterate for each date_key
|
@@ -247,9 +254,13 @@ def query_usuarios(data, query_list, limit_days=8, debug=False):
|
|
247 |
|
248 |
# Add the date_key to the list and break the loop, because is first mach so is match with less days between dates
|
249 |
date_keys_that_match.append(date_to_string(date_key))
|
|
|
|
|
|
|
|
|
250 |
break
|
251 |
|
252 |
-
return date_keys_that_match
|
253 |
|
254 |
def get_macros_differences(data, dates_list):
|
255 |
macros_differences_list = []
|
|
|
219 |
return string_date
|
220 |
|
221 |
def get_days_between_dates(date1, date2):
|
222 |
+
if isinstance(date1, str):
|
223 |
+
date1 = datetime.strptime(date1, '%Y-%m-%d')
|
224 |
+
if isinstance(date2, str):
|
225 |
+
date2 = datetime.strptime(date2, '%Y-%m-%d')
|
226 |
return (date1 - date2).days
|
227 |
|
228 |
def query_usuarios(data, query_list, limit_days=8, debug=False):
|
|
|
240 |
# Create empty list to store the date_keys that match
|
241 |
date_keys_that_match = []
|
242 |
|
243 |
+
# Create empty list to store the macros differences date
|
244 |
+
macros_differences_dates = []
|
245 |
+
|
246 |
# Iterate for each query_list date
|
247 |
for query_date in query_list:
|
248 |
# Iterate for each date_key
|
|
|
254 |
|
255 |
# Add the date_key to the list and break the loop, because is first mach so is match with less days between dates
|
256 |
date_keys_that_match.append(date_to_string(date_key))
|
257 |
+
|
258 |
+
# Add the date_key to the macros_differences_dates list
|
259 |
+
macros_differences_dates.append(date_to_string(query_date))
|
260 |
+
|
261 |
break
|
262 |
|
263 |
+
return date_keys_that_match, macros_differences_dates
|
264 |
|
265 |
def get_macros_differences(data, dates_list):
|
266 |
macros_differences_list = []
|