MCPcopy Index your code
hub / github.com/diffgram/diffgram / fill_missing_dates

Method fill_missing_dates

default/methods/stats/stats.py:8–49  ·  view source on GitHub ↗

date_from, a python datetime.datetime object

(date_from, 
						   date_to, 
						   known_dates_list: list)

Source from the content-addressed store, hash-verified

6
7 @staticmethod
8 def fill_missing_dates(date_from,
9 date_to,
10 known_dates_list: list):
11
12 """
13 date_from, a python datetime.datetime object
14
15 """
16
17 # CAREFUL
18 # ASSUMES *assending* ORDERED!!!!! (
19
20 with_missing_dates = []
21
22 if isinstance(date_from, datetime.datetime) is False:
23 date_from = datetime.datetime.strptime(date_from, "%Y-%m-%d")
24 date_to = datetime.datetime.strptime(date_to, "%Y-%m-%d")
25
26 next_date = date_from
27
28 period_desired = (date_to - date_from).days
29
30 len_period = len(known_dates_list)
31
32 known_date_index = 0
33 for i in range(period_desired):
34
35 # date() "Return date object with same year, month and day."
36
37 if known_date_index + 1 <= len_period:
38 known_date = known_dates_list[known_date_index]
39 if known_date.date() == next_date.date() :
40 with_missing_dates.append(known_date)
41 known_date_index += 1
42 else:
43 with_missing_dates.append(next_date)
44 else:
45 with_missing_dates.append(next_date)
46
47 next_date = next_date + datetime.timedelta(days=1)
48
49 return with_missing_dates

Callers 3

stats_task_coreFunction · 0.80
stats_task_core_projectFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected