Repository: influxdata/influxdb-client-python

Issue:
_convert_timestamp assumes passed datetime to be UTC
This function here https://github.com/influxdata/influxdb-client-python/blob/62f93503044dbbd86443555ccfac5cfd8359f91a/influxdb_client/client/write/point.py#L130 assumes a passed datetime object to be in UTC format if no timezone is specified. I find this to be highly misleading. From the moment on I set the local timezone when I install an OS I want my system to accept local timezone data from me if I don't specify otherwise.

Discussion:
codecov-commenter: # [Codecov](https://codecov.io/gh/influxdata/influxdb-client-python/pull/238?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata) Report
> Merging [#238](https://codecov.io/gh/influxdata/influxdb-client-python/pull/238?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata) (44094c0) into [master](https://codecov.io/gh/influxdata/influxdb-client-python/commit/6844f60336531d06c15c66b8929921f7029fcb58?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata) (6844f60) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/influxdata/influxdb-client-python/pull/238/graphs/tree.svg?width=650&height=150&src=pr&token=PcyupQSPFt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata)](https://codecov.io/gh/influxdata/influxdb-client-python/pull/238?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata)

```diff
@@           Coverage Diff           @@
##           master     #238   +/-   ##
=======================================
  Coverage   91.87%   91.88%           
=======================================
  Files          25       25           
  Lines        2031     2033    +2     
=======================================
+ Hits         1866     1868    +2     
  Misses        165      165           
```


| [Impacted Files](https://codecov.io/gh/influxdata/influxdb-client-python/pull/238?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata) | Coverage Δ | |
|---|---|---|
| [influxdb\_client/client/util/date\_utils.py](https://codecov.io/gh/influxdata/influxdb-client-python/pull/238/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata#diff-aW5mbHV4ZGJfY2xpZW50L2NsaWVudC91dGlsL2RhdGVfdXRpbHMucHk=) | `96.29% <100.00%> (+0.29%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/influxdata/influxdb-client-python/pull/238?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/influxdata/influxdb-client-python/pull/238?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata). Last update [6844f60...44094c0](https://codecov.io/gh/influxdata/influxdb-client-python/pull/238?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dbc23df..891af11 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
 ### Features
 1. [#237](https://github.com/influxdata/influxdb-client-python/pull/237): Use kwargs to pass query parameters into API list call - useful for the ability to use pagination.
 1. [#241](https://github.com/influxdata/influxdb-client-python/pull/241): Add detail error message for not supported type of `Point.field`
+1. [#238](https://github.com/influxdata/influxdb-client-python/pull/238): Add possibility to specify default `timezone` for datetimes without `tzinfo`
 
 ## 1.17.0 [2021-04-30]
 
diff --git a/influxdb_client/client/util/date_utils.py b/influxdb_client/client/util/date_utils.py
index f7557b1..f1f6f39 100644
--- a/influxdb_client/client/util/date_utils.py
+++ b/influxdb_client/client/util/date_utils.py
@@ -10,6 +10,15 @@ date_helper = None
 class DateHelper:
     """DateHelper to groups different implementations of date operations."""
 
+    def __init__(self, timezone: datetime.tzinfo = UTC) -> None:
+        """
+        Initialize defaults.
+
+        :param timezone: Default timezone used for serialization "datetime" without "tzinfo".
+                         Default value is "UTC".
+        """
+        self.timezone = timezone
+
     def parse_date(self, date_string: str):
         """
         Parse string into Date or Timestamp.
@@ -40,7 +49,7 @@ class DateHelper:
         :return: datetime in UTC
         """
         if not value.tzinfo:
-            return UTC.localize(value)
+            return self.to_utc(value.replace(tzinfo=self.timezone))
         else:
             return value.astimezone(UTC)
 


Test patch:
diff --git a/tests/test_DateHelper.py b/tests/test_DateHelper.py
new file mode 100644
index 0000000..abff4e5
--- /dev/null
+++ b/tests/test_DateHelper.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+
+import unittest
+from datetime import datetime, timezone
+
+from pytz import UTC, timezone
+
+from influxdb_client.client.util.date_utils import DateHelper
+
+
+class DateHelperTest(unittest.TestCase):
+
+    def test_to_utc(self):
+        date = DateHelper().to_utc(datetime(2021, 4, 29, 20, 30, 10, 0))
+        self.assertEqual(datetime(2021, 4, 29, 20, 30, 10, 0, UTC), date)
+
+    def test_to_utc_different_timezone(self):
+        date = DateHelper(timezone=timezone('ETC/GMT+2')).to_utc(datetime(2021, 4, 29, 20, 30, 10, 0))
+        self.assertEqual(datetime(2021, 4, 29, 22, 30, 10, 0, UTC), date)
+
+
+if __name__ == '__main__':
+    unittest.main()