Skip to content

Commit

Permalink
Merge pull request #172 from obsidianforensics/issue-155
Browse files Browse the repository at this point in the history
Fix sorting error when an item is missing tzinfo (and add warning)
  • Loading branch information
obsidianforensics authored Apr 29, 2024
2 parents 7a6b616 + 39b92be commit 5a7196f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyhindsight/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def generate_excel(self, output_object):

# Start at the row after the headers, and begin writing out the items in parsed_artifacts
row_number = 2
for item in self.parsed_artifacts:
for item in sorted(self.parsed_artifacts):
try:
if item.row_type.startswith("url"):
w.write_string(row_number, 0, item.row_type, black_type_format) # record_type
Expand Down
7 changes: 7 additions & 0 deletions pyhindsight/browsers/webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ def __init__(self, item_type, timestamp, profile, url=None, name=None, value=Non
self.interpretation = interpretation

def __lt__(self, other):
if not self.timestamp.tzinfo and other.timestamp.tzinfo:
log.warning(f'{self} missing tzinfo; using tzinfo from {other} during sort')
self.timestamp = self.timestamp.replace(tzinfo=other.timestamp.tzinfo)
elif self.timestamp.tzinfo and not other.timestamp.tzinfo:
log.warning(f'{other} missing tzinfo; using tzinfo from {self} during sort')
other.timestamp = other.timestamp.replace(tzinfo=self.timestamp.tzinfo)

return self.timestamp < other.timestamp

def __iter__(self):
Expand Down

0 comments on commit 5a7196f

Please sign in to comment.