-
Notifications
You must be signed in to change notification settings - Fork 187
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
_convert_timestamp assumes passed datetime to be UTC #73
Comments
Note that also strings are assumed to be in UTC if no timezone is specified in the string. |
Hi @gooney47, Thanks for using our client. The InfluxDB 2 requires timestamp as UTC so we assume that a naive object These data point produce same LineProtocol: Point.measurement("a")
.field("val", 1)
.time(datetime(2009, 11, 10, 23, 0, 0, 123456))
.to_line_protocol()
Point.measurement("a")
.field("val", 1)
.time(1257894000123456000)
.to_line_protocol()
If you want to use a OS timezone use something like that: Regards |
I still find this highly misleading for me for instance I was wondering why I couldn't see any data after I added some with giving datetime with local time (no timezone specified). My timezone is +1. Now When I did a range query I couldn't see my data until I just for the sake of trial and error put a stop: 1d (which makes it so that the time range isn't stopped at the current time). The error could have been anywhere in my code at that point and that was just pure guessing since there were no errors. Let's take a look at how datetimes should be worked with: With sufficient knowledge of applicable algorithmic and political time adjustments, such as time zone and daylight saving time information, an aware object can locate itself relative to other aware objects. An aware object represents a specific moment in time that is not open to interpretation. 1 A naive object does not contain enough information to unambiguously locate itself relative to other date/time objects. Whether a naive object represents Coordinated Universal Time (UTC), local time, or time in some other timezone is purely up to the program, just like it is up to the program whether a particular number represents metres, miles, or mass. Naive objects are easy to understand and to work with, at the cost of ignoring some aspects of reality." (Source) This means that naive objects should not be assumed as UTC times, they can really be anything. The proper solution here - in my opinion - is raising an exception if no timezone is specified. Just adding the information into the documentation does not fix the problem - at least in my case - as I wasn't checking the documentation of that function specifically as the error could have been anywhere (database setup, not understanding the query language and what not...). |
@gooney47 thanks for detail info |
The default timezone can be changed by: from dateutil.tz import tzlocal
from influxdb_client import InfluxDBClient
from influxdb_client.client.util import date_utils
from influxdb_client.client.util.date_utils import DateHelper
date_utils.date_helper = DateHelper(timezone=tzlocal())
with InfluxDBClient(url="http://localhost:8086", token="my-token", org="my-org", debug=False) as client:
... The issue is fixed in milestone 1.18.0. If you would like to use dev version then install client by: pip install git+https://github.com/influxdata/influxdb-client-python.git@master |
See influxdata/influxdb-client-python#73 We need a timezone aware datetime. Python 3.3+ uses .aztimezone(None) to convert to local timezone https://docs.python.org/3/library/datetime.html#datetime.datetime.astimezone
* REQ: Remove tzlocal as a dependency Only InfluxDB requires this, we'll handle it later if needed. * BUG: Ensure datetime is time-zone aware See influxdata/influxdb-client-python#73 We need a timezone aware datetime. Python 3.3+ uses .aztimezone(None) to convert to local timezone https://docs.python.org/3/library/datetime.html#datetime.datetime.astimezone * GIT: avoid merge conflict with sa-packaging Co-authored-by: S Anand <root.node@gmail.com>
This function here
influxdb-client-python/influxdb_client/client/write/point.py
Line 130 in 62f9350
The text was updated successfully, but these errors were encountered: