Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add behaviour to always use datetime.UTC if there is no zoneinfo available #86

Merged
merged 4 commits into from
Oct 11, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions flow/record/fieldtypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
from urllib.parse import urlparse

try:
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
try:
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
except ImportError:
from backports.zoneinfo import ZoneInfo, ZoneInfoNotFoundError
HAS_ZONE_INFO = True
except ImportError:
from backports.zoneinfo import ZoneInfo, ZoneInfoNotFoundError
HAS_ZONE_INFO = False

Check warning on line 24 in flow/record/fieldtypes/__init__.py

View check run for this annotation

Codecov / codecov/patch

flow/record/fieldtypes/__init__.py#L24

Added line #L24 was not covered by tests


from flow.record.base import FieldType

Expand Down Expand Up @@ -50,9 +55,15 @@
Returns:
None if ``FLOW_RECORD_TZ=NONE`` otherwise ``ZoneInfo(FLOW_RECORD_TZ)`` or ``UTC`` if ZoneInfo is not found.
"""

tz = os.environ.get("FLOW_RECORD_TZ", default_tz)
if tz.upper() == "NONE":
return None

yunzheng marked this conversation as resolved.
Show resolved Hide resolved
if not HAS_ZONE_INFO:
warnings.warn("Cannot use FLOW_RECORD_TZ due to missing zoneinfo module, defaulting to 'UTC'.")
Miauwkeru marked this conversation as resolved.
Show resolved Hide resolved
return UTC

Check warning on line 65 in flow/record/fieldtypes/__init__.py

View check run for this annotation

Codecov / codecov/patch

flow/record/fieldtypes/__init__.py#L64-L65

Added lines #L64 - L65 were not covered by tests

try:
return ZoneInfo(tz)
except ZoneInfoNotFoundError as exc:
Expand Down