Skip to content

Commit

Permalink
Implement review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JSCU-CNI committed Sep 24, 2024
1 parent 464d00d commit 05b75c2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions flow/record/adapter/xlsx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from base64 import b64decode, b64encode
from datetime import datetime
from datetime import datetime, timezone
from typing import Any, Iterator

from openpyxl import Workbook, load_workbook
Expand All @@ -16,7 +16,7 @@
Microsoft Excel spreadsheet adapter
---
Write usage: rdump -w xlsx://[PATH]
Read usage: rdump xlsx://[PATH]
Read usage: rdump xlsx://[PATH]
[PATH]: path to file. Leave empty or "-" to output to stdout
"""

Expand All @@ -28,9 +28,7 @@ def sanitize_fieldvalues(values: Iterator[Any]) -> Iterator[Any]:
# openpyxl doesn't support timezone-aware datetime instances,
# so we convert to UTC and then remove the timezone info.
if isinstance(value, datetime) and value.tzinfo is not None:
utc_offset = value.utcoffset()
value += utc_offset
value = value.replace(tzinfo=None)
value = value.astimezone(timezone.utc).replace(tzinfo=None)

elif type(value) in [ipaddress, list, fieldtypes.posix_path, fieldtypes.windows_path]:
value = str(value)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_xlsx_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_sanitize_field_values(mock_openpyxl_package):
)
) == [
7,
datetime(1920, 11, 11, 15, 37, 0), # UTC normalization
datetime(1920, 11, 11, 11, 37, 0), # UTC normalization
"James",
'b"Bond"', # When possible, encode bytes in a printable way
"base64:AAc=", # If not, base64 encode
Expand Down

0 comments on commit 05b75c2

Please sign in to comment.