-
Notifications
You must be signed in to change notification settings - Fork 297
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
Harmonization DateTime incorrect handling of naive time strings #2278
Comments
Also if we are phasing out Python 3.6 (#2272) some additional functions can be dropped. Such as |
gethvi
added a commit
to gethvi/intelmq
that referenced
this issue
Nov 22, 2022
gethvi
added a commit
to gethvi/intelmq
that referenced
this issue
Nov 22, 2022
gethvi
added a commit
to gethvi/intelmq
that referenced
this issue
Nov 22, 2022
This was referenced Nov 22, 2022
I cannot be sure, but I think it was the original intention - to assume the UTC. But as you mentioned, the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Considering this function of
DateTime
class:intelmq/intelmq/lib/harmonization.py
Lines 421 to 436 in 122e3a3
In particular the line:
This causes that naive time strings (without timezone information) are being considered as being in a timezone of the local computer. My computer is set to a UTC +01:00 timezone and this is the result:
Because the parsed timestamps are usually produced by feeds outside of the local computer I believe it makes much more sense to assume they are produced in UTC rather than processing them based on whatever is the local timezone of the IntelMQ installation.
On a side note: There are several cases of this kind of code:
Such expressions are not equal in what they do. The first one (
pytz.utc.localize
) merely attaches a time zone object to a datetime without adjustment of date and time data. The second one (astimezone(pytz.utc)
) adjusts time and date based on local time (docs). Example (with the computer in UTC +01:00):I think this is also the reason why the following test works only when the machine running the test is in UTC timezone:
intelmq/intelmq/tests/lib/test_harmonization.py
Lines 252 to 262 in 122e3a3
PROPOSED SOLUTION:
I think the better way of handling of naive time strings is to assume they are in UTC rather than local timezone of IntelMQ installation:
The function
value.replace(tzinfo=datetime.timezone.utc)
does effectively the same thing aspytz.utc.localize(value)
: it attaches a time zone object to a datetime without adjustment of date and time data. And without needing pytz as dependency.Quick tests showed that my solution seems to work and passes all the tests including the one previously skipped.
The text was updated successfully, but these errors were encountered: