Skip to content

Commit

Permalink
blacked
Browse files Browse the repository at this point in the history
  • Loading branch information
Malutthias committed Oct 29, 2024
1 parent 8a3ca21 commit d02fef3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion logprep/util/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ def parse_datetime(
The parsed timestamp as datetime object.
"""
if source_format == "UNIX":
parsed_datetime = int(timestamp) if len(timestamp) <= 10 else int(timestamp) / 10 ** (len(timestamp) - 10)
parsed_datetime = (
int(timestamp)
if len(timestamp) <= 10
else int(timestamp) / 10 ** (len(timestamp) - 10)
)
parsed_datetime = cls.from_timestamp(parsed_datetime)
elif source_format == "ISO8601":
parsed_datetime = cls.from_string(timestamp, set_missing_utc=False)
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/util/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,22 @@ def test_parse_datetime_unix_timestamp_is_always_utc(
assert timestamp.tzinfo.tzname(timestamp) == expected_timezone_name
for attribute, value in expected.items():
assert getattr(timestamp, attribute) == value

@pytest.mark.parametrize(
"timestamp, expected_timezone_name, expected",
[
(
"1615634593",
"1615634593",
"UTC",
{"year": 2021, "month": 3, "day": 13, "hour": 11, "minute": 23, "second": 13},
),
(
"1615634593000",
"1615634593000",
"UTC",
{"year": 2021, "month": 3, "day": 13, "hour": 11, "minute": 23, "second": 13},
),
(
"1615634593000000",
"1615634593000000",
"UTC",
{"year": 2021, "month": 3, "day": 13, "hour": 11, "minute": 23, "second": 13},
),
Expand Down

0 comments on commit d02fef3

Please sign in to comment.