Skip to content

Commit 2f6989a

Browse files
author
aviau
committed
Support 'ms' in _datetime_to_epoch
1 parent 48868fc commit 2f6989a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

influxdb/dataframe_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def _datetime_to_epoch(self, datetime, time_precision='s'):
133133
seconds = (datetime - self.EPOCH).total_seconds()
134134
if time_precision == 's':
135135
return seconds
136-
elif time_precision == 'm':
136+
elif time_precision == 'm' or time_precision == 'ms':
137137
return seconds * 1000
138138
elif time_precision == 'u':
139139
return seconds * 1000000

tests/influxdb/dataframe_client_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,28 @@ def test_list_series(self):
221221
cli = DataFrameClient('host', 8086, 'username', 'password', 'db')
222222
series_list = cli.get_list_series()
223223
assert series_list == ['seriesA', 'seriesB']
224+
225+
def test_datetime_to_epoch(self):
226+
timestamp = pd.Timestamp('2013-01-01 00:00:00.000+00:00')
227+
cli = DataFrameClient('host', 8086, 'username', 'password', 'db')
228+
229+
self.assertEqual(
230+
cli._datetime_to_epoch(timestamp),
231+
1356998400.0
232+
)
233+
self.assertEqual(
234+
cli._datetime_to_epoch(timestamp, time_precision='s'),
235+
1356998400.0
236+
)
237+
self.assertEqual(
238+
cli._datetime_to_epoch(timestamp, time_precision='m'),
239+
1356998400000.0
240+
)
241+
self.assertEqual(
242+
cli._datetime_to_epoch(timestamp, time_precision='ms'),
243+
1356998400000.0
244+
)
245+
self.assertEqual(
246+
cli._datetime_to_epoch(timestamp, time_precision='u'),
247+
1356998400000000.0
248+
)

0 commit comments

Comments
 (0)