File tree 2 files changed +15
-6
lines changed 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
22
22
- Clean up stale CI config (#755 )
23
23
- Add legacy client test (#752 & #318 thx @oldmantaiter & @sebito91 )
24
24
- Update make_lines section in line_protocol.py to split out core function (#375 thx @aisbaa )
25
+ - Fix nanosecond time resolution for points (#407 thx @AndreCAndersen && @clslgrnc )
25
26
26
27
### Removed
27
28
Original file line number Diff line number Diff line change 16
16
EPOCH = UTC .localize (datetime .utcfromtimestamp (0 ))
17
17
18
18
19
+ def _to_nanos (timestamp ):
20
+ delta = timestamp - EPOCH
21
+ nanos_in_days = delta .days * 86400 * 10 ** 9
22
+ nanos_in_seconds = delta .seconds * 10 ** 9
23
+ nanos_in_micros = delta .microseconds * 10 ** 3
24
+ return nanos_in_days + nanos_in_seconds + nanos_in_micros
25
+
26
+
19
27
def _convert_timestamp (timestamp , precision = None ):
20
28
if isinstance (timestamp , Integral ):
21
29
return timestamp # assume precision is correct if timestamp is int
@@ -27,24 +35,24 @@ def _convert_timestamp(timestamp, precision=None):
27
35
if not timestamp .tzinfo :
28
36
timestamp = UTC .localize (timestamp )
29
37
30
- ns = (timestamp - EPOCH ). total_seconds () * 1e9
38
+ ns = _to_nanos (timestamp )
31
39
if precision is None or precision == 'n' :
32
40
return ns
33
41
34
42
if precision == 'u' :
35
- return ns / 1e3
43
+ return ns / 10 ** 3
36
44
37
45
if precision == 'ms' :
38
- return ns / 1e6
46
+ return ns / 10 ** 6
39
47
40
48
if precision == 's' :
41
- return ns / 1e9
49
+ return ns / 10 ** 9
42
50
43
51
if precision == 'm' :
44
- return ns / 1e9 / 60
52
+ return ns / 10 ** 9 / 60
45
53
46
54
if precision == 'h' :
47
- return ns / 1e9 / 3600
55
+ return ns / 10 ** 9 / 3600
48
56
49
57
raise ValueError (timestamp )
50
58
You can’t perform that action at this time.
0 commit comments