Skip to content

Commit d5bff52

Browse files
authored
Merge pull request #3252 from chaoss/facade-timezone-fix-redux
Facade timezone fix redux
2 parents 6cd41f6 + aeaf09f commit d5bff52

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

augur/application/db/lib.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,24 +225,46 @@ def facade_bulk_insert_commits(logger, records):
225225

226226
facade_bulk_insert_commits(logger, firsthalfRecords)
227227
facade_bulk_insert_commits(logger, secondhalfRecords)
228-
elif len(records) == 1 and isinstance(e,DataError) and "time zone displacement" in f"{e}":
228+
elif len(records) == 1:
229229
commit_record = records[0]
230230
#replace incomprehensible dates with epoch.
231231
#2021-10-11 11:57:46 -0500
232232

233233
# placeholder_date = "1970-01-01 00:00:15 -0500"
234-
placeholder_date = commit_record['author_timestamp']
234+
placeholder_date = commit_record['cmt_author_timestamp']
235+
236+
postgres_valid_timezones = {
237+
-1200, -1100, -1000, -930, -900, -800, -700,
238+
-600, -500, -400, -300, -230, -200, -100, 000,
239+
100, 200, 300, 330, 400, 430, 500, 530, 545, 600,
240+
630, 700, 800, 845, 900, 930, 1000, 1030, 1100, 1200,
241+
1245, 1300, 1400
242+
}
235243

236244
# Reconstruct timezone portion of the date string to UTC
237-
placeholder_date = re.split("[-+]", placeholder_date)
238-
placeholder_date.pop()
239-
placeholder_date = "-".join(placeholder_date) + "+0000"
245+
placeholder_date_segments = re.split(" ", placeholder_date)
246+
tzdata = placeholder_date_segments.pop()
247+
248+
if ":" in tzdata:
249+
tzdata = tzdata.replace(":", "")
250+
251+
if int(tzdata) not in postgres_valid_timezones:
252+
tzdata = "+0000"
253+
else:
254+
raise e
255+
256+
placeholder_date_segments.append(tzdata)
257+
258+
placeholder_date = " ".join(placeholder_date_segments)
240259

241260
#Check for improper utc timezone offset
242261
#UTC timezone offset should be between -14:00 and +14:00
243262

244-
commit_record['author_timestamp'] = placeholder_date
245-
commit_record['committer_timestamp'] = placeholder_date
263+
# analyzecommit.generate_commit_record() defines the keys on the commit_record dictionary
264+
commit_record['cmt_author_timestamp'] = placeholder_date
265+
commit_record['cmt_committer_timestamp'] = placeholder_date
266+
267+
logger.warning(f"commit with invalid timezone set to UTC: {commit_record['cmt_commit_hash']}")
246268

247269
session.execute(
248270
s.insert(Commit),

0 commit comments

Comments
 (0)