Skip to content

Add support for datetime with zoneinfo tzinfo #46

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

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
16 changes: 6 additions & 10 deletions src/pywaterinfo/waterinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def _parse_date(input_datetime, timezone="UTC"):
we normalize everything to UTC by default. Hence, we interpret the user
input as UTC, provide the input to the API as CET and request the returned
output data as UTC. If the user provides a timezone, we interpret user input as
the given timezone, doe the request in CET and return th output data in the
the given timezone, do the request in CET and return the output data in the
requested timezone.

Parameters
Expand All @@ -359,16 +359,12 @@ def _parse_date(input_datetime, timezone="UTC"):
f"{timezone} is not a valid timezone string."
)

input_timestamp = pd.to_datetime(input_datetime)
input_timestamp = pd.to_datetime(str(input_datetime))

if input_timestamp.tz: # timestamp already contains tz info
return input_timestamp.tz_convert("CET").strftime("%Y-%m-%d %H:%M:%S")
else:
return (
input_timestamp.tz_localize(timezone)
.tz_convert("CET")
.strftime("%Y-%m-%d %H:%M:%S")
)
if not input_timestamp.tz: # timestamp does not contain tz info
input_timestamp = input_timestamp.tz_localize(timezone)

return input_timestamp.tz_convert("CET").strftime("%Y-%m-%d %H:%M:%S")

def _parse_period(self, start=None, end=None, period=None, timezone="UTC"):
"""Check the from/to/period arguments when requesting
Expand Down