-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add possibility to specify default
timezone
for datetimes wit…
…hout `tzinfo` (#238)
- Loading branch information
Showing
3 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |